tuoda pygame
tuonti sys
MUSTA =(0, 0, 0)
VALKOINEN =(255, 255, 255)
VIHREÄ =(0, 255, 0)
PUNAINEN =(255, 0, 0)
SCREEN_WIDTH =800
SCREEN_HEIGHT =600
näyttö =pygame.display.set_mode((KUVARUUTU_LEVEYS, NÄYTÖN_KORKEUS))
pelaaja =pygame.sprite.Sprite()
player.image =pygame.image.load("pongebob.png")
player.rect =player.image.get_rect()
seinät =pygame.sprite.Group()
i alueella (5):
seinä =pygame.sprite.Sprite()
seinä.kuva =pygame.Surface((100, 100))
wall.image.fill (VIHREÄ)
wall.rect =wall.image.get_rect()
seinä.suora.x =i * 100
seinä.suora.y =i * 100
seinät.add(seinä)
kun taas Totta:
# Tarkista tapahtumat
tapahtumalle pygame.event.get():
if event.type ==pygame.QUIT:
pygame.quit()
sys.exit()
# Siirrä soitinta
avaimet =pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
player.rekt.x -=5
if keys[pygame.K_RIGHT]:
player.rekt.x +=5
if keys[pygame.K_UP]:
player.rekt.y -=5
if keys[pygame.K_DOWN]:
player.rekt.y +=5
# Tarkista törmäyksiä
jos pygame.sprite.spritecollideany(pelaaja, seinät):
player.rekt.x -=5
player.rekt.y -=5
# Piirrä näyttö
screen.fill(MUSTA)
näyttö.blit(soitin.kuva, pelaaja.suora)
seinät.piirrä (näyttö)
# Päivitä näyttö
pygame.display.flip()
```