From cbb6caea9702545554995ae86407b21363bf97eb Mon Sep 17 00:00:00 2001 From: Sakse Dalum Date: Wed, 8 Aug 2012 19:11:43 +0200 Subject: [PATCH] Implemented carry animations. --- robotgame/player.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/robotgame/player.py b/robotgame/player.py index 8f3d445..5584285 100644 --- a/robotgame/player.py +++ b/robotgame/player.py @@ -36,7 +36,8 @@ class Player(worldobject.WorldObject): worldobject.WorldObject.__init__(self, level, x, y, z=z, movable=movable) - self.anim = 'idle_right' + self.anim_root = 'idle' + self.anim = 'right' self.frame = 0 self.anim_speed = 15 @@ -49,7 +50,11 @@ class Player(worldobject.WorldObject): [('idle_up', os.path.join('robot_idle', 'up')), ('idle_down', os.path.join('robot_idle', 'down')), ('idle_right', os.path.join('robot_idle', 'right')), - ('idle_left', os.path.join('robot_idle', 'right'))] + ('idle_left', os.path.join('robot_idle', 'right')), + ('carry_up', os.path.join('robot_carry', 'up')), + ('carry_down', os.path.join('robot_carry', 'down')), + ('carry_right', os.path.join('robot_carry', 'right')), + ('carry_left', os.path.join('robot_carry', 'right'))] ): self.imgs[anim] = [] @@ -67,12 +72,12 @@ class Player(worldobject.WorldObject): img = pygame.image.load(f) # Special treatment: - if anim == 'idle_left': + if anim in ['idle_left', 'carry_left']: img = pygame.transform.flip(img, 1, 0) self.imgs[anim].append(img) - self.img = self.imgs[self.anim][int(self.frame)] + self.img = self.imgs[self.anim_root + '_' + self.anim][int(self.frame)] def touch(self, touch_x, touch_y): for obj in self.level.objects: @@ -91,33 +96,34 @@ class Player(worldobject.WorldObject): if keys[pygame.K_UP]: if not self.holding: self.direction = (0, -1) - self.anim = 'idle_up' + self.anim = 'up' self.move(0, -1) if keys[pygame.K_DOWN]: if not self.holding: self.direction = (0, 1) - self.anim = 'idle_down' + self.anim = 'down' self.move(0, 1) if keys[pygame.K_RIGHT]: if not self.holding: self.direction = (1, 0) - self.anim = 'idle_right' + self.anim = 'right' self.move(1, 0) if keys[pygame.K_LEFT]: if not self.holding: self.direction = (-1, 0) - self.anim = 'idle_left' + self.anim = 'left' self.move(-1, 0) - # Update the animation self.frame = ((self.frame + self.anim_speed * dt) % - len(self.imgs[self.anim])) + len(self.imgs[self.anim_root + '_' + self.anim])) worldobject.WorldObject.update(self, e, t, dt) def draw(self, window): - self.img = self.imgs[self.anim][int(self.frame)] + self.anim_root = 'carry' if self.holding else 'idle' + + self.img = self.imgs[self.anim_root + '_' + self.anim][int(self.frame)] self.img.set_alpha(128) window.blit(self.img, (self.x - 32 - self.level.camera_x, self.y - self.img.get_size()[1] + 24