From 8490b2cbfe010433034623d46d668accd79946b9 Mon Sep 17 00:00:00 2001 From: Sakse Dalum Date: Wed, 8 Aug 2012 15:22:27 +0200 Subject: [PATCH] Not really sure what I did ... but some sort of improvement. --- robotgame/player.py | 44 +++++++++++++++++++++------------------- robotgame/worldobject.py | 2 +- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/robotgame/player.py b/robotgame/player.py index cde90c4..8f3d445 100644 --- a/robotgame/player.py +++ b/robotgame/player.py @@ -84,30 +84,32 @@ class Player(worldobject.WorldObject): def update(self, e, t, dt): for event in e: if event.type == pygame.KEYDOWN: - if event.key == pygame.K_UP: - if not self.holding: - self.direction = (0, -1) - self.anim = 'idle_up' - self.move(0, -1) - if event.key == pygame.K_DOWN: - if not self.holding: - self.direction = (0, 1) - self.anim = 'idle_down' - self.move(0, 1) - if event.key == pygame.K_RIGHT: - if not self.holding: - self.direction = (1, 0) - self.anim = 'idle_right' - self.move(1, 0) - if event.key == pygame.K_LEFT: - if not self.holding: - self.direction = (-1, 0) - self.anim = 'idle_left' - self.move(-1, 0) - if event.key == pygame.K_SPACE: self.touch(*self.direction) + keys = pygame.key.get_pressed() + if keys[pygame.K_UP]: + if not self.holding: + self.direction = (0, -1) + self.anim = 'idle_up' + self.move(0, -1) + if keys[pygame.K_DOWN]: + if not self.holding: + self.direction = (0, 1) + self.anim = 'idle_down' + self.move(0, 1) + if keys[pygame.K_RIGHT]: + if not self.holding: + self.direction = (1, 0) + self.anim = 'idle_right' + self.move(1, 0) + if keys[pygame.K_LEFT]: + if not self.holding: + self.direction = (-1, 0) + self.anim = 'idle_left' + self.move(-1, 0) + + # Update the animation self.frame = ((self.frame + self.anim_speed * dt) % len(self.imgs[self.anim])) diff --git a/robotgame/worldobject.py b/robotgame/worldobject.py index 6c59361..e52848b 100644 --- a/robotgame/worldobject.py +++ b/robotgame/worldobject.py @@ -29,7 +29,7 @@ import numpy import copy class WorldObject(object): - def __init__(self, level, x, y, z=0, direction=(1, 0), speed=5, + def __init__(self, level, x, y, z=0, direction=(1, 0), speed=4, tile_x=64, tile_y=48, movable=False): self.__dict__.update(locals())