all repos — Legends-RPG @ 107c8c01760c5aab0de838393c6aceca60c3b1dc

A fantasy mini-RPG built with Python and Pygame.

Can move in and out of item menu in battle, fixed some index error bugs.
Justin Armstrong justinmeister@gmail.com
Mon, 21 Apr 2014 19:36:30 -0700
commit

107c8c01760c5aab0de838393c6aceca60c3b1dc

parent

61f0da87462ae50df935f65a5aa2cdade74d8ad3

3 files changed, 49 insertions(+), 14 deletions(-)

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

@@ -157,7 +157,8 @@

class SelectArrow(object): """Small arrow for menu""" - def __init__(self, enemy_pos_list): + def __init__(self, enemy_pos_list, info_box): + self.info_box = info_box self.image = setup.GFX['smallarrow'] self.rect = self.image.get_rect() self.state = 'select action'

@@ -171,7 +172,8 @@

def make_state_dict(self): """Make state dictionary""" state_dict = {'select action': self.select_action, - 'select enemy': self.select_enemy} + 'select enemy': self.select_enemy, + 'select item': self.select_item} return state_dict

@@ -182,17 +184,7 @@ """

self.pos_list = self.make_select_action_pos_list() self.rect.topleft = self.pos_list[self.index] - if self.allow_input: - if keys[pg.K_DOWN] and self.index < (len(self.pos_list) - 1): - self.index += 1 - self.allow_input = False - elif keys[pg.K_UP] and self.index > 0: - self.index -= 1 - self.allow_input = False - - if keys[pg.K_DOWN] == False and keys[pg.K_UP] == False: - self.allow_input = True - + self.check_input(keys) def make_select_action_pos_list(self): """

@@ -218,6 +210,9 @@ pos = self.pos_list[self.index]

self.rect.x = pos[0] - 60 self.rect.y = pos[1] + 20 + self.check_input(keys) + + def check_input(self, keys): if self.allow_input: if keys[pg.K_DOWN] and self.index < (len(self.pos_list) - 1): self.index += 1

@@ -231,6 +226,34 @@ if keys[pg.K_DOWN] == False and keys[pg.K_UP] == False \

and keys[pg.K_RIGHT] == False and keys[pg.K_LEFT] == False: self.allow_input = True + def select_item(self, keys): + """ + Select item to use. + """ + self.pos_list = self.make_select_item_pos_list() + + pos = self.pos_list[self.index] + self.rect.x = pos[0] - 60 + self.rect.y = pos[1] + 20 + + self.check_input(keys) + + def make_select_item_pos_list(self): + """ + Make the coordinates for the arrow for the item select screen. + """ + pos_list = [] + text_list = self.info_box.make_item_text() + text_list = text_list[1:] + + for i in range(len(text_list)): + left = 90 + top = (i * 29) + 488 + pos_list.append((left, top)) + + return pos_list + + def become_invisible_surface(self): """ Make image attribute an invisible surface.

@@ -238,6 +261,9 @@ """

self.image = pg.Surface((32, 32)) self.image.set_colorkey(c.BLACK) + def become_select_item_state(self): + self.index = 0 + self.state = c.SELECT_ITEM def enter_select_action(self): """
M data/observer.pydata/observer.py

@@ -61,11 +61,13 @@ self.info_box.state = c.SELECT_ACTION

def select_enemy(self): self.level.state = c.SELECT_ENEMY + self.arrow.index = 0 self.arrow.state = c.SELECT_ENEMY def select_item(self): self.level.state = c.SELECT_ITEM self.info_box.state = c.SELECT_ITEM + self.arrow.become_select_item_state() def enemy_attack(self): pass

@@ -88,6 +90,7 @@ """

Make an attack animation over attacked enemy. """ self.arrow.remove_pos(self.player.attacked_enemy) + self.arrow.state = c.SELECT_ACTION self.level.attack_enemy() self.info_box.state = c.ENEMY_HIT
M data/states/battle.pydata/states/battle.py

@@ -24,7 +24,8 @@ self.enemy_group, self.enemy_pos_list = self.make_enemies()

self.player = self.make_player() self.attack_animations = pg.sprite.Group() self.info_box = battlegui.InfoBox(game_data) - self.arrow = battlegui.SelectArrow(self.enemy_pos_list) + self.arrow = battlegui.SelectArrow(self.enemy_pos_list, + self.info_box) self.attacked_enemy = None self.attacking_enemy = None self.select_box = battlegui.SelectBox()

@@ -120,6 +121,11 @@

elif self.state == c.ENEMY_DEAD: self.state = c.SELECT_ACTION self.notify(self.state) + + elif self.state == c.SELECT_ITEM: + if self.arrow.index == (len(self.arrow.pos_list) - 1): + self.state = c.SELECT_ACTION + self.notify(self.state) self.allow_input = False