all repos — Legends-RPG @ c00a96d3b62fa0d580bba601b8f00a621b26947a

A fantasy mini-RPG built with Python and Pygame.

Improving player menu.
Justin Armstrong justinmeister@gmail.com
Sat, 24 May 2014 14:29:20 -0700
commit

c00a96d3b62fa0d580bba601b8f00a621b26947a

parent

d4842499160b2b7f27df95928231834d218d5ff4

6 files changed, 59 insertions(+), 59 deletions(-)

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

@@ -408,7 +408,7 @@ Basic health meter for player.

""" def __init__(self, select_box_rect, game_data): self.health_stats = game_data['player stats']['health'] - self.magic_stats = game_data['player stats']['magic points'] + self.magic_stats = game_data['player stats']['magic'] self.title_font = pg.font.Font(setup.FONTS[c.MAIN_FONT], 22) self.posx = select_box_rect.centerx self.posy = select_box_rect.y - 5
M data/constants.pydata/constants.py

@@ -35,9 +35,7 @@ RED = 255, 0, 0

GREEN = 0, 255, 0 PINK = 208, 32, 144 - MAIN_FONT = 'DroidSans' - #BATTLE STATES
M data/menugui.pydata/menugui.py

@@ -20,7 +20,6 @@ self.state_dict = self.make_state_dict()

self.slots = info_box.slots self.pos_list = [] - def make_state_dict(self): """Make state dictionary""" state_dict = {'selectmenu': self.navigate_select_menu,

@@ -29,12 +28,10 @@ 'magicsubmenu': self.navigate_magic_submenu}

return state_dict - def navigate_select_menu(self, pos_index): """Nav the select menu""" self.pos_list = self.make_select_menu_pos_list() self.rect.topleft = self.pos_list[pos_index] - def navigate_item_submenu(self, pos_index): """Nav the item submenu"""

@@ -60,7 +57,7 @@ """Make the list of possible arrow positions"""

pos_list = [] for i in range(4): - pos = (35, 356 + (i * 50)) + pos = (35, 452 + (i * 50)) pos_list.append(pos) return pos_list

@@ -77,53 +74,69 @@ (535, 478),

(535, 528)] return pos_list - def update(self, pos_index): """Update arrow position""" state_function = self.state_dict[self.state] state_function(pos_index) - def draw(self, surface): """Draw to surface""" surface.blit(self.image, self.rect) - class GoldBox(pg.sprite.Sprite): - def __init__(self, inventory): - self.inventory = inventory + def __init__(self, game_data): + self.inventory = game_data['player inventory'] + self.game_data = game_data + self.health = game_data['player stats']['health'] + self.stats = self.game_data['player stats'] self.font = pg.font.Font(setup.FONTS[c.MAIN_FONT], 22) + self.small_font = pg.font.Font(setup.FONTS[c.MAIN_FONT], 18) self.image, self.rect = self.make_image() def make_image(self): - """Make the surface for the gold box""" - image = setup.GFX['goldbox2'] - rect = image.get_rect(left=10, top=234) + """ + Make the surface for the gold box. + """ + stat_list = ['GOLD', 'health', 'magic'] + magic_health_list = ['health', 'magic'] + image = setup.GFX['goldbox'] + rect = image.get_rect(left=10, top=244) surface = pg.Surface(rect.size) surface.set_colorkey(c.BLACK) surface.blit(image, (0, 0)) - text = "Gold: " + str(self.inventory['GOLD']['quantity']) - text_render = self.font.render(text, True, c.NEAR_BLACK) - text_rect = text_render.get_rect(centerx=130, - centery=35) - surface.blit(text_render, text_rect) - + for i, stat in enumerate(stat_list): + first_letter = stat[0].upper() + rest_of_letters = stat[1:] + if stat in magic_health_list: + current = self.stats[stat]['current'] + max = self.stats[stat]['maximum'] + text = "{}{}: {}/{}".format(first_letter, rest_of_letters, current, max) + elif stat == 'GOLD': + text = "{}: {}".format(stat, self.inventory[stat]['quantity']) + render = self.small_font.render(text, True, c.NEAR_BLACK) + x = 16 + y = 25 + (i*30) + text_rect = render.get_rect(x=x, + centery=y) + surface.blit(render, text_rect) + return surface, rect - def update(self): - """Update gold""" + """ + Update gold. + """ self.image, self.rect = self.make_image() - def draw(self, surface): - """Draw to surface""" + """ + Draw to surface. + """ surface.blit(self.image, self.rect) - class InfoBox(pg.sprite.Sprite):

@@ -145,7 +158,7 @@ self.possible_weapons = ['Long Sword', 'Rapier']

self.possible_magic = ['Fire Blast', 'Cure'] self.quantity_items = ['Healing Potion', 'ELIXIR', 'Ether Potion'] self.slots = {} - self.state = 'stats' + self.state = 'items' self.state_dict = self.make_state_dict() self.print_slots = True

@@ -163,11 +176,11 @@ def show_player_stats(self):

"""Show the player's main stats""" title = 'STATS' stat_list = ['Level', 'health', - 'magic points', 'experience to next level'] + 'magic', 'experience to next level'] surface, rect = self.make_blank_info_box(title) for i, stat in enumerate(stat_list): - if stat == 'health' or stat == 'magic points': + if stat == 'health' or stat == 'magic': text = "{}{}: {} / {}".format(stat[0].upper(), stat[1:], str(self.player_stats[stat]['current']),

