all repos — Legends-RPG @ d96752daa4c3f2dd549a2434ddabf1086675b823

A fantasy mini-RPG built with Python and Pygame.

Attack damages and switching between enemies are all timed events now.
Justin Armstrong justinmeister@gmail.com
Sun, 27 Apr 2014 10:35:27 -0700
commit

d96752daa4c3f2dd549a2434ddabf1086675b823

parent

7f3c4199a540d84af6027570cea264e34480d310

3 files changed, 31 insertions(+), 20 deletions(-)

jump to
M data/battlegui.pydata/battlegui.py

@@ -21,9 +21,6 @@ self.font = pg.font.Font(setup.FONTS[c.MAIN_FONT], 18)

self.state_dict = self.make_state_dict() self.image = self.make_image() self.rect = self.image.get_rect(bottom=608) - self.arrow = textbox.NextArrow() - self.arrow.rect.topleft = (380, 55) - def make_state_dict(self): """

@@ -120,8 +117,6 @@ else:

text_surface = self.font.render(self.state_dict[self.state], True, c.NEAR_BLACK) text_rect = text_surface.get_rect(x=50, y=50) surface.blit(text_surface, text_rect) - if self.state == c.ENEMY_HIT or self.state == c.ENEMY_DEAD or self.state == c.DISPLAY_ENEMY_ATTACK_DAMAGE: - surface.blit(self.arrow.image, self.arrow.rect) return surface
M data/observer.pydata/observer.py

@@ -93,12 +93,11 @@ if self.level.enemy_index < len(self.level.enemy_list) - 1:

self.level.enemy_index += 1 self.on_notify(c.ENEMY_ATTACK) - def display_enemy_attack_damage(self): self.info_box.state = c.DISPLAY_ENEMY_ATTACK_DAMAGE self.level.state = c.DISPLAY_ENEMY_ATTACK_DAMAGE + self.level.set_timer_to_current_time() self.level.player_damaged(5) - def player_attack(self): enemy_posx = self.arrow.rect.x + 60

@@ -121,6 +120,8 @@ self.arrow.remove_pos(self.player.attacked_enemy)

self.arrow.state = c.SELECT_ACTION self.arrow.index = 0 self.level.attack_enemy() + self.level.set_timer_to_current_time() + self.level.state = c.ENEMY_HIT self.info_box.state = c.ENEMY_HIT def run_away(self):
M data/states/battle.pydata/states/battle.py

@@ -94,7 +94,9 @@ return dict(zip(pos_list, state_list))

def update(self, surface, keys, current_time): """Update the battle state""" + self.current_time = current_time self.check_input(keys) + self.check_for_timed_events() self.check_if_battle_won() self.enemy_group.update(current_time) self.player.update(keys, current_time)

@@ -126,30 +128,39 @@ elif self.state == c.PLAYER_ATTACK:

self.state = c.ENEMY_DEAD self.info_box.state = c.ENEMY_DEAD - elif self.state == c.ENEMY_DEAD: - if len(self.enemy_list): - self.state = c.ENEMY_ATTACK - else: - self.state = c.BATTLE_WON - self.notify(self.state) - elif self.state == c.SELECT_ITEM or self.state == c.SELECT_MAGIC: if self.arrow.index == (len(self.arrow.pos_list) - 1): self.state = c.SELECT_ACTION self.notify(self.state) - elif self.state == c.DISPLAY_ENEMY_ATTACK_DAMAGE: + self.allow_input = False + + if keys[pg.K_RETURN] == False and keys[pg.K_SPACE] == False: + self.allow_input = True + + def check_for_timed_events(self): + """ + Check if amount of time has passed for timed events. + """ + timed_states = [c.DISPLAY_ENEMY_ATTACK_DAMAGE, c.ENEMY_HIT, c.ENEMY_DEAD] + + if self.state in timed_states: + if (self.current_time - self.timer) > 1500: + if self.state == c.DISPLAY_ENEMY_ATTACK_DAMAGE: if self.enemy_index == (len(self.enemy_list) - 1): self.state = c.SELECT_ACTION else: self.state = c.SWITCH_ENEMY - self.notify(self.state) - + elif self.state == c.ENEMY_HIT: + self.state = c.ENEMY_DEAD + elif self.state == c.ENEMY_DEAD: + if len(self.enemy_list): + self.state = c.ENEMY_ATTACK + else: + self.state = c.BATTLE_WON - self.allow_input = False + self.notify(self.state) - if keys[pg.K_RETURN] == False and keys[pg.K_SPACE] == False: - self.allow_input = True def check_if_battle_won(self): """

@@ -206,5 +217,9 @@ self.sword.draw(surface)

def player_damaged(self, damage): self.game_data['player stats']['Health']['current'] -= damage + + def set_timer_to_current_time(self): + """Set the timer to the current time.""" + self.timer = self.current_time