all repos — Legends-RPG @ 7f3c4199a540d84af6027570cea264e34480d310

A fantasy mini-RPG built with Python and Pygame.

Enemies do damage to player, prompts input after every enemy attack.
Justin Armstrong justinmeister@gmail.com
Sat, 26 Apr 2014 11:49:51 -0700
commit

7f3c4199a540d84af6027570cea264e34480d310

parent

143e33398571ea292900a7201095b1086c6d8a47

5 files changed, 33 insertions(+), 6 deletions(-)

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

@@ -37,7 +37,8 @@ c.ENEMY_ATTACK: 'Enemy attacks player!',

c.PLAYER_ATTACK: 'Player attacks enemy.', c.RUN_AWAY: 'Run away', c.ENEMY_HIT: 'Enemy hit with 20 damage.', - c.ENEMY_DEAD: 'Enemy killed.'} + c.ENEMY_DEAD: 'Enemy killed.', + c.DISPLAY_ENEMY_ATTACK_DAMAGE: 'Player hit with 5 damage'} return state_dict

@@ -119,7 +120,7 @@ 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: + 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

@@ -366,7 +367,13 @@ Make the image surface for the player

""" current_health = str(self.health_stats['current']) max_health = str(self.health_stats['maximum']) - health_string = "Health: " + current_health + "/" + max_health + if len(current_health) == 2: + buffer = ' ' + elif len(current_health) == 1: + buffer = ' ' + else: + buffer = '' + health_string = "Health: " + buffer + current_health + "/" + max_health health_surface = self.title_font.render(health_string, True, c.NEAR_BLACK) health_rect = health_surface.get_rect(x=20, y=9)
M data/components/person.pydata/components/person.py

@@ -348,7 +348,7 @@ if self.move_counter == 3:

self.x_vel = 0 self.state = 'battle resting' self.rect.x = STARTX - self.notify(c.SWITCH_ENEMY) + self.notify(c.ENEMY_ATTACK_DAMAGE) elif self.x_vel == FAST_LEFT: if self.rect.x <= (STARTX - 15):
M data/constants.pydata/constants.py

@@ -46,6 +46,8 @@ BATTLE_WON = 'battle won'

ENEMY_HIT = 'enemy hit' ENEMY_DEAD = 'enemy dead' PLAYER_FINISHED_ATTACK = 'player finished attack' +ENEMY_ATTACK_DAMAGE = 'enemy attack damage' +DISPLAY_ENEMY_ATTACK_DAMAGE = 'display enemy attack damage' #EVENTS
M data/observer.pydata/observer.py

@@ -39,6 +39,7 @@ c.PLAYER_ATTACK: self.player_attack,

c.ATTACK_ANIMATION: self.attack_animation, c.RUN_AWAY: self.run_away, c.BATTLE_WON: self.battle_won, + c.ENEMY_ATTACK_DAMAGE: self.display_enemy_attack_damage, c.PLAYER_FINISHED_ATTACK: self.player_finished_attack} return event_dict

@@ -91,8 +92,13 @@ """Switch which enemy is attacking player."""

if self.level.enemy_index < len(self.level.enemy_list) - 1: self.level.enemy_index += 1 self.on_notify(c.ENEMY_ATTACK) - else: - self.on_notify(c.SELECT_ACTION) + + + 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.player_damaged(5) + def player_attack(self): enemy_posx = self.arrow.rect.x + 60
M data/states/battle.pydata/states/battle.py

@@ -16,6 +16,7 @@

def startup(self, current_time, game_data): """Initialize state attributes""" self.current_time = current_time + self.timer = current_time self.allow_input = False self.allow_info_box_change = False self.game_data = game_data

@@ -137,6 +138,14 @@ 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: + if self.enemy_index == (len(self.enemy_list) - 1): + self.state = c.SELECT_ACTION + else: + self.state = c.SWITCH_ENEMY + self.notify(self.state) + + self.allow_input = False if keys[pg.K_RETURN] == False and keys[pg.K_SPACE] == False:

@@ -194,5 +203,8 @@ surface.blit(self.select_box.image, self.select_box.rect)

surface.blit(self.arrow.image, self.arrow.rect) self.player_health.draw(surface) self.sword.draw(surface) + + def player_damaged(self, damage): + self.game_data['player stats']['Health']['current'] -= damage