all repos — Legends-RPG @ 3033ec723dbf8059aad0a4e2b087d5ed2fca6c5f

A fantasy mini-RPG built with Python and Pygame.

Added stats to menu screen
Justin Armstrong justinmeister@gmail.com
Tue, 01 Apr 2014 10:25:45 -0700
commit

3033ec723dbf8059aad0a4e2b087d5ed2fca6c5f

parent

cc5415b4ae455bd90a3ba7e4e0e42dc9b3e9811d

M data/constants.pydata/constants.py

@@ -25,7 +25,7 @@ LIGHT_BLUE = (0, 153, 204)

DARK_RED = (118, 27, 12) -MAIN_FONT = 'DroidSerif' +MAIN_FONT = 'DroidSans'
M data/menugui.pydata/menugui.py

@@ -16,10 +16,13 @@ self.rect = self.image.get_rect()

class MenuGui(object): - def __init__(self, level, inventory): + def __init__(self, level, inventory, stats): self.level = level self.font = pg.font.Font(setup.FONTS[c.MAIN_FONT], 22) + self.title_font = pg.font.Font(setup.FONTS[c.MAIN_FONT], 24) + self.title_font.set_underline(True) self.inventory = inventory + self.stats = stats self.allow_input = False self.state = 'topmenu' self.gold_box = None

@@ -64,15 +67,30 @@

return sprite - def make_stat_box(self): + def make_stat_box(self, title, stat_list): """Make the box for displaying stats and items""" image = setup.GFX['playerstatsbox'] rect = image.get_rect(left=285, top=35) + centerx = rect.width / 2 surface = pg.Surface(rect.size) surface.set_colorkey(c.BLACK) surface.blit(image, (0,0)) + title_image = self.title_font.render(title, True, c.NEAR_BLACK) + title_rect = title_image.get_rect(centerx=centerx, y=30) + surface.blit(title_image, title_rect) + + for i, stat in enumerate(stat_list): + if stat == 'Health' or stat == 'Magic Points': + text = (stat + ": " + str(self.stats[stat]['current']) + + " / " + str(self.stats[stat]['maximum'])) + else: + text = stat + ": " + str(self.stats[stat]) + text_image = self.font.render(text, True, c.NEAR_BLACK) + text_rect = text_image.get_rect(x=50, y=80+(i*70)) + surface.blit(text_image, text_rect) + sprite = pg.sprite.Sprite() sprite.image = surface sprite.rect = rect

@@ -119,9 +137,12 @@

def select_main_options(self, keys): """Allow player to select items, magic, weapons and armor""" choices = ['Equip', 'Items', 'Magic', 'Exit'] + title = 'PLAYER STATS' + stats = ['Level', 'Health', 'Experience to next level', + 'Magic Points', 'Attack Points', 'Defense Points' ] self.selection_box = self.make_selection_box(choices) self.gold_box = self.make_gold_box() - self.stat_box = self.make_stat_box() + self.stat_box = self.make_stat_box(title, stats) self.arrow.rect.topleft = self.arrow_pos[self.arrow_index] if self.allow_input:

@@ -136,8 +157,12 @@ self.allow_input = False

elif keys[pg.K_SPACE]: if self.arrow_index == len(choices) - 1: self.level.done = True + elif keys[pg.K_RETURN]: + self.level.done = True - if not keys[pg.K_DOWN] and not keys[pg.K_UP]: + if (not keys[pg.K_DOWN] + and not keys[pg.K_UP] + and not keys[pg.K_RETURN]): self.allow_input = True
M data/shopgui.pydata/shopgui.py

@@ -289,6 +289,8 @@ item_type = item['type']

quantity = item['quantity'] value = item['price'] 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'] item_to_add = {'quantity': quantity, 'value': value}

@@ -297,6 +299,9 @@ if item_type in player_items:

player_items[item_type]['quantity'] += quantity elif quantity > 0: player_items[item_type] = item_to_add + elif item_type == 'room': + player_health['current'] = player_health['maximum'] + player_magic['current'] = player_magic['maximum'] def confirm_sell(self, keys, current_time):
M data/states/main_menu/main_menu.pydata/states/main_menu/main_menu.py

@@ -9,7 +9,7 @@ self.next = c.TOWN

self.surface = setup.SCREEN self.rect = self.surface.get_rect() text = 'Arrows for navigation, space for input, Enter/Return for menu' - self.font = pg.font.Font(setup.FONTS['Fixedsys500c'], 15) + self.font = pg.font.Font(setup.FONTS[c.MAIN_FONT], 22) self.rendered_text = self.font.render(text, 1, c.BLACK) self.text_rect = self.rendered_text.get_rect() self.text_rect.center = self.rect.center
M data/states/player_menu.pydata/states/player_menu.py

@@ -17,12 +17,13 @@

def startup(self, current_time, game_data): """Call when state is switched to""" inventory = game_data['player inventory'] + stats = game_data['player stats'] self.next = game_data['last state'] self.allow_input = False self.game_data = game_data self.current_time = current_time self.background = self.make_background() - self.gui = menugui.MenuGui(self, inventory) + self.gui = menugui.MenuGui(self, inventory, stats) def make_background(self):
M data/states/town/town.pydata/states/town/town.py

@@ -18,11 +18,12 @@ def set_sprite_dialogue(self):

"""Sets unique dialogue for each sprite""" for sprite in self.sprites: if sprite.location == [9, 46]: - sprite.dialogue = ['Welcome to our town, Mr. Traveller!', - 'The King is loved by all!', - 'You should go visit him in his castle.'] + sprite.dialogue = ['Welcome to our town, traveller!', + 'Our King protects us against the evil forces of the outside world.', + 'As long as we never leave, we have nothing to fear!'] elif sprite.location == [15, 41]: - sprite.dialogue = ['You seem tired, why not rest at our Inn?'] + sprite.dialogue = ['You seem tired from your travels.', + 'Why not rest at our Inn and stay awhile?'] sprite.begin_auto_resting() elif sprite.location == [13, 13]: sprite.dialogue = ['Be careful. There are monsters surrounding our town.',

@@ -34,7 +35,8 @@ 'Perhaps you should pay him a visit.']

elif sprite.location == [10, 7]: sprite.dialogue = ['Welcome to the castle, citizen.'] elif sprite.location == [13, 7]: - sprite.dialogue = ['Move along.'] + sprite.dialogue = ['Only those given special permission by the King can leave this town.', + 'It is for our own good, as few could survive in the outside world.'] elif sprite.location == [18, 27]: sprite.dialogue = ["Don't be frightened. I'm a friendly Demon.", "My brothers and sisters, however, are not so nice.",
M data/tools.pydata/tools.py

@@ -154,6 +154,19 @@ """Create a dictionary of persistant values the player

carries between states""" player_items = {'gold': 100} + player_health = {'current': 100, + 'maximum': 100} + + player_magic = {'current': 100, + 'maximum': 100} + + player_stats = {'Health': player_health, + 'Level': 1, + 'Experience to next level': 100, + 'Magic Points': player_magic, + 'Attack Points': 10, + 'Defense Points': 10} + data_dict = {'last location': None, 'last state': None,

@@ -162,7 +175,8 @@ 'town start pos': [12, 49],

'castle start pos': [12, 26], 'house start pos': [12, 13], 'king item': {'gold': 500}, - 'player inventory': player_items + 'player inventory': player_items, + 'player stats': player_stats } return data_dict