Mostly finished castle, added King.
jump to
@@ -33,7 +33,8 @@ self.current_time = 0.0
self.state = state self.blockers = self.set_blockers() self.location = self.get_tile_location() - self.dialogue = ['Placeholder Dialogue'] + self.dialogue = ['Location: ' + str(self.location)] + self.default_direction = direction def create_spritesheet_dict(self, sheet_key):@@ -229,7 +230,7 @@
def begin_auto_resting(self): """Transition sprite to an automatic resting state""" self.state = 'autoresting' - self.index = 0 + self.index = 1 self.x_vel = self.y_vel = 0 self.move_timer = self.current_time@@ -331,3 +332,9 @@
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'): + super(King, self).__init__('king', x, y, direction, state) +
@@ -107,6 +107,7 @@ else:
self.level.state = 'normal' self.textbox = None self.last_textbox_timer = current_time + self.reset_sprite_direction() def check_for_dialogue(self, sprite):@@ -130,6 +131,13 @@ elif player.direction == 'right':
if sprite.location == [tile_x + 1, tile_y]: self.textbox = DialogueBox(400, sprite.dialogue) sprite.direction = 'left' + + + def reset_sprite_direction(self): + """Reset sprite to default direction""" + for sprite in self.sprites: + if sprite.state == 'resting': + sprite.direction = sprite.default_direction def draw(self, surface):
@@ -10,9 +10,9 @@
def main(): """Add states to control here""" run_it = tools.Control(setup.ORIGINAL_CAPTION) - state_dict = {c.TOWN: town.Town(c.TOWN), + 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)} + c.CASTLE: castle.Castle(c.CASTLE, 25, 27)} run_it.setup_states(state_dict, c.MAIN_MENU) run_it.main()
@@ -0,0 +1,28 @@
+0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +000BBBBBBBBBBBBBBBBBBB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BHHHHHHPFFFAHHHHHHB000 +000BBBBBBBRDDDUBBBBBBB000 +
@@ -8,10 +8,18 @@ from .. import level_state
from ... import constants as c class Castle(level_state.LevelState): - def __init__(self, name): - super(Castle, self).__init__(name) + def __init__(self, name, width, height): + super(Castle, self).__init__(name, width, height) self.parent_level = c.TOWN def set_sprite_dialogue(self): """Sets unique dialogue for each sprite""" - return None+ 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.", + "Our town's fate is in your hands!"] + else: + sprite.dialogue = ['Hail to the King!']
@@ -1,28 +1,12 @@
0000000000000000000000000 0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 +000C00C00C00C00C00C00X000 +000V00000000000000000X000 +000VSSSSSSSSSSSSSSSSSX000 +000VHHHHHHHHHHHHHHHHHX000 +000VHHHHHHHHHHHHHHHHHX000 +000VHHHHHHHHHHHHHHHHHX000 +000VHHHHHHQJJJEHHHHHHX000 000VHHHHHHPFFFAHHHHHHX000 000VHHHHHHPFFFAHHHHHHX000 000VHHHHHHPFFFAHHHHHHX000@@ -40,12 +24,5 @@ 000VHHHHHHPFFFAHHHHHHX000
000VHHHHHHPFFFAHHHHHHX000 000VHHHHHHPFFFAHHHHHHX000 000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHRDDDUHHHHHHX000 +000C00C0C0RDDDUC00C00X000
@@ -1,40 +1,7 @@
0000000000000000000000000 0000000000000000000000000 0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 +0000A00B00C00A00B00C00000 0000000000000000000000000 0000000000000000000000000 0000000000000000000000000@@ -58,3 +25,4 @@ 0000000000000000000000000
0000000000000000000000000 0000000000000000000000000 0000000000000000000000000 +
@@ -25,27 +25,4 @@ 0000000000000000000000000
0000000000000000000000000 0000000000000000000000000 0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 BBBBBBBBBBBBBBBBBBBBBBBBB
@@ -4,37 +4,14 @@ 0000000000000000000000000
0000000000000000000000000 0000000000000000000000000 0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 +000000000000C000000000000 0000000000000000000000000 0000000000000000000000000 +0000000A000000000B0000000 0000000000000000000000000 +0000000A000000000B0000000 0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 +0000000A000000000B0000000 0000000000000000000000000 0000000A000000000B0000000 0000000000000000000000000
@@ -14,8 +14,10 @@ from .. components import person, textbox
class LevelState(tools._State): - def __init__(self, name): + def __init__(self, name, width, height): super(LevelState, self).__init__(name) + self.map_width = width + self.map_height = height def startup(self, current_time, persist):@@ -23,7 +25,9 @@ """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.create_town_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)
@@ -1,4 +1,4 @@
-#TC00C00C00000C00C0CT000# +#T000000000000000000T000# 000000000L00R0000000000#0 #0W0000M0000000000000W#0# 0#W000000000000000000W0#0@@ -7,9 +7,9 @@ 0#V000000000000000000V0#0
#0V000000000000000000V#0# 00V000000000000000000V0#0 #TV00000000000000000TV00# -00C00C00C0000C00C00C000#0 +00000000000000000000000#0 #00000000000000000000000# -00000000000BB000000000000 +0000000000000000000000000 @@@@@@@@@@@00@@@@@@@@@@@@ 0000000000000000000000000 0000000000011000000000000
@@ -7,8 +7,8 @@
from .. import level_state class Town(level_state.LevelState): - def __init__(self, name): - super(Town, self).__init__(name) + def __init__(self, name, width, height): + super(Town, self).__init__(name, width, height) def set_sprite_dialogue(self): """Sets unique dialogue for each sprite"""
@@ -13,10 +13,7 @@ tile_dict = {}
tileset1 = setup.GFX['tileset1'] tileset2 = setup.GFX['tileset2'] tileset3 = setup.GFX['tileset3'] - sword = setup.GFX['sword'] - shield = setup.GFX['shield'] - potion = setup.GFX['potion'] - gem = setup.GFX['gem'] + shopsigns = setup.GFX['shopsigns'] castle_door = setup.GFX['castledoor'] medieval_signs = setup.GFX['medievalsigns']@@ -29,10 +26,10 @@ tile_dict['well'] = get_tile(96, 50, tileset1, 16, 32)
tile_dict['moat'] = get_tile(16, 16, tileset2) tile_dict['fence'] = get_tile(48, 64, tileset1) tile_dict['grass'] = get_tile(0, 16, tileset1) - tile_dict['sword'] = get_tile(0, 0, sword, 32, 32) - tile_dict['shield'] = get_tile(0, 0, shield, 32, 32) - tile_dict['potion'] = get_tile(0, 0, potion, 32, 32) - tile_dict['gem'] = get_tile(0, 0, gem, 32, 32) + tile_dict['sword'] = get_tile(96, 0, shopsigns, 32, 32) + tile_dict['shield'] = get_tile(64, 0, shopsigns, 32, 32) + tile_dict['potion'] = get_tile(32, 0, shopsigns, 32, 32) + tile_dict['gem'] = get_tile(0, 0, shopsigns, 32, 32) tile_dict['castle bridge'] = get_tile(48, 27, tileset1, 16, 32 ) tile_dict['flower1'] = get_tile(64, 64, tileset2) tile_dict['flower2'] = get_tile(80, 64, tileset2)@@ -50,13 +47,16 @@ tile_dict['carpet topright'] = get_tile(144, 112, tileset2)
tile_dict['carpet bottomleft'] = get_tile(112, 144, tileset2) tile_dict['carpet bottomright'] = get_tile(144, 144, tileset2) tile_dict['carpet bottom'] = get_tile(128, 144, tileset2) - tile_dict['carpet top'] = get_tile(128, 144, tileset2) + tile_dict['carpet top'] = get_tile(128, 112, tileset2) tile_dict['carpet left'] = get_tile(112, 128, tileset2) tile_dict['carpet right'] = get_tile(144, 128, tileset2) tile_dict['carpet center'] = get_tile(128, 128, tileset2) tile_dict['castle window'] = get_tile(128, 59, tileset1) tile_dict['marble floor'] = get_tile(80, 96, tileset3) tile_dict['inn sign'] = get_tile(0, 96, medieval_signs, 32, 32) + tile_dict['banner1'] = get_tile(112, 38, tileset3, 16, 22) + tile_dict['banner2'] = get_tile(128, 38, tileset3, 16, 22) + tile_dict['banner3'] = get_tile(144, 38, tileset3, 16, 22) return tile_dict@@ -73,9 +73,9 @@
return tile_dict -def create_town_map(state): +def create_town_map(state, width, height): """Blits the different layers of the map onto one surface""" - map = create_background(state) + map = create_background(state, width, height) map = create_map_layer1(map, state) map = create_map_layer2(map, state) map = scale_map(map)@@ -84,10 +84,10 @@
return map -def create_background(state_name): +def create_background(state_name, width, height): """Creates the background surface that the rest of the town map will be blitted on""" - size = (25*16, 50*16) + size = (width*16, height*16) surface = pg.Surface(size) if state_name == c.CASTLE: tile = pg.Surface((16, 16))@@ -118,87 +118,91 @@
for row, line in enumerate(tile_map): for column, letter in enumerate(line): if letter == '1': - tile = town_map_dict['pavement'] + tile = tile_dict['pavement'] blit_tile_to_map(tile, row, column, map) elif letter == '2': - tile = town_map_dict['house wall'] + tile = tile_dict['house wall'] blit_tile_to_map(tile, row, column, map) elif letter == '3': - tile = town_map_dict['house roof'] + tile = tile_dict['house roof'] blit_tile_to_map(tile, row, column, map) elif letter == 'T': - tile = town_map_dict['tree'] + tile = tile_dict['tree'] blit_tile_to_map(tile, row, column, map) elif letter == 'W': - tile = town_map_dict['well'] + tile = tile_dict['well'] blit_tile_to_map(tile, row, column, map) elif letter == 'M': - tile = town_map_dict['moat'] + tile = tile_dict['moat'] blit_tile_to_map(tile, row, column, map) elif letter == 'G': - tile = town_map_dict['grass'] + tile = tile_dict['grass'] blit_tile_to_map(tile, row, column, map) elif letter == 'B': - tile = town_map_dict['castle bridge'] + tile = tile_dict['castle bridge'] blit_tile_to_map(tile, row, column, map) elif letter == 'C': - tile = town_map_dict['horiz castle wall'] + tile = tile_dict['horiz castle wall'] blit_tile_to_map(tile, row, column, map) elif letter == 'V': - tile = town_map_dict['left vert castle wall'] + tile = tile_dict['left vert castle wall'] blit_tile_to_map(tile, row, column, map) elif letter == 'X': - tile = town_map_dict['right vert castle wall'] + tile = tile_dict['right vert castle wall'] blit_tile_to_map(tile, row, column, map) elif letter == 'S': - tile = town_map_dict['castle side'] + tile = tile_dict['castle side'] blit_tile_to_map(tile, row, column, map) elif letter == 'Q': - tile = town_map_dict['carpet topleft'] + tile = tile_dict['carpet topleft'] blit_tile_to_map(tile, row, column, map) elif letter == 'E': - tile = town_map_dict['carpet topright'] + tile = tile_dict['carpet topright'] + blit_tile_to_map(tile, row, column, map) + + elif letter == 'J': + tile = tile_dict['carpet top'] blit_tile_to_map(tile, row, column, map) elif letter == 'R': - tile = town_map_dict['carpet bottomleft'] + tile = tile_dict['carpet bottomleft'] blit_tile_to_map(tile, row, column, map) elif letter == 'U': - tile = town_map_dict['carpet bottomright'] + tile = tile_dict['carpet bottomright'] blit_tile_to_map(tile, row, column, map) elif letter == 'D': - tile = town_map_dict['carpet bottom'] + tile = tile_dict['carpet bottom'] blit_tile_to_map(tile, row, column, map) elif letter == 'P': - tile = town_map_dict['carpet left'] + tile = tile_dict['carpet left'] blit_tile_to_map(tile, row, column, map) elif letter == 'A': - tile = town_map_dict['carpet right'] + tile = tile_dict['carpet right'] blit_tile_to_map(tile, row, column, map) elif letter == 'F': - tile = town_map_dict['carpet center'] + tile = tile_dict['carpet center'] blit_tile_to_map(tile, row, column, map) elif letter == 'H': - tile = town_map_dict['marble floor'] + tile = tile_dict['marble floor'] blit_tile_to_map(tile, row, column, map)@@ -214,40 +218,49 @@
for row, line in enumerate(tile_map): for column, letter in enumerate(line): if letter == 'D': - tile = town_map_dict['house door'] + tile = tile_dict['house door'] blit_tile_to_map(tile, row, column, map) elif letter == 'F': - tile = town_map_dict['fence'] + tile = tile_dict['fence'] blit_tile_to_map(tile, row, column, map) elif letter == '$': - tile = town_map_dict['flower1'] + tile = tile_dict['flower1'] blit_tile_to_map(tile, row, column, map) elif letter == '*': - tile = town_map_dict['flower2'] + tile = tile_dict['flower2'] blit_tile_to_map(tile, row, column, map) elif letter == 'T': - tile = town_map_dict['castle tower'] + tile = tile_dict['castle tower'] blit_tile_to_map(tile, row, column, map) elif letter == 'W': - tile = town_map_dict['left vert castle wall'] + tile = tile_dict['left vert castle wall'] blit_tile_to_map(tile, row, column, map) elif letter == 'M': - tile = town_map_dict['main castle roof'] + tile = tile_dict['main castle roof'] blit_tile_to_map(tile, row, column, map) elif letter == 'L': - tile = town_map_dict['left castle roof piece'] + tile = tile_dict['left castle roof piece'] blit_tile_to_map(tile, row, column, map) elif letter == 'R': - tile = town_map_dict['right castle roof piece'] + tile = tile_dict['right castle roof piece'] blit_tile_to_map(tile, row, column, map) elif letter == '#': - tile = town_map_dict['tree'] + tile = tile_dict['tree'] blit_tile_to_map(tile, row, column, map) elif letter == 'O': - tile = town_map_dict['castle door'] + tile = tile_dict['castle door'] blit_tile_to_map(tile, row, column, map) elif letter == 'Q': - tile = town_map_dict['castle window'] + tile = tile_dict['castle window'] + blit_tile_to_map(tile, row, column, map) + elif letter == 'A': + tile = tile_dict['banner1'] + blit_tile_to_map(tile, row, column, map) + elif letter == 'B': + tile = tile_dict['banner2'] + blit_tile_to_map(tile, row, column, map) + elif letter == 'C': + tile = tile_dict['banner3'] blit_tile_to_map(tile, row, column, map) tile_map.close()@@ -270,19 +283,19 @@
for row, line in enumerate(tile_map): for column, letter in enumerate(line): if letter == 'W': - tile = town_map_dict['sword'] + tile = tile_dict['sword'] blit_tile_to_map(tile, row, column, map, 32) elif letter == 'A': - tile = town_map_dict['shield'] + tile = tile_dict['shield'] blit_tile_to_map(tile, row, column, map, 32) elif letter == 'P': - tile = town_map_dict['potion'] + tile = tile_dict['potion'] blit_tile_to_map(tile, row, column, map, 32) elif letter == 'M': - tile = town_map_dict['gem'] + tile = tile_dict['gem'] blit_tile_to_map(tile, row, column, map, 32) elif letter == 'I': - tile = town_map_dict['inn sign'] + tile = tile_dict['inn sign'] blit_tile_to_map(tile, row, column, map, 32) tile_map.close()@@ -351,6 +364,9 @@ level_sprites.add(soldier)
elif letter == 'B': soldier = person.Soldier(column*32, row*32, 'left', 'resting') level_sprites.add(soldier) + elif letter == 'C': + king = person.King(column*32, row*32, 'down', 'resting') + level_sprites.add(king) tile_map.close()@@ -372,5 +388,5 @@
get_image = tools.get_image -town_map_dict = create_town_sprite_sheet_dict() +tile_dict = create_town_sprite_sheet_dict()
@@ -157,7 +157,7 @@ data_dict = {'last location': None,
'last state': None, 'last direction': 'up', 'town start pos': [12, 49], - 'castle start pos': [12, 49]} + 'castle start pos': [12, 26]} return data_dict