@@ -321,9 +334,9 @@ self.image, self.rect = self.make_image()

def make_image(self): - choices = ['Stats', 'Items', 'Magic', 'Exit'] - image = setup.GFX['selectionbox'] - rect = image.get_rect(left=10, top=330) + choices = ['Items', 'Magic'] + image = setup.GFX['goldbox'] + rect = image.get_rect(left=10, top=425) surface = pg.Surface(rect.size) surface.set_colorkey(c.BLACK)

@@ -335,7 +348,6 @@ choice_rect = choice_image.get_rect(x=100, y=(25 + (i * 50)))

surface.blit(choice_image, choice_rect) return surface, rect - def draw(self, surface): """Draw to surface"""

@@ -351,12 +363,11 @@ self.game_data = self.level.game_data

self.inventory = inventory self.stats = stats self.info_box = InfoBox(inventory, stats) - self.gold_box = GoldBox(inventory) + self.gold_box = GoldBox(self.game_data) self.selection_box = SelectionBox() self.arrow = SmallArrow(self.info_box) self.arrow_index = 0 self.allow_input = False - self.state = 'stats' def check_for_input(self, keys):

@@ -386,18 +397,9 @@ self.arrow_index = 0

elif keys[pg.K_SPACE]: if self.arrow.state == 'selectmenu': if self.arrow_index == 0: - self.info_box.state = 'stats' - + self.info_box.state = 'items' elif self.arrow_index == 1: - self.info_box.state = 'items' - - elif self.arrow_index == 2: self.info_box.state = 'magic' - - 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() elif self.arrow.state == 'magicsubmenu':

@@ -406,7 +408,7 @@

self.allow_input = False elif keys[pg.K_RETURN]: self.level.state = 'normal' - self.info_box.state = 'stats' + self.info_box.state = 'items' self.allow_input = False self.arrow_index = 0 self.arrow.state = 'selectmenu'

@@ -432,7 +434,7 @@ value = 30

self.drink_potion(potion, health, value) elif self.info_box.slots[(posx, posy)][:5] == 'Ether': potion = 'Ether Potion' - stat = self.game_data['player stats']['magic points'] + stat = self.game_data['player stats']['magic'] value = 30 self.drink_potion(potion, stat, value) elif self.info_box.slots[(posx, posy)][:10] == 'Long Sword':

@@ -455,7 +457,7 @@ """

Select spell from magic menu. """ health = self.game_data['player stats']['health'] - magic = self.game_data['player stats']['magic points'] + magic = self.game_data['player stats']['magic'] posx = self.arrow.rect.x - 190 posy = self.arrow.rect.y - 39

