Advertisement
niromru

Спрайты ---> Герой двигается!

Jan 26th, 2021
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. import urllib.request
  2. import pygame
  3.  
  4. f, h = urllib.request.urlretrieve('https://yastatic.net/s3/lyceum/content/image/pygame/creature.png')
  5. img = open(f)
  6. if __name__ == '__main__':
  7.     pygame.init()
  8.     x, y = 0, 0
  9.     size = width, height = 800, 600
  10.     sc = pygame.display.set_mode(size)
  11.     imgp = pygame.image.load(img).convert()
  12.     sc.fill((255, 255, 255))
  13.     sc.blit(imgp, (x, y))
  14.     pygame.display.update()
  15.     while True:
  16.         for i in pygame.event.get():
  17.             if i.type == pygame.QUIT:
  18.                 exit(0)
  19.             elif i.type == pygame.KEYDOWN:
  20.                 if i.key == pygame.K_RIGHT:
  21.                     x += 10
  22.                     sc.fill((255, 255, 255))
  23.                     sc.blit(imgp, (x, y))
  24.                     pygame.display.update()
  25.                 elif i.key == pygame.K_LEFT:
  26.                     x -= 10
  27.                     sc.fill((255, 255, 255))
  28.                     sc.blit(imgp, (x, y))
  29.                     pygame.display.update()
  30.                 elif i.key == pygame.K_UP:
  31.                     y -= 10
  32.                     sc.fill((255, 255, 255))
  33.                     sc.blit(imgp, (x, y))
  34.                     pygame.display.update()
  35.                 elif i.key == pygame.K_DOWN:
  36.                     y += 10
  37.                     sc.fill((255, 255, 255))
  38.                     sc.blit(imgp, (x, y))
  39.                     pygame.display.update()
  40.     pygame.quit()
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement