all repos — Legends-RPG @ d8373003d109394bfb66273042e2a2fb96a2b738

A fantasy mini-RPG built with Python and Pygame.

Minor refactoring
Justin Armstrong justinmeister@gmail.com
Fri, 21 Mar 2014 23:26:05 -0700
commit

d8373003d109394bfb66273042e2a2fb96a2b738

parent

a3ef5e6b4ee7fab5e9532a97a89dcf999279f5df

M data/constants.pydata/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.pydata/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.pydata/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.pydata/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/main_menu/main_menu.pydata/states/main_menu/main_menu.py

@@ -6,8 +6,8 @@ from ... import constants as c

class Menu(tools._State): - def __init__(self, name): - super(Menu, self).__init__(name) + def __init__(self): + super(Menu, self).__init__() self.next = c.TOWN self.surface = setup.SCREEN self.rect = self.surface.get_rect()

@@ -17,6 +17,7 @@ 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 self.game_data = tools.create_game_data_dict() + self.name = c.MAIN_MENU def update(self, surface, keys, current_time):
M data/states/shop.pydata/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.txtdata/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.pydata/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.pydata/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.pydata/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