diff options
author | Rodolfo D. Arce S <rodolfo.arce.s@gmail.com> | 2011-05-20 17:26:48 (GMT) |
---|---|---|
committer | Rodolfo D. Arce S <rodolfo.arce.s@gmail.com> | 2011-05-20 17:26:48 (GMT) |
commit | 7e2a5b9e56fb4cf6488977960157964215edc868 (patch) | |
tree | 2e0b8df8bb8c1176dde34569247f778b33f1ff62 | |
parent | cdd157091d11fe2dcdbcc22c516083fb9f383c79 (diff) |
Motion for the ranger
-rw-r--r-- | main.py | 3 | ||||
-rw-r--r-- | ranger.py | 7 |
2 files changed, 9 insertions, 1 deletions
@@ -23,7 +23,7 @@ clock = pygame.time.Clock() # Ranger unit = 1.0 -ranger_speed = 6 +ranger_speed = 2 ranger = Ranger(window_h, window_w, unit, ranger_speed) # Draw background @@ -39,6 +39,7 @@ while True: for event in pygame.event.get(): if event.type == pygame.QUIT: exit() + ranger.input(event) keyboard = pygame.key.get_pressed() if keyboard[K_ESCAPE]: @@ -32,6 +32,13 @@ class Ranger: if event.key == pygame.K_DOWN: self.direction_y = 1 self.direction_x = 0 + if event.type == pygame.KEYUP: + if (event.key == pygame.K_LEFT and self.direction_x == -1 and self.direction_y == 0) or\ + (event.key == pygame.K_RIGHT and self.direction_x == 1 and self.direction_y == 0) or\ + (event.key == pygame.K_UP and self.direction_y == -1 and self.direction_x == 0) or\ + (event.key == pygame.K_DOWN and self.direction_y == 1 and self.direction_x == 0): + self.direction_x = 0 + self.direction_y = 0 def update(self): image_center = self.image.get_width()/2 |