all repos — Legends-RPG @ 0e61bf196e004c9c59c8ccec24e4fed83faa4610

A fantasy mini-RPG built with Python and Pygame.

Player can now use potions from the player menu.
Justin Armstrong justinmeister@gmail.com
Wed, 07 May 2014 10:52:22 -0700
commit

0e61bf196e004c9c59c8ccec24e4fed83faa4610

parent

c6b5b5cb031ab81893532d4514cedf0cb3d0d70e

1 files changed, 35 insertions(+), 1 deletions(-)

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

@@ -187,6 +187,7 @@ armor.append(item)

elif item in self.possible_potions: potions.append(item) + self.slots = {} self.assign_slots(weapons, 85) self.assign_slots(armor, 235) self.assign_slots(potions, 390)

@@ -319,6 +320,7 @@

class MenuGui(object): def __init__(self, level, inventory, stats): self.level = level + self.game_data = self.level.game_data self.inventory = inventory self.stats = stats self.info_box = InfoBox(inventory, stats)

@@ -365,7 +367,8 @@ elif self.arrow_index == 3:

self.level.state = 'normal' self.arrow_index = 0 self.info_box.state = 'stats' - + elif self.arrow.state == 'itemsubmenu': + self.select_item() self.allow_input = False elif keys[pg.K_RETURN]:

@@ -373,6 +376,7 @@ self.level.state = 'normal'

self.info_box.state = 'stats' self.allow_input = False self.arrow_index = 0 + self.arrow.state = 'selectmenu' if (not keys[pg.K_DOWN] and not keys[pg.K_UP]

@@ -380,6 +384,36 @@ and not keys[pg.K_RETURN]

and not keys[pg.K_SPACE]): self.allow_input = True + def select_item(self): + """ + Select item from item menu. + """ + health = self.game_data['player stats']['health'] + posx = self.arrow.rect.x - 220 + posy = self.arrow.rect.y - 38 + + if (posx, posy) in self.info_box.slots: + if self.info_box.slots[(posx, posy)][:7] == 'Healing': + potion = 'Healing Potion' + stat = self.game_data['player stats']['health'] + value = 30 + self.drink_potion(potion, stat, value) + elif self.info_box.slots[(posx, posy)][:5] == 'Ether': + potion = 'Ether Potion' + stat = self.game_data['player stats']['magic points'] + value = 30 + self.drink_potion(potion, stat, value) + + def drink_potion(self, potion, stat, value): + """ + Drink potion and change player stats. + """ + self.inventory[potion]['quantity'] -= 1 + stat['current'] += value + if stat['current'] > stat['maximum']: + stat['current'] = stat['maximum'] + if not self.inventory[potion]['quantity']: + del self.inventory[potion] def update(self, keys): self.info_box.update()