Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. import pygame
  2.  
  3. pygame.init()
  4. screen = pygame.display.set_mode((400, 300))
  5. done = False
  6. clock = pygame.time.Clock()
  7.  
  8. x = 30
  9. y = 30
  10.  
  11. def time_slice(time_since, interval):
  12.         "return current time slice"
  13.         return int(time_since / interval)
  14.  
  15. interval = 10 # second
  16. time_since = 0 # second
  17. last_slice = 0
  18. time_passed = 1
  19.  
  20. def image(path):
  21.         return pygame.image.load(path).convert_alpha()
  22.  
  23. while not done:
  24.         for event in pygame.event.get():
  25.                 if event.type == pygame.QUIT:
  26.                         done = True
  27.  
  28.         pressed = pygame.key.get_pressed()
  29.         if time_slice(time_since, interval) != last_slice:
  30.                 if pressed[pygame.K_w]:
  31.                         y -= 20
  32.                 elif pressed[pygame.K_s]:
  33.                          y += 20
  34.                 elif pressed[pygame.K_a]:
  35.                         x -= 20
  36.                 elif pressed[pygame.K_d]:
  37.                         x += 20
  38.                        
  39.                 last_slice = time_slice(time_since, interval)
  40.         time_since += time_passed
  41.                        
  42.         screen.fill((255, 255, 255))
  43.  
  44.  
  45.         screen.blit(image('man.png'), (x, y))
  46.                
  47.         pygame.display.flip()
  48.         clock.tick(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement