Minor refactoring
Justin Armstrong justinmeister@gmail.com
Fri, 21 Mar 2014 23:26:05 -0700
10 files changed,
95 insertions(+),
27 deletions(-)
M
data/constants.py
→
data/constants.py
@@ -7,7 +7,11 @@
TOWN = 'town' MAIN_MENU = 'main menu' CASTLE = 'castle' -SHOP = 'shop' +INN = 'Inn' +POTION_SHOP = 'potion shop' +ARMOR_SHOP = 'armor shop' +WEAPON_SHOP = 'weapon shop' +MAGIC_SHOP = 'magic shop' ##Colors
M
data/main.py
→
data/main.py
@@ -5,13 +5,29 @@ from data.states import shop
from . import setup, tools from . import constants as c + +TOWN = 'town' +MAIN_MENU = 'main menu' +CASTLE = 'castle' +INN = 'Inn' +ARMOR_SHOP = 'armor shop' +WEAPON_SHOP = 'weapon shop' +MAGIC_SHOP = 'magic shop' +POTION_SHOP = 'potion shop' + + def main(): """Add states to control here""" run_it = tools.Control(setup.ORIGINAL_CAPTION) - state_dict = {c.TOWN: town.Town(c.TOWN, 25, 50), - c.MAIN_MENU: main_menu.Menu(c.MAIN_MENU), - c.CASTLE: castle.Castle(c.CASTLE, 25, 27), - c.SHOP: shop.Shop(c.SHOP)} + state_dict = {TOWN: town.Town(), + MAIN_MENU: main_menu.Menu(), + CASTLE: castle.Castle(), + INN: shop.Inn(), + ARMOR_SHOP: shop.ArmorShop(), + WEAPON_SHOP: shop.WeaponShop(), + MAGIC_SHOP: shop.MagicShop(), + POTION_SHOP: shop.PotionShop() + } run_it.setup_states(state_dict, c.MAIN_MENU) run_it.main()
M
data/states/castle/castle.py
→
data/states/castle/castle.py
@@ -8,9 +8,11 @@ from .. import level_state
from ... import constants as c class Castle(level_state.LevelState): - def __init__(self, name, width, height): - super(Castle, self).__init__(name, width, height) - self.parent_level = c.TOWN + def __init__(self): + super(Castle, self).__init__() + self.name = c.CASTLE + self.map_width = 25 + self.map_height = 27 def set_sprite_dialogue(self): """Sets unique dialogue for each sprite"""
M
data/states/level_state.py
→
data/states/level_state.py
@@ -14,10 +14,9 @@ from .. components import person, textbox
class LevelState(tools._State): - def __init__(self, name, width, height): - super(LevelState, self).__init__(name) - self.map_width = width - self.map_height = height + def __init__(self): + super(LevelState, self).__init__() + def startup(self, current_time, game_data):
M
data/states/shop.py
→
data/states/shop.py
@@ -228,8 +228,8 @@
class Shop(tools._State): """Basic shop state""" - def __init__(self, name): - super(Shop, self).__init__(name) + def __init__(self): + super(Shop, self).__init__() self.map_width = 13 self.map_height = 10@@ -241,7 +241,7 @@ self.state = 'normal'
self.get_image = tools.get_image self.dialogue = self.make_dialogue() self.background = self.make_background() - self.gui = Gui('Inn', self.dialogue, self) + self.gui = Gui('shop states', self.dialogue, self) def make_dialogue(self):@@ -314,4 +314,39 @@
def draw_level(self, surface): """Blit graphics to game surface""" surface.blit(self.background.image, self.background.rect) - self.gui.draw(surface)+ self.gui.draw(surface) + + +class Inn(Shop): + """Where our hero gets rest""" + def __init__(self): + super(Inn, self).__init__() + self.name = 'Inn' + + +class WeaponShop(Shop): + """A place to buy weapons""" + def __init__(self): + super(WeaponShop, self).__init__() + self.name = 'Weapon Shop' + + +class ArmorShop(Shop): + """A place to buy armor""" + def __init__(self): + super(ArmorShop, self).__init__() + self.name = 'Armor Shop' + + +class MagicShop(Shop): + """A place to buy magic""" + def __init__(self): + super(MagicShop, self).__init__() + self.name = 'Magic Shop' + + +class PotionShop(Shop): + """A place to buy potions""" + def __init__(self): + super(PotionShop, self).__init__() + self.name = 'Potion Shop'
M
data/states/town/portals.txt
→
data/states/town/portals.txt
@@ -20,14 +20,14 @@ 0000000000011000000000000
0333033300011000033303330 0333033300011000033303330 0222022200011000022202220 -02A202A20001100002A202A20 +02F202G20001100002E202D20 0010001000011000001000100 0011111111111111111111100 0000000000011000000000000 0000000000011000000000000 -00000000001GG100000000000 -0000000001GGGG10000000000 -00000000001GG100000000000 +0000000000111100000000000 +0000000001111110000000000 +0000000000111100000000000 0000000000011000000000000 0000000000011000000000000 MMMMMMMMMMM11MMMMMMMMMMMM
M
data/states/town/town.py
→
data/states/town/town.py
@@ -5,10 +5,14 @@ only purpose of town.py is to assign dialogue to each sprite
""" from .. import level_state +from ... import constants as c class Town(level_state.LevelState): - def __init__(self, name, width, height): - super(Town, self).__init__(name, width, height) + def __init__(self): + super(Town, self).__init__() + self.name = c.TOWN + self.map_width = 25 + self.map_height = 50 def set_sprite_dialogue(self): """Sets unique dialogue for each sprite"""
M
data/tilemap.py
→
data/tilemap.py
@@ -387,7 +387,15 @@ portal_group.add(portal.Portal(column, row, c.CASTLE))
elif letter == 'B': portal_group.add(portal.Portal(column, row, c.TOWN)) elif letter == 'C': - portal_group.add(portal.Portal(column, row, c.SHOP)) + portal_group.add(portal.Portal(column, row, c.INN)) + elif letter == 'D': + portal_group.add(portal.Portal(column, row, c.MAGIC_SHOP)) + elif letter == 'E': + portal_group.add(portal.Portal(column, row, c.POTION_SHOP)) + elif letter == 'F': + portal_group.add(portal.Portal(column, row, c.WEAPON_SHOP)) + elif letter == 'G': + portal_group.add(portal.Portal(column, row, c.ARMOR_SHOP)) return portal_group
M
data/tools.py
→
data/tools.py
@@ -77,7 +77,7 @@
class _State(object): """Base class for all game states""" - def __init__(self, name): + def __init__(self): self.start_time = 0.0 self.current_time = 0.0 self.done = False@@ -85,7 +85,6 @@ self.quit = False
self.next = None self.previous = None self.game_data = {} - self.name = name def get_event(self, event): pass