Enemy becomes gradually transparent when it dies.
Justin Armstrong justinmeister@gmail.com
Tue, 06 May 2014 19:41:24 -0700
4 files changed,
30 insertions(+),
9 deletions(-)
M
data/components/person.py
→
data/components/person.py
@@ -11,6 +11,7 @@ controlled by the computer"""
def __init__(self, sheet_key, x, y, direction='down', state='resting', index=0): super(Person, self).__init__() + self.alpha = 255 self.name = sheet_key self.get_image = setup.tools.get_image self.spritesheet_dict = self.create_spritesheet_dict(sheet_key)@@ -38,6 +39,7 @@ self.wander_box = self.make_wander_box()
self.observers = [] self.level = 1 self.health = 0 + self.death_image = pg.transform.scale2x(self.image) def create_spritesheet_dict(self, sheet_key): """Implemented by inheriting classes"""@@ -88,7 +90,8 @@ 'attack': self.attack,
'enemy attack': self.enemy_attack, c.RUN_AWAY: self.run_away, c.VICTORY_DANCE: self.victory_dance, - c.KNOCK_BACK: self.knock_back} + c.KNOCK_BACK: self.knock_back, + c.FADE_DEATH: self.fade_death} return state_dict@@ -429,6 +432,19 @@ elif self.rect.x >= self.origin_pos[0]:
self.rect.x = self.origin_pos[0] self.state = 'battle resting' self.x_vel = 0 + + def fade_death(self): + """ + Make character become transparent in death. + """ + self.image = pg.Surface((64, 64)).convert() + self.image.set_colorkey(c.BLACK) + self.image.set_alpha(self.alpha) + self.image.blit(self.death_image, (0, 0)) + self.alpha -= 8 + if self.alpha <= 0: + self.kill() + self.notify(c.ENEMY_DEAD) def enter_knock_back_state(self):
M
data/constants.py
→
data/constants.py
@@ -58,6 +58,7 @@ FIRE_SPELL = 'fire spell'
VICTORY_DANCE = 'victory dance' KNOCK_BACK = 'knock back' FLEE = 'flee' +FADE_DEATH = 'fade death' #EVENTS
M
data/observer.py
→
data/observer.py
@@ -36,6 +36,7 @@ c.SELECT_ITEM: self.select_item,
c.SELECT_ENEMY: self.select_enemy, c.SELECT_MAGIC: self.select_magic, c.ENEMY_ATTACK: self.enemy_attack, + c.ENEMY_DEAD: self.enemy_dead, c.SWITCH_ENEMY: self.switch_enemy, c.PLAYER_ATTACK: self.player_attack, c.ATTACK_ANIMATION: self.enemy_damaged,@@ -193,12 +194,19 @@ Cast cure spell on player.
""" self.level.cast_cure() - def fire_spell(self): """ Cast fire spell on all enemies. """ self.level.cast_fire_blast() + + def enemy_dead(self): + """ + Eliminate all traces of enemy. + """ + self.player.attacked_enemy = None + +
M
data/states/battle.py
→
data/states/battle.py
@@ -194,7 +194,7 @@ c.DRINK_ETHER_POTION]
long_delay = timed_states[1:] if self.state in long_delay: - if (self.current_time - self.timer) > 800: + if (self.current_time - self.timer) > 1000: if self.state == c.ENEMY_HIT: if len(self.enemy_list): self.state = c.ENEMY_ATTACK@@ -266,15 +266,11 @@
if enemy: enemy.enter_knock_back_state() if enemy.health <= 0: - enemy.kill() self.enemy_list.pop(enemy.index) + enemy.state = c.FADE_DEATH + self.notify(c.FADE_DEATH) self.arrow.remove_pos(self.player.attacked_enemy) - posx = enemy.rect.x - 32 - posy = enemy.rect.y - 64 - fire_sprite = attack.Fire(posx, posy) - self.attack_animations.add(fire_sprite) self.enemy_index = 0 - self.player.attacked_enemy = None def set_enemy_indices(self): for i, enemy in enumerate(self.enemy_list):