@@ -468,10 +470,10 @@ """

Use cure spell to heal player. """ health = self.game_data['player stats']['health'] - magic = self.game_data['player stats']['magic points'] + magic = self.game_data['player stats']['magic'] inventory = self.game_data['player inventory'] - if magic['current'] > inventory['Cure']['magic points']: + if magic['current'] >= inventory['Cure']['magic points']: magic['current'] -= inventory['Cure']['magic points'] health['current'] += inventory['Cure']['power'] if health['current'] > health['maximum']:
M data/shopgui.pydata/shopgui.py

@@ -298,7 +298,7 @@ power = item['power']

magic_list = ['Cure', 'Fire Blast'] player_items = self.level.game_data['player inventory'] player_health = self.level.game_data['player stats']['health'] - player_magic = self.level.game_data['player stats']['magic points'] + player_magic = self.level.game_data['player stats']['magic'] item_to_add = {'quantity': quantity, 'value': value,
M data/states/battle.pydata/states/battle.py

@@ -194,11 +194,11 @@ elif self.state == c.SELECT_MAGIC:

if self.arrow.index == (len(self.arrow.pos_list) - 1): self.enter_select_action_state() elif self.info_box.magic_text_list[self.arrow.index] == 'Cure': - if self.game_data['player stats']['magic points']['current'] >= 25: + if self.game_data['player stats']['magic']['current'] >= 25: self.player_actions.append(c.CURE_SPELL) self.action_selected = True elif self.info_box.magic_text_list[self.arrow.index] == 'Fire Blast': - if self.game_data['player stats']['magic points']['current'] >= 25: + if self.game_data['player stats']['magic']['current'] >= 25: self.player_actions.append(c.FIRE_SPELL) self.action_selected = True

@@ -280,7 +280,7 @@ player_stats['experience to next level'] -= self.experience_points

if player_stats['experience to next level'] <= 0: player_stats['Level'] += 1 player_stats['health']['maximum'] += int(player_stats['health']['maximum']*.25) - player_stats['magic points']['maximum'] += int(player_stats['magic points']['maximum']*.20) + player_stats['magic']['maximum'] += int(player_stats['magic']['maximum']*.20) new_experience = int((player_stats['Level'] * 100) * .75) player_stats['experience to next level'] = new_experience self.enter_level_up_state()

@@ -373,13 +373,13 @@ self.game_data['player inventory']['Healing Potion']['quantity'] -= 1

if self.game_data['player inventory']['Healing Potion']['quantity'] == 0: del self.game_data['player inventory']['Healing Potion'] elif self.state == c.CURE_SPELL: - self.game_data['player stats']['magic points']['current'] -= magic_points + self.game_data['player stats']['magic']['current'] -= magic_points def magic_boost(self, magic_points): """ Add magic from ether to game data. """ - magic = self.game_data['player stats']['magic points'] + magic = self.game_data['player stats']['magic'] magic['current'] += magic_points if magic['current'] > magic['maximum']: magic['current'] = magic['maximum']

@@ -398,8 +398,8 @@ Cast fire blast on all enemies.

""" self.state = self.info_box.state = c.FIRE_SPELL POWER = self.inventory['Fire Blast']['power'] - MAGIC_POINTS = self.inventory['Fire Blast']['magic points'] - self.game_data['player stats']['magic points']['current'] -= MAGIC_POINTS + MAGIC_POINTS = self.inventory['Fire Blast']['magic'] + self.game_data['player stats']['magic']['current'] -= MAGIC_POINTS for enemy in self.enemy_list: DAMAGE = random.randint(POWER//2, POWER) self.damage_points.add(
M data/tools.pydata/tools.py

@@ -194,7 +194,7 @@

player_stats = {'health': player_health, 'Level': 2, 'experience to next level': 20, - 'magic points': player_magic, + 'magic': player_magic, 'attack points': 10, 'Defense Points': 10}