all repos — Legends-RPG @ 61f0da87462ae50df935f65a5aa2cdade74d8ad3

A fantasy mini-RPG built with Python and Pygame.

Arrow positions for dead monsters are now deleted.
Justin Armstrong justinmeister@gmail.com
Mon, 21 Apr 2014 18:54:52 -0700
commit

61f0da87462ae50df935f65a5aa2cdade74d8ad3

parent

83af8e19d1806b1256852088fd7dc4ecbfddca80

3 files changed, 27 insertions(+), 12 deletions(-)

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

@@ -212,9 +212,11 @@ """

Select what enemy you want to take action on. """ self.pos_list = self.enemy_pos_list - pos = self.pos_list[self.index] - self.rect.x = pos[0] - 60 - self.rect.y = pos[1] + 20 + + if self.pos_list: + pos = self.pos_list[self.index] + self.rect.x = pos[0] - 60 + self.rect.y = pos[1] + 20 if self.allow_input: if keys[pg.K_DOWN] and self.index < (len(self.pos_list) - 1):

@@ -262,3 +264,10 @@ Draw to surface.

""" surface.blit(self.image, self.rect) + def remove_pos(self, enemy): + enemy_list = self.enemy_pos_list + enemy_pos = list(enemy.rect.topleft) + + self.enemy_pos_list = [pos for pos in enemy_list if pos != enemy_pos] + +
M data/observer.pydata/observer.py

@@ -87,14 +87,8 @@ def attack_animation(self):

""" Make an attack animation over attacked enemy. """ - enemy = self.player.attacked_enemy - if enemy: - enemy.kill() - posx = enemy.rect.x - 32 - posy = enemy.rect.y - 64 - fire_sprite = attack.Fire(posx, posy) - self.level.attack_animations.add(fire_sprite) - + self.arrow.remove_pos(self.player.attacked_enemy) + self.level.attack_enemy() self.info_box.state = c.ENEMY_HIT def run_away(self):
M data/states/battle.pydata/states/battle.py

@@ -4,8 +4,9 @@

import random import pygame as pg from .. import tools, battlegui, observer -from .. components import person +from .. components import person, attack from .. import constants as c + class Battle(tools._State):

@@ -145,6 +146,17 @@ End battle and flip back to previous state.

""" self.game_data['last state'] = self.name self.done = True + + def attack_enemy(self): + enemy = self.player.attacked_enemy + + if enemy: + enemy.kill() + posx = enemy.rect.x - 32 + posy = enemy.rect.y - 64 + fire_sprite = attack.Fire(posx, posy) + self.attack_animations.add(fire_sprite) + self.player.attacked_enemy = None def draw_battle(self, surface): """Draw all elements of battle state"""