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
6 files changed,
34 insertions(+),
32 deletions(-)
M
data/components/person.py
→
data/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.py
→
data/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.py
→
data/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/states/level_state.py
→
data/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):