all repos — Legends-RPG @ cd7f046fd56e95bda0da95b6a8b9a192e10aa6c0

A fantasy mini-RPG built with Python and Pygame.

Added fire blast to battle.
Justin Armstrong justinmeister@gmail.com
Fri, 02 May 2014 10:57:45 -0700
commit

cd7f046fd56e95bda0da95b6a8b9a192e10aa6c0

parent

468b0801c22e6e19227024b6258b56aadd4d3da3

3 files changed, 57 insertions(+), 7 deletions(-)

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

@@ -52,6 +52,7 @@ ENEMY_ATTACK_DAMAGE = 'enemy attack damage'

DISPLAY_ENEMY_ATTACK_DAMAGE = 'display enemy attack damage' DRINK_HEALING_POTION = 'drink healing potion' CURE_SPELL = 'cure spell' +FIRE_SPELL = 'fire spell' #EVENTS
M data/observer.pydata/observer.py

@@ -43,7 +43,8 @@ c.RUN_AWAY: self.run_away,

c.BATTLE_WON: self.battle_won, c.ENEMY_ATTACK_DAMAGE: self.display_enemy_attack_damage, c.DRINK_HEALING_POTION: self.drink_healing_potion, - c.CURE_SPELL: self.cure_spell} + c.CURE_SPELL: self.cure_spell, + c.FIRE_SPELL: self.fire_spell} return event_dict

@@ -178,6 +179,15 @@ self.level.damage_points.add(

attackitems.HealthPoints(50, self.player.rect.topright, False)) self.level.player_healed(50) self.info_box.state = c.DRINK_HEALING_POTION + + def fire_spell(self): + """ + Cast fire spell on all enemies. + """ + self.level.cast_fire_blast() + self.level.state = c.FIRE_SPELL + self.level.set_timer_to_current_time() +
M data/states/battle.pydata/states/battle.py

@@ -61,6 +61,7 @@

self.select_action_state_dict = self.make_selection_state_dict() self.observers = [observer.Battle(self)] self.player.observers.extend(self.observers) + self.damage_points = pg.sprite.Group() @staticmethod def make_background():

@@ -164,8 +165,13 @@ if self.arrow.index == (len(self.arrow.pos_list) - 1):

self.state = c.SELECT_ACTION self.notify(self.state) elif self.info_box.magic_text_list[self.arrow.index] == 'Cure': - self.state = c.CURE_SPELL - self.notify(self.state) + if self.game_data['player stats']['magic points']['current'] >= 25: + self.state = c.CURE_SPELL + self.notify(self.state) + elif self.info_box.magic_text_list[self.arrow.index] == 'Fire Blast': + if self.game_data['player stats']['magic points']['current'] >= 75: + self.state = c.FIRE_SPELL + self.notify(self.state) self.allow_input = False

@@ -180,11 +186,12 @@ timed_states = [c.DISPLAY_ENEMY_ATTACK_DAMAGE,

c.ENEMY_HIT, c.ENEMY_DEAD, c.DRINK_HEALING_POTION, - c.CURE_SPELL] + c.CURE_SPELL, + c.FIRE_SPELL] long_delay = timed_states[1:] if self.state in long_delay: - if (self.current_time - self.timer) > 600: + if (self.current_time - self.timer) > 800: if self.state == c.ENEMY_HIT: self.state = c.ENEMY_DEAD elif self.state == c.ENEMY_DEAD:

@@ -192,8 +199,13 @@ if len(self.enemy_list):

self.state = c.ENEMY_ATTACK else: self.state = c.BATTLE_WON - elif self.state == c.DRINK_HEALING_POTION or self.state == c.CURE_SPELL: - self.state = c.ENEMY_ATTACK + elif (self.state == c.DRINK_HEALING_POTION or + self.state == c.CURE_SPELL or + self.state == c.FIRE_SPELL): + if len(self.enemy_list): + self.state = c.ENEMY_ATTACK + else: + self.state = c.BATTLE_WON self.timer = self.current_time self.notify(self.state)

@@ -283,5 +295,32 @@

def set_timer_to_current_time(self): """Set the timer to the current time.""" self.timer = self.current_time + + def cast_fire_blast(self): + """ + Cast fire blast on all enemies. + """ + DAMAGE = 5 + MAGIC_POINTS = 75 + self.game_data['player stats']['magic points']['current'] -= MAGIC_POINTS + for enemy in self.enemy_list: + self.damage_points.add( + attackitems.HealthPoints(DAMAGE, enemy.rect.topright)) + enemy.health -= DAMAGE + posx = enemy.rect.x - 32 + posy = enemy.rect.y - 64 + fire_sprite = attack.Fire(posx, posy) + self.attack_animations.add(fire_sprite) + if enemy.health <= 0: + enemy.kill() + self.arrow.remove_pos(enemy) + self.enemy_list = [enemy for enemy in self.enemy_list if enemy.health > 0] + self.enemy_index = 0 + self.arrow.index = 0 + self.arrow.become_invisible_surface() + self.arrow.state = c.SELECT_ACTION + + +