all repos — Legends-RPG @ 41e31ec9b4428abcfcac1c9661c5addb5fdf9802

A fantasy mini-RPG built with Python and Pygame.

The menu is now an object attached to each level state, rather than being it's own separate state.  This way I don't have to keep track of each sprite's position on the map to prevent conflicts during their respawning.
Justin Armstrong justinmeister@gmail.com
Tue, 01 Apr 2014 21:13:46 -0700
commit

41e31ec9b4428abcfcac1c9661c5addb5fdf9802

parent

3680331e18c35231e06b60e40f5431de762dbf63

M data/components/person.pydata/components/person.py

@@ -357,13 +357,6 @@ super(FemaleVillager2, self).__init__('femvillager2', x, y, direction)

self.index = 1 -class MaleVillager(Person): - """Male Person for town""" - - def __init__(self): - super(MaleVillager, self).__init__('male villager', x, y) - - class King(Person): """King of the town""" def __init__(self, x, y, direction='down', state='resting'):
M data/components/textbox.pydata/components/textbox.py

@@ -116,6 +116,7 @@ self.player = level.player

self.sprites = level.sprites self.talking_sprite = None self.textbox = None + self.allow_input = False self.level = level self.last_textbox_timer = 0.0 self.game_data = level.game_data

@@ -123,10 +124,11 @@

def update(self, keys, current_time): """Checks for the creation of Dialogue boxes""" - if keys[pg.K_SPACE] and not self.textbox: + if keys[pg.K_SPACE] and not self.textbox and self.allow_input: for sprite in self.sprites: if (current_time - self.last_textbox_timer) > 300: if self.player.state == 'resting': + self.allow_input = False self.check_for_dialogue(sprite) if self.textbox:

@@ -149,6 +151,9 @@ self.level.state = 'normal'

self.textbox = None self.last_textbox_timer = current_time self.reset_sprite_direction() + + if not keys[pg.K_SPACE]: + self.allow_input = True def check_for_dialogue(self, sprite):
M data/main.pydata/main.py

@@ -31,8 +31,7 @@ INN: shop.Inn(),

ARMOR_SHOP: shop.ArmorShop(), WEAPON_SHOP: shop.WeaponShop(), MAGIC_SHOP: shop.MagicShop(), - POTION_SHOP: shop.PotionShop(), - PLAYER_MENU: player_menu.Player_Menu() + POTION_SHOP: shop.PotionShop() } run_it.setup_states(state_dict, c.MAIN_MENU)
M data/menugui.pydata/menugui.py

@@ -281,15 +281,22 @@ elif self.arrow_index == 2:

self.state = 'magic' elif self.arrow_index == 3: - self.level.done = True + self.level.state = 'normal' + self.arrow_index = 0 + self.state = 'stats' + self.allow_input = False elif keys[pg.K_RETURN]: - self.level.done = True + self.level.state = 'normal' + self.state = 'stats' + self.allow_input = False + self.arrow_index = 0 if (not keys[pg.K_DOWN] and not keys[pg.K_UP] - and not keys[pg.K_RETURN]): + and not keys[pg.K_RETURN] + and not keys[pg.K_SPACE]): self.allow_input = True
M data/states/level_state.pydata/states/level_state.py

@@ -11,6 +11,7 @@ import pygame as pg

from .. import tools, collision from .. import tilemap as tm from .. components import person, textbox +from . import player_menu class LevelState(tools._State):

@@ -51,6 +52,7 @@ self.sprites)

self.dialogue_handler = textbox.TextHandler(self) self.state_dict = self.make_state_dict() self.portals = tm.make_level_portals(self.name) + self.menu_screen = player_menu.Player_Menu(game_data, self) def set_sprite_dialogue(self):

@@ -61,7 +63,8 @@

def make_state_dict(self): """Make a dictionary of states the level can be in""" state_dict = {'normal': self.running_normally, - 'dialogue': self.handling_dialogue} + 'dialogue': self.handling_dialogue, + 'menu': self.goto_menu} return state_dict

@@ -95,10 +98,8 @@ def check_for_menu(self, keys):

"""Check if player hits enter to go to menu""" if keys[pg.K_RETURN] and self.allow_input: if self.player.state == 'resting': - self.player.location = self.player.get_tile_location() - self.next = 'player menu' - self.update_game_data() - self.done = True + self.state = 'menu' + self.allow_input = False if not keys[pg.K_RETURN]:

@@ -138,6 +139,12 @@ def handling_dialogue(self, surface, keys, current_time):

"""Update only dialogue boxes""" self.dialogue_handler.update(keys, current_time) self.draw_level(surface) + + + def goto_menu(self, surface, keys, *args): + """Go to menu screen""" + self.menu_screen.update(surface, keys) + self.menu_screen.draw(surface) def check_for_dialogue(self):
M data/states/player_menu.pydata/states/player_menu.py

@@ -7,23 +7,14 @@ from .. import tools, setup, menugui

from .. import constants as c -class Player_Menu(tools._State): - def __init__(self): - super(Player_Menu, self).__init__() - self.get_image = tools.get_image - - - - def startup(self, current_time, game_data): - """Call when state is switched to""" +class Player_Menu(object): + def __init__(self, game_data, level): inventory = game_data['player inventory'] stats = game_data['player stats'] - self.next = game_data['last state'] + self.get_image = tools.get_image 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, stats) + self.gui = menugui.MenuGui(level, inventory, stats) def make_background(self):

@@ -59,7 +50,7 @@

return sprite - def update(self, surface, keys, current_time): + def update(self, surface, keys): self.gui.update(keys) self.draw(surface)