Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodolfo 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)
commit7e2a5b9e56fb4cf6488977960157964215edc868 (patch)
tree2e0b8df8bb8c1176dde34569247f778b33f1ff62
parentcdd157091d11fe2dcdbcc22c516083fb9f383c79 (diff)
Motion for the ranger
-rw-r--r--main.py3
-rw-r--r--ranger.py7
2 files changed, 9 insertions, 1 deletions
diff --git a/main.py b/main.py
index e2ff080..701c6e5 100644
--- a/main.py
+++ b/main.py
@@ -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]:
diff --git a/ranger.py b/ranger.py
index 2c2cddb..356087b 100644
--- a/ranger.py
+++ b/ranger.py
@@ -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