Started shop level state
Justin Armstrong justinmeister@gmail.com
Tue, 18 Mar 2014 19:22:49 -0700
6 files changed,
68 insertions(+),
17 deletions(-)
M
data/components/textbox.py
→
data/components/textbox.py
@@ -17,7 +17,8 @@
class DialogueBox(object): """Text box used for dialogue""" - def __init__(self, dialogue, index=0, image_key='dialoguebox'): + def __init__(self, dialogue, index=0, image_key='dialoguebox', item=None): + self.item = item self.bground = setup.GFX[image_key] self.rect = self.bground.get_rect(centerx=400) self.timer = 0.0@@ -81,8 +82,8 @@
class ItemBox(DialogueBox): """Text box for information like obtaining new items""" - def __init__(self, dialogue, index=0, image_key='infobox'): - super(ItemBox, self).__init__(dialogue, index, image_key) + def __init__(self, dialogue, item=None): + super(ItemBox, self).__init__(None, 0, 'infobox', item) def make_dialogue_box_image(self):@@ -91,9 +92,14 @@ image = pg.Surface(self.rect.size)
image.set_colorkey(c.BLACK) image.blit(self.bground, (0, 0)) - dialogue = 'You received ' + self.dialogue_list[self.index] + '.' + if self.item: + total = str(self.item['total']) + type = self.item['type'] + dialogue = 'You received ' + total + ' ' + type + '.' + self.dialogue_list = [dialogue] + self.item = None - dialogue_image = self.font.render(dialogue, + dialogue_image = self.font.render(self.dialogue_list[self.index], False, c.NEAR_BLACK) dialogue_rect = dialogue_image.get_rect(left=50, top=50)@@ -137,7 +143,7 @@ elif self.textbox.name == 'infobox':
self.textbox = ItemBox(dialogue, index) elif self.talking_sprite.item: item = self.check_for_item() - self.textbox = ItemBox(item, 0) + self.textbox = ItemBox(None, item) else: self.level.state = 'normal' self.textbox = None
M
data/states/castle/castle.py
→
data/states/castle/castle.py
@@ -18,8 +18,8 @@ for sprite in self.level_sprites:
if sprite.location == [12, 6]: sprite.dialogue = ["Please! You must help me!", "An evil sorceror has stolen my magic crown!", - "Without the crown's magic, our town will be overun by monsters!", - "Take this 500 gold for supplies.", + "Without it, our town will be overun by monsters!", + "Take this money for supplies.", "Our town's fate is in your hands!"] sprite.item = self.persist['king item'] else:
M
data/states/level_state.py
→
data/states/level_state.py
@@ -25,12 +25,12 @@ """Called when the State object is created"""
self.persist = persist self.current_time = current_time self.state = 'normal' - self.town_map = tm.create_town_map(self.name, + self.town_map = tm.make_level_map(self.name, self.map_width, self.map_height) self.viewport = tm.create_viewport(self.town_map) self.blockers = tm.create_blockers(self.name) - self.level_surface = tm.create_level_surface(self.town_map) + self.level_surface = tm.make_level_surface(self.town_map) self.level_rect = self.level_surface.get_rect() self.player = person.Player(persist['last direction']) self.level_sprites = pg.sprite.Group()@@ -112,10 +112,6 @@ elif direction == 'right':
location[0] -= 1 self.persist[state + ' start pos'] = location - - - - def handling_dialogue(self, surface, keys, current_time):
A
data/states/shop.py
@@ -0,0 +1,47 @@
+""" +This class is the parent class of all shop states. +This includes weapon, armour, magic and potion shops. +It also includes the inn. These states are scaled +twice as big as a level state. +""" + +import pygame as pg +from .. import tools +from .. import tilemap as tm +from .. components import person, textbox + + +class Shop(tools._State): + """Basic shop state""" + def __init__(self, name): + super(Shop, self).__init__(name) + self.map_width = 13 + self.map_height = 10 + + def startup(self, current_time, persist): + """Startup state""" + self.persist = persist + self.current_time = current_time + self.state = 'normal' + self.level_map = tm.make_level_map(self.name, + self.map_width, + self.map_height) + self.level_surface = tm.make_level_surface(self.level_map) + self.level_rect = self.level_surface.get_rect() + self.player = person.Player('right') + self.shop_owner = self.make_shop_owner() + + + self.dialogue_handler = textbox.DialogueHandler(self.player, + self.shop_owner, + self) + + + def make_shop_owner(self): + """Make the shop owner sprite""" + return None + + + def update(self, surface, keys, current_time): + """Update level state""" + pass
M
data/tilemap.py
→
data/tilemap.py
@@ -73,7 +73,7 @@
return tile_dict -def create_town_map(state, width, height): +def make_level_map(state, width, height): """Blits the different layers of the map onto one surface""" map = create_background(state, width, height) map = create_map_layer1(map, state)@@ -328,7 +328,7 @@
return blockers -def create_level_surface(map): +def make_level_surface(map): """Creates the surface all images are blitted to""" width = map['rect'].width height = map['rect'].height
M
data/tools.py
→
data/tools.py
@@ -158,7 +158,9 @@ 'last state': None,
'last direction': 'up', 'town start pos': [12, 49], 'castle start pos': [12, 26], - 'king item': ['500 gold']} + 'king item': {'total': 500, + 'type': 'gold'} + } return data_dict