all repos — Legends-RPG @ 4b9f2008aa45d1c1cfd5b0f335eca68b8313b26f

A fantasy mini-RPG built with Python and Pygame.

Began implementing enemy attacks during battle scene.
Justin Armstrong justinmeister@gmail.com
Thu, 24 Apr 2014 10:50:50 -0700
commit

4b9f2008aa45d1c1cfd5b0f335eca68b8313b26f

parent

1cff6e4fd351db22b6f34a35606ee230eef7ccd5

3 files changed, 46 insertions(+), 6 deletions(-)

jump to
M data/components/person.pydata/components/person.py

@@ -80,7 +80,8 @@ 'animated resting': self.animated_resting,

'autoresting': self.auto_resting, 'automoving': self.auto_moving, 'battle resting': self.battle_resting, - 'attack': self.attack} + 'attack': self.attack, + 'enemy attack': self.enemy_attack} return state_dict

@@ -291,7 +292,7 @@ """

Set values for attack state. """ self.attacked_enemy = enemy - self.x_vel = 1 + self.x_vel = -5 self.state = 'attack' def attack(self):

@@ -322,6 +323,39 @@ self.state = 'battle resting'

self.image = self.spritesheet_dict['facing left 2'] self.image = pg.transform.scale2x(self.image) self.observer.on_notify(c.PLAYER_FINISHED_ATTACK) + + def enter_enemy_attack_state(self): + """ + Set values for enemy attack state. + """ + self.x_vel = -5 + self.state = 'enemy attack' + self.origin_pos = self.rect.topleft + self.move_counter = 0 + + def enemy_attack(self): + """ + Enemy does an attack animation. + """ + FAST_LEFT = -5 + FAST_RIGHT = 5 + STARTX = self.origin_pos[0] + + self.rect.x += self.x_vel + + if self.move_counter == 3: + self.x_vel = 0 + self.state = 'battle resting' + self.rect.x = STARTX + + elif self.x_vel == FAST_LEFT: + if self.rect.x <= (STARTX - 15): + self.x_vel = FAST_RIGHT + elif self.x_vel == FAST_RIGHT: + if self.rect.x >= (STARTX + 15): + self.move_counter += 1 + self.x_vel = FAST_LEFT +
M data/observer.pydata/observer.py

@@ -76,7 +76,8 @@ self.info_box.state = c.SELECT_MAGIC

self.arrow.become_select_magic_state() def enemy_attack(self): - pass + enemy = self.level.enemy_list[self.level.enemy_index] + enemy.enter_enemy_attack_state() def player_attack(self): enemy_posx = self.arrow.rect.x + 60
M data/states/battle.pydata/states/battle.py

@@ -20,7 +20,8 @@ self.allow_input = False

self.allow_info_box_change = False self.game_data = game_data self.background = self.make_background() - self.enemy_group, self.enemy_pos_list = self.make_enemies() + self.enemy_group, self.enemy_pos_list, self.enemy_list = self.make_enemies() + self.enemy_index = 0 self.player = self.make_player() self.attack_animations = pg.sprite.Group() self.info_box = battlegui.InfoBox(game_data)

@@ -69,8 +70,11 @@

for i, enemy in enumerate(enemy_group): enemy.rect.topleft = pos_list[i] enemy.image = pg.transform.scale2x(enemy.image) + enemy.index = i + + enemy_list = [enemy for enemy in enemy_group] - return enemy_group, pos_list[0:len(enemy_group)] + return enemy_group, pos_list[0:len(enemy_group)], enemy_list def make_player(self): """Make the sprite for the player's character"""

@@ -122,7 +126,7 @@ self.state = c.ENEMY_DEAD

self.info_box.state = c.ENEMY_DEAD elif self.state == c.ENEMY_DEAD: - self.state = c.SELECT_ACTION + self.state = c.ENEMY_ATTACK self.notify(self.state) elif self.state == c.SELECT_ITEM or self.state == c.SELECT_MAGIC:

@@ -161,6 +165,7 @@ enemy = self.player.attacked_enemy

if enemy: enemy.kill() + self.enemy_list.pop(enemy.index) posx = enemy.rect.x - 32 posy = enemy.rect.y - 64 fire_sprite = attack.Fire(posx, posy)