all repos — Legends-RPG @ 134a5fab9d4a4dcf1ce9d6e5a5191c5a42036902

A fantasy mini-RPG built with Python and Pygame.

Added sword animation.
Justin Armstrong justinmeister@gmail.com
Mon, 28 Apr 2014 18:35:32 -0700
commit

134a5fab9d4a4dcf1ce9d6e5a5191c5a42036902

parent

b5733447a499f57ee5e055cff73e18dbfac21354

M data/components/attackitems.pydata/components/attackitems.py

@@ -13,21 +13,42 @@ """

def __init__(self, player): self.player = player self.sprite_sheet = setup.GFX['shopsigns'] - self.image = tools.get_image(48, 0, 16, 16, self.sprite_sheet) - self.image = pg.transform.scale2x(self.image) + self.image_list = self.make_image_list() + self.index = 0 + self.timer = 0.0 + + def make_image_list(self): + """ + Make the list of two images for animation. + """ + image_list = [tools.get_image(48, 0, 16, 16, self.sprite_sheet), + tools.get_image(0, 0, 22, 16, setup.GFX['sword2'])] + return image_list + + @property + def image(self): + new_image = self.image_list[self.index] + return pg.transform.scale2x(new_image) @property def rect(self): new_rect = copy.copy(self.player.rect) - new_rect.right -= 10 - new_rect.top += 15 + new_rect.bottom += 17 + new_rect.right -= 16 return new_rect + def update(self, current_time): + if (current_time - self.timer) > 60: + self.timer = current_time + if self.index == 0: + self.index += 1 + else: + self.index -= 1 + def draw(self, surface): """ Draw sprite to surface. """ if self.player.state == 'attack': - if self.player.x_vel % 5 == 0: - surface.blit(self.image, self.rect) + surface.blit(self.image, self.rect)
M data/components/person.pydata/components/person.py

@@ -299,24 +299,20 @@ self.attacked_enemy = enemy

self.x_vel = -5 self.state = 'attack' + def attack(self): """ Player does an attack animation. """ - SLOW_BACK = 1 FAST_FORWARD = -5 FAST_BACK = 5 self.rect.x += self.x_vel - if self.x_vel == SLOW_BACK: - if self.rect.x >= self.origin_pos[0] + 20: - self.x_vel = FAST_FORWARD - elif self.x_vel == FAST_FORWARD: - if self.rect.topleft >= self.origin_pos: - self.image = self.spritesheet_dict['facing left 1'] - self.image = pg.transform.scale2x(self.image) - elif self.rect.x <= self.origin_pos[0] - 110: + if self.x_vel == FAST_FORWARD: + self.image = self.spritesheet_dict['facing left 1'] + self.image = pg.transform.scale2x(self.image) + if self.rect.x <= self.origin_pos[0] - 110: self.x_vel = FAST_BACK self.notify('attack animation') else:
M data/states/battle.pydata/states/battle.py

@@ -129,6 +129,7 @@ self.player.update(keys, current_time)

self.attack_animations.update() self.info_box.update() self.arrow.update(keys) + self.sword.update(current_time) self.draw_battle(surface)

@@ -233,12 +234,13 @@ """Draw all elements of battle state"""

self.background.draw(surface) self.enemy_group.draw(surface) self.attack_animations.draw(surface) + self.sword.draw(surface) surface.blit(self.player.image, self.player.rect) surface.blit(self.info_box.image, self.info_box.rect) surface.blit(self.select_box.image, self.select_box.rect) surface.blit(self.arrow.image, self.arrow.rect) self.player_health_box.draw(surface) - self.sword.draw(surface) + def player_damaged(self, damage): self.game_data['player stats']['health']['current'] -= damage