Back to where I was, sort of, before the great tmx experiment.
Justin Armstrong justinmeister@gmail.com
Mon, 14 Apr 2014 20:46:59 -0700
17 files changed,
284 insertions(+),
622 deletions(-)
M
data/main.py
→
data/main.py
@@ -25,6 +25,7 @@ """Add states to control here"""
run_it = tools.Control(setup.ORIGINAL_CAPTION) state_dict = {MAIN_MENU: main_menu.Menu(), TOWN: levels.LevelState(TOWN), + CASTLE: levels.LevelState(CASTLE), HOUSE: levels.LevelState(HOUSE), OVERWORLD: levels.LevelState(OVERWORLD), BROTHER_HOUSE: levels.LevelState(BROTHER_HOUSE),
D
data/states/castle/blockers.txt
@@ -1,28 +0,0 @@
-0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -000BBBBBBBBBBBBBBBBBBB000 -000BHHHHHHPFFFAHHHHHHB000 -000BHHHHHHPFFFAHHHHHHB000 -000BHHHHHHPFFFAHHHHHHB000 -000BHBHHHHPFFFAHHHHBHB000 -000BHHHHHHPFFFAHHHHHHB000 -000BHHHHHHPFFFAHHHHHHB000 -000BHHHHHHPFFFAHHHHHHB000 -000BHHHHHHPFFFAHHHHHHB000 -000BHBHHHHPFFFAHHHHBHB000 -000BHHHHHHPFFFAHHHHHHB000 -000BHHHHHHPFFFAHHHHHHB000 -000BHHHHHHPFFFAHHHHHHB000 -000BHHHHHHPFFFAHHHHHHB000 -000BHBHHHHPFFFAHHHHBHB000 -000BHHHHHHPFFFAHHHHHHB000 -000BHHHHHHPFFFAHHHHHHB000 -000BHHHHHHPFFFAHHHHHHB000 -000BHHHHHHPFFFAHHHHHHB000 -000BHBHHHHPFFFAHHHHBHB000 -000BHHHHHHPFFFAHHHHHHB000 -000BHHHHHHPFFFAHHHHHHB000 -000BBBBBBBRDDDUBBBBBBB000 -
D
data/states/castle/castle.py
@@ -1,28 +0,0 @@
-"""This is the castle state. Most of its functionality is inherited -from the level_state.py module. Most of the level data is contained -in the tilemap .txt files in this state's directory. Essentially the -only purpose of castle.py is to assign dialogue to each sprite. -""" - -from .. import levels -from ... import constants as c - -class Castle(levels.LevelState): - def __init__(self): - super(Castle, self).__init__(self.name) - self.name = c.CASTLE - self.map_width = 25 - self.map_height = 27 - - def set_sprite_dialogue(self): - """Sets unique dialogue for each sprite""" - for sprite in self.sprites: - if sprite.location == [12, 6]: - sprite.dialogue = ["Please! You must help me!", - "An evil sorceror has stolen my magic crown!", - "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.game_data['king item'] - else: - sprite.dialogue = ['Hail to the King!']
D
data/states/castle/layer1.txt
@@ -1,28 +0,0 @@
-0000000000000000000000000 -0000000000000000000000000 -000C00C00C00C00C00C00X000 -000V00000000000000000X000 -000VSSSSSSSSSSSSSSSSSX000 -000VHHHHHHHHHHHHHHHHHX000 -000VHHHHHHHHHHHHHHHHHX000 -000VHHHHHHHHHHHHHHHHHX000 -000VHHHHHHQJJJEHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000VHHHHHHPFFFAHHHHHHX000 -000C00C0C0RDDDUC00C00X000 -
D
data/states/castle/layer1extra.txt
@@ -1,28 +0,0 @@
-0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000A00B00C00A00B00C00000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -
D
data/states/castle/layer2.txt
@@ -1,28 +0,0 @@
-0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -00000K0000000000000K00000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -00000K0000000000000K00000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -00000K0000000000000K00000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -00000K0000000000000K00000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -
D
data/states/castle/portals.txt
@@ -1,28 +0,0 @@
-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
D
data/states/castle/sprite_start_pos.txt
@@ -1,28 +0,0 @@
-0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -000000000000C000000000000 -0000000000000000000000000 -0000000000000000000000000 -00000000A0000000B00000000 -0000000000000000000000000 -00000000A0000000B00000000 -0000000000000000000000000 -00000000A0000000B00000000 -0000000000000000000000000 -00000000A0000000B00000000 -0000000000000000000000000 -00000000A0000000B00000000 -0000000000000000000000000 -00000000A0000000B00000000 -0000000000000000000000000 -00000000A0000000B00000000 -0000000000000000000000000 -00000000A0000000B00000000 -0000000000000000000000000 -0000000000000000000000000 -000000000000P000000000000 -
M
data/states/levels.py
→
data/states/levels.py
@@ -29,6 +29,7 @@ self.game_data = game_data
self.current_time = current_time self.state = 'normal' self.allow_input = False + self.cut_off_bottom_map = ['castle', 'town'] self.renderer = tilerender.Renderer(self.tmx_map) self.map_image = self.renderer.make_2x_map()@@ -63,7 +64,7 @@ Create the surface all images are blitted to.
""" map_rect = map_image.get_rect() map_width = map_rect.width - if self.name == 'town': + if self.name in self.cut_off_bottom_map: map_height = map_rect.height - 32 else: map_height = map_rect.height@@ -114,23 +115,35 @@
for object in self.renderer.tmx_data.getObjects(): properties = object.__dict__ if properties['name'] == 'sprite': + if 'direction' in properties: + direction = properties['direction'] + else: + direction = 'down' + + if properties['type'] == 'soldier' and direction == 'left': + index = 1 + else: + index = 0 + x = properties['x'] * 2 y = ((properties['y']) * 2) - 32 sprite_dict = {'oldman': person.Person('oldman', - x, y, 'down'), + x, y, direction), 'bluedressgirl': person.Person('femalevillager', - x, y, 'right', + x, y, direction, 'resting', 1), 'femalewarrior': person.Person('femvillager2', - x, y, 'down', + x, y, direction, 'autoresting'), 'devil': person.Person('devil', x, y, 'down', 'autoresting'), 'oldmanbrother': person.Person('oldmanbrother', - x, y, 'down'), + x, y, direction), 'soldier': person.Person('soldier', - x, y, 'down')} + x, y, direction, + 'resting', index), + 'king': person.Person('king', x, y, direction)} sprite = sprite_dict[properties['type']] self.assign_dialogue(sprite, properties)
D
data/tilemap.py
@@ -1,412 +0,0 @@
-__author__ = 'justinarmstrong' - -import os -import pygame as pg -from . import tools, setup -from . components import person, portal -from . import constants as c - - -def create_town_sprite_sheet_dict(): - """Create a dictionary of sprite sheet tiles""" - tile_dict = {} - tileset1 = setup.GFX['tileset1'] - tileset2 = setup.GFX['tileset2'] - tileset3 = setup.GFX['tileset3'] - shopsigns = setup.GFX['shopsigns'] - castle_door = setup.GFX['castledoor'] - medieval_signs = setup.GFX['medievalsigns'] - house = setup.GFX['house'] - houseoverworld = setup.GFX['houseoverworld'] - oldmanhouse = setup.GFX['house1'] - evilcastle = setup.GFX['evilcastle'] - - tile_dict['pavement'] = get_tile(32, 48, tileset2) - tile_dict['house wall'] = get_tile(64, 48, tileset2) - tile_dict['house roof'] = get_tile(0, 144, tileset2) - tile_dict['house door'] = get_tile(48, 64, tileset2) - tile_dict['tree'] = get_tile(80, 48, tileset1, 16, 32) - 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(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) - tile_dict['horiz castle wall'] = get_tile(32, 0, tileset3, 48, 32) - tile_dict['left vert castle wall'] = get_tile(0, 16, tileset3) - tile_dict['right vert castle wall'] = get_tile(162, 16, tileset3) - tile_dict['castle tower'] = get_tile(116, 16, tileset1, 48, 64) - tile_dict['main castle roof'] = get_tile(0, 0, tileset1, 160, 16) - tile_dict['left castle roof piece'] = get_tile(0, 0, tileset1, 48, 16) - tile_dict['right castle roof piece'] = get_tile(112, 0, tileset1, 48, 16) - tile_dict['castle side'] = get_tile(0, 72, tileset3) - tile_dict['castle door'] = get_tile(0, 0, castle_door, 64, 96) - tile_dict['carpet topleft'] = get_tile(112, 112, tileset2) - 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, 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) - tile_dict['black tile'] = make_black_surface_tile() - tile_dict['bed'] = get_tile(456, 206, house, 48, 82) - tile_dict['shelves'] = get_tile(352, 116, house, 160, 70) - tile_dict['chair'] = get_tile(323, 256, house, 32, 32) - tile_dict['table'] = get_tile(82, 161, tileset3, 46, 32) - tile_dict['fancy carpet'] = get_tile(112, 96, tileset3, 64, 64) - tile_dict['column'] = get_tile(64, 96, tileset3, 16, 48) - tile_dict['bottomwater1'] = get_tile(16, 32, tileset2) - tile_dict['bottomwater2'] = get_tile(32, 32, tileset2) - tile_dict['bottomwater3'] = get_tile(48, 32, tileset2) - tile_dict['topwater1'] = get_tile(16, 0, tileset2) - tile_dict['topwater2'] = get_tile(32, 0, tileset2) - tile_dict['topwater3'] = get_tile(48, 0, tileset2) - tile_dict['leftwater1'] = get_tile(80, 0, tileset2) - tile_dict['leftwater2'] = get_tile(80, 16, tileset2) - tile_dict['leftwater3'] = get_tile(0, 16, tileset2) - tile_dict['rightwater1'] = get_tile(144, 0, tileset2) - tile_dict['rightwater2'] = get_tile(144, 16, tileset2) - tile_dict['rightwater3'] = get_tile(64, 16, tileset2) - tile_dict['houseoverworld'] = get_tile(0, 0, houseoverworld, 128, 128) - tile_dict['oldmanhouse'] = get_tile(0, 0, oldmanhouse, 32, 32) - tile_dict['evilcastle'] = get_tile(0, 0, evilcastle, 128, 128) - - return tile_dict - -def create_layer1_tile_code_dict(): - """Creates a dictionary of codes to tiles for layer 1""" - tile_dict = {'1': 'pavement', - '2': 'house wall', - '3': 'house roof', - 'T': 'tree', - 'W': 'well', - 'M': 'moat', - 'G': 'grass', - 'B': 'castle bridge', - 'V': 'left vert castle wall', - 'C': 'horiz castle wall', - 'X': 'right vert castle wall', - 'S': 'castle side', - 'Q': 'carpet topleft', - 'E': 'carpet topright', - 'J': 'carpet top', - 'R': 'carpet bottomleft', - 'U': 'carpet bottomright', - 'D': 'carpet bottom', - 'P': 'carpet left', - 'A': 'carpet right', - 'F': 'carpet center', - 'H': 'marble floor', - 'K': 'black tile', - 'L': 'topwater1', - 'N': 'topwater2', - 'Y': 'topwater3', - 'Z': 'leftwater1', - '4': 'leftwater2', - '5': 'leftwater3', - '6': 'rightwater1', - '7': 'rightwater2', - '8': 'rightwater3', - '9': 'bottomwater1', - 'a': 'bottomwater2', - 'b': 'bottomwater3' - } - - return tile_dict - -def create_layer2_tile_code_dict(): - """Creates a dictionary of tile codes for layer 2""" - tile_dict = {'D': 'house door', - 'F': 'fence', - '$': 'flower1', - '*': 'flower2', - 'T': 'castle tower', - 'W': 'left vert castle wall', - 'M': 'main castle roof', - 'L': 'left castle roof piece', - 'R': 'right castle roof piece', - '#': 'tree', - 'O': 'castle door', - 'Q': 'castle window', - 'A': 'banner1', - 'B': 'banner2', - 'C': 'banner3', - 'E': 'bed', - 'G': 'shelves', - 'H': 'chair', - 'I': 'table', - 'J': 'fancy carpet', - 'K': 'column', - 'N': 'black tile', - 'P': 'houseoverworld', - '4': 'oldmanhouse', - '5': 'evilcastle' - } - - return tile_dict - -def create_layer3_tile_code_dict(): - """Creates a dictionary of tile codes for layer 3""" - tile_dict = {'W': 'sword', - 'A': 'shield', - 'P': 'potion', - 'M': 'gem', - 'I': 'inn sign', - 'B': 'chair'} - - return tile_dict - -def make_level_portals_code_dict(): - """Make the dictionary for codes for level portals""" - portal_dict = {'A': c.CASTLE, - 'B': c.TOWN, - 'C': c.INN, - 'D': c.MAGIC_SHOP, - 'E': c.POTION_SHOP, - 'F': c.WEAPON_SHOP, - 'G': c.ARMOR_SHOP, - 'H': c.HOUSE, - 'J': c.OVERWORLD, - 'K': c.BROTHER_HOUSE - } - - return portal_dict - -def get_tile(x, y, tileset, width=16, height=16, scale=1): - """Gets the surface and rect for a tile""" - surface = get_image(x, y, width, height, tileset) - surface = pg.transform.scale(surface, (int(width*scale), int(height*scale))) - rect = surface.get_rect() - - tile_dict = {'surface': surface, - 'rect': rect} - - return tile_dict - - -def make_black_surface_tile(): - """Make a black surface""" - surface = pg.Surface((32, 32)) - surface.fill(c.NEAR_BLACK_BLUE) - rect = surface.get_rect() - new_dict = {'surface': surface, - 'rect': rect} - - return new_dict - - -def make_background(state_name, width, height): - """Creates the background surface that the rest of - the town map will be blitted on""" - size = (width*16, height*16) - surface = pg.Surface(size) - if state_name == c.TOWN or state_name == c.OVERWORLD: - tile = get_image(0, 0, 16, 16, setup.GFX['tileset2']) - else: - tile = pg.Surface((16, 16)) - tile.fill(c.BLACK_BLUE) - - rect = tile.get_rect() - - for row in range(height): - for column in range(width): - rect.y = row * 16 - rect.x = column * 16 - surface.blit(tile, rect) - - return surface - - -def create_map_layer1(state, width, height): - """Creates the town from a tile map and creates a - surface on top of the background""" - map = make_background(state, width, height) - - tile_map = open(os.path.join('data', 'states', state, 'layer1.txt'), 'r') - - for row, line in enumerate(tile_map): - for column, letter in enumerate(line): - if letter not in layer1_tile_code_dict: - pass - else: - tile = tile_dict[layer1_tile_code_dict[letter]] - blit_tile_to_map(tile, row, column, map) - - tile_map.close() - - layer1_extra = create_map_layer2(state, width, height, 'layer1extra.txt') - map.blit(layer1_extra, (0,0)) - - map = scale_map(map) - - return map - - -def create_map_layer2(state, width, height, file_name='layer2.txt'): - """Creates doors and other items on top of the rest of the map""" - map = make_background(None, width, height) - map.set_colorkey(c.BLACK_BLUE) - layer2_tile_dict = create_layer2_tile_code_dict() - - tile_map = open(os.path.join('data', 'states', state, file_name), 'r') - - for row, line in enumerate(tile_map): - for column, letter in enumerate(line): - if letter not in layer2_tile_dict: - pass - else: - tile = tile_dict[layer2_tile_dict[letter]] - blit_tile_to_map(tile, row, column, map) - - tile_map.close() - - if file_name == 'layer2.txt': - map = pg.transform.scale2x(map) - map = create_map_layer3(map, state) - - return map - - -def scale_map(map): - """Double resolution of map to 32x32""" - map = pg.transform.scale2x(map) - - return map - - -def create_map_layer3(map, state): - """Layers for images that are already 32x32""" - tile_map = open(os.path.join('data', 'states', state, 'layer3.txt'), 'r') - layer3_tile_dict = create_layer3_tile_code_dict() - - for row, line in enumerate(tile_map): - for column, letter in enumerate(line): - if letter not in layer3_tile_dict: - pass - else: - tile = tile_dict[layer3_tile_dict[letter]] - blit_tile_to_map(tile, row, column, map, 32) - - tile_map.close() - - return map - - -def blit_tile_to_map(tile, row, column, map, side_length=16): - """Places tile to map""" - tile['rect'].x = column * side_length - tile['rect'].y = row * side_length - - map.blit(tile['surface'], tile['rect']) - - -def create_blockers(state): - """Creates invisible rect objects that will prevent the player from - walking into trees, buildings and other solid objects""" - tile_map = open(os.path.join('data', 'states', state, 'blockers.txt'), 'r') - blockers = [] - - for row, line in enumerate(tile_map): - for column, letter in enumerate(line): - if letter == 'B': - blockers.append(pg.Rect(column*32, row*32, 32, 32)) - - tile_map.close() - - return blockers - - -def make_level_surface(map): - """Creates the surface all images are blitted to""" - map_rect = map.get_rect() - size = map_rect.size - - - return pg.Surface(size).convert() - - -def create_viewport(map): - """Create the viewport to view the level through""" - map_rect = map.get_rect() - return setup.SCREEN.get_rect(bottom=map_rect.bottom) - - -def set_sprite_positions(player, level_sprites, state, game_data): - """Set the start positions for all the sprites in the level""" - start_pos_key = state + ' start pos' - x = game_data[start_pos_key][0]*32 - y = game_data[start_pos_key][1]*32 - player.rect = pg.Rect(x, y, 32, 32) - - tile_map = open(os.path.join('data', 'states', state, 'sprite_start_pos.txt'), 'r') - - for row, line in enumerate(tile_map): - for column, letter in enumerate(line): - if letter == 'F': - fem_villager = person.FemaleVillager(column*32, row*32) - level_sprites.add(fem_villager) - elif letter == 'S': - soldier = person.Soldier(column*32, row*32) - level_sprites.add(soldier) - elif letter == 'A': - soldier = person.Soldier(column*32, row*32, 'right', 'resting') - 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) - elif letter == 'D': - well = person.Well(column*32, row*32) - level_sprites.add(well) - elif letter == 'E': - fem_villager = person.FemaleVillager2(column*32, row*32) - level_sprites.add(fem_villager) - elif letter == 'G': - devil_villager = person.Devil(column*32, row*32) - level_sprites.add(devil_villager) - elif letter == 'H': - old_villager = person.OldMan(column*32, row*32) - level_sprites.add(old_villager) - elif letter == 'J': - old_brother = person.OldManBrother(column*32, row*32) - level_sprites.add(old_brother) - - tile_map.close() - - -def make_level_portals(state): - """Create portals to different levels on doors""" - tile_map = open(os.path.join('data', 'states', state, 'portals.txt'), 'r') - portal_code_dict = make_level_portals_code_dict() - portal_group = pg.sprite.Group() - - for row, line in enumerate(tile_map): - for column, letter in enumerate(line): - if letter not in portal_code_dict: - pass - else: - portal_group.add(portal.Portal( - column, row, portal_code_dict[letter])) - - return portal_group - - -get_image = tools.get_image -tile_dict = create_town_sprite_sheet_dict() -layer1_tile_code_dict = create_layer1_tile_code_dict() -
M
data/tools.py
→
data/tools.py
@@ -155,6 +155,17 @@ image.set_colorkey(c.BLACK)
return image +def get_tile(x, y, tileset, width=16, height=16, scale=1): + """Gets the surface and rect for a tile""" + surface = get_image(x, y, width, height, tileset) + surface = pg.transform.scale(surface, (int(width*scale), int(height*scale))) + rect = surface.get_rect() + + tile_dict = {'surface': surface, + 'rect': rect} + + return tile_dict + def create_game_data_dict(): """Create a dictionary of persistant values the player
A
resources/tmx/castle.tmx
@@ -0,0 +1,223 @@
+<?xml version="1.0" encoding="UTF-8"?> +<map version="1.0" orientation="orthogonal" width="25" height="27" tilewidth="16" tileheight="16" backgroundcolor="#130f30"> + <tileset firstgid="1" name="tileset2" tilewidth="16" tileheight="16"> + <image source="../graphics/tileset2.png" width="160" height="180"/> + </tileset> + <tileset firstgid="111" name="tileset3" tilewidth="16" tileheight="16"> + <image source="../graphics/tileset3.png" width="176" height="192"/> + </tileset> + <layer name="Tile Layer 1" width="25" height="27"> + <data encoding="base64" compression="zlib"> + eJxjYBh+IB+Ii4C4GIhLoOwCIC4kkl0KxS147KgC4gYgrgbiGiCuJZHdAMXE2IEL1yJhfOoI2bGdCniw2nEIB6a2P/yA2B8JB9DAjgggjkTCUaN2jNpBZTtqh4k/Ru0YtWMk2jGbAbXtg9wGSgLiZCScApUDtXXKgLgcSi8lYAetAAB7/gvf + </data> + </layer> + <layer name="Tile Layer 2" width="25" height="27"> + <data encoding="base64" compression="zlib"> + eJxjYBgF5IIeJHYvEruPRDX4wHQk9gwk9kwS1YyCUTAKRgEhEDnQDhgFo2AUjEgAAF4VBzg= + </data> + </layer> + <objectgroup name="Object Layer 1" width="25" height="27"> + <object name="start point" gid="73" x="192" y="416"> + <properties> + <property name="state" value="town"/> + </properties> + </object> + <object name="portal" type="town" gid="89" x="224" y="432"/> + <object name="portal" type="town" gid="89" x="208" y="432"/> + <object name="portal" type="town" gid="89" x="192" y="432"/> + <object name="portal" type="town" gid="89" x="176" y="432"/> + <object name="portal" type="town" gid="89" x="160" y="432"/> + <object name="blocker" gid="70" x="240" y="416"/> + <object name="blocker" gid="70" x="272" y="416"/> + <object name="blocker" gid="70" x="256" y="416"/> + <object name="blocker" gid="70" x="288" y="416"/> + <object name="blocker" gid="70" x="304" y="416"/> + <object name="blocker" gid="70" x="320" y="416"/> + <object name="blocker" gid="70" x="336" y="400"/> + <object name="blocker" gid="70" x="336" y="384"/> + <object name="blocker" gid="70" x="336" y="352"/> + <object name="blocker" gid="70" x="336" y="368"/> + <object name="blocker" gid="70" x="336" y="336"/> + <object name="blocker" gid="70" x="336" y="320"/> + <object name="blocker" gid="70" x="336" y="304"/> + <object name="blocker" gid="70" x="336" y="272"/> + <object name="blocker" gid="70" x="336" y="288"/> + <object name="blocker" gid="70" x="336" y="240"/> + <object name="blocker" gid="70" x="336" y="256"/> + <object name="blocker" gid="70" x="336" y="208"/> + <object name="blocker" gid="70" x="336" y="224"/> + <object name="blocker" gid="70" x="336" y="192"/> + <object name="blocker" gid="70" x="336" y="160"/> + <object name="blocker" gid="70" x="336" y="176"/> + <object name="blocker" gid="70" x="336" y="144"/> + <object name="blocker" gid="70" x="336" y="112"/> + <object name="blocker" gid="70" x="336" y="128"/> + <object name="blocker" gid="70" x="336" y="96"/> + <object name="blocker" gid="70" x="320" y="80"/> + <object name="blocker" gid="70" x="304" y="80"/> + <object name="blocker" gid="70" x="288" y="80"/> + <object name="blocker" gid="70" x="272" y="80"/> + <object name="blocker" gid="70" x="256" y="80"/> + <object name="blocker" gid="70" x="240" y="80"/> + <object name="blocker" gid="70" x="224" y="80"/> + <object name="blocker" gid="70" x="208" y="80"/> + <object name="blocker" gid="70" x="192" y="80"/> + <object name="blocker" gid="70" x="176" y="80"/> + <object name="blocker" gid="70" x="160" y="80"/> + <object name="blocker" gid="70" x="144" y="80"/> + <object name="blocker" gid="70" x="128" y="80"/> + <object name="blocker" gid="70" x="112" y="80"/> + <object name="blocker" gid="70" x="96" y="80"/> + <object name="blocker" gid="70" x="80" y="80"/> + <object name="blocker" gid="70" x="64" y="80"/> + <object name="blocker" gid="70" x="48" y="96"/> + <object name="blocker" gid="70" x="48" y="96"/> + <object name="blocker" gid="70" x="48" y="112"/> + <object name="blocker" gid="70" x="48" y="128"/> + <object name="blocker" gid="70" x="48" y="144"/> + <object name="blocker" gid="70" x="48" y="160"/> + <object name="blocker" gid="70" x="48" y="176"/> + <object name="blocker" gid="70" x="48" y="192"/> + <object name="blocker" gid="70" x="48" y="208"/> + <object name="blocker" gid="70" x="48" y="224"/> + <object name="blocker" gid="70" x="48" y="240"/> + <object name="blocker" gid="70" x="48" y="256"/> + <object name="blocker" gid="70" x="48" y="272"/> + <object name="blocker" gid="70" x="48" y="288"/> + <object name="blocker" gid="70" x="48" y="304"/> + <object name="blocker" gid="70" x="48" y="320"/> + <object name="blocker" gid="70" x="48" y="336"/> + <object name="blocker" gid="70" x="48" y="352"/> + <object name="blocker" gid="70" x="48" y="368"/> + <object name="blocker" gid="70" x="48" y="384"/> + <object name="blocker" gid="70" x="48" y="400"/> + <object name="blocker" gid="70" x="64" y="416"/> + <object name="blocker" gid="70" x="80" y="416"/> + <object name="blocker" gid="70" x="96" y="416"/> + <object name="blocker" gid="70" x="112" y="416"/> + <object name="blocker" gid="70" x="128" y="416"/> + <object name="blocker" gid="70" x="144" y="416"/> + <object name="sprite" type="soldier" gid="74" x="256" y="368"> + <properties> + <property name="dialogue length" value="1"/> + <property name="dialogue0" value="Hail to the King!"/> + <property name="direction" value="left"/> + </properties> + </object> + <object name="sprite" type="soldier" gid="74" x="256" y="304"> + <properties> + <property name="dialogue length" value="1"/> + <property name="dialogue0" value="Hail to the King!"/> + <property name="direction" value="left"/> + </properties> + </object> + <object name="sprite" type="soldier" gid="74" x="256" y="336"> + <properties> + <property name="dialogue length" value="1"/> + <property name="dialogue0" value="Hail to the King!"/> + <property name="direction" value="left"/> + </properties> + </object> + <object name="sprite" type="soldier" gid="74" x="256" y="240"> + <properties> + <property name="dialogue length" value="1"/> + <property name="dialogue0" value="Hail to the King!"/> + <property name="direction" value="left"/> + </properties> + </object> + <object name="sprite" type="soldier" gid="74" x="128" y="368"> + <properties> + <property name="dialogue length" value="1"/> + <property name="dialogue0" value="Hail to the King!"/> + <property name="direction" value="right"/> + </properties> + </object> + <object name="sprite" type="soldier" gid="74" x="256" y="208"> + <properties> + <property name="dialogue length" value="1"/> + <property name="dialogue0" value="Hail to the King!"/> + <property name="direction" value="left"/> + </properties> + </object> + <object name="sprite" type="soldier" gid="74" x="256" y="272"> + <properties> + <property name="dialogue length" value="1"/> + <property name="dialogue0" value="Hail to the King!"/> + <property name="direction" value="left"/> + </properties> + </object> + <object name="sprite" type="soldier" gid="74" x="256" y="176"> + <properties> + <property name="dialogue length" value="1"/> + <property name="dialogue0" value="Hail to the King!"/> + <property name="direction" value="left"/> + </properties> + </object> + <object name="sprite" type="soldier" gid="74" x="256" y="144"> + <properties> + <property name="dialogue length" value="1"/> + <property name="dialogue0" value="Hail to the King!"/> + <property name="direction" value="left"/> + </properties> + </object> + <object name="sprite" type="king" gid="74" x="192" y="112"> + <properties> + <property name="dialogue length" value="5"/> + <property name="dialogue0" value="Please! You must help me!"/> + <property name="dialogue1" value="An evil sorceror has stolen my magic crown."/> + <property name="dialogue2" value="WIthout it, our town will be overrun by monsters!"/> + <property name="dialogue3" value="Take this money for supplies."/> + <property name="dialogue4" value="Our town's fate is in your hands."/> + </properties> + </object> + <object name="sprite" type="soldier" gid="74" x="128" y="336"> + <properties> + <property name="dialogue length" value="1"/> + <property name="dialogue0" value="Hail to the King!"/> + <property name="direction" value="right"/> + </properties> + </object> + <object name="sprite" type="soldier" gid="74" x="128" y="304"> + <properties> + <property name="dialogue length" value="1"/> + <property name="dialogue0" value="Hail to the King!"/> + <property name="direction" value="right"/> + </properties> + </object> + <object name="sprite" type="soldier" gid="74" x="128" y="272"> + <properties> + <property name="dialogue length" value="1"/> + <property name="dialogue0" value="Hail to the King!"/> + <property name="direction" value="right"/> + </properties> + </object> + <object name="sprite" type="soldier" gid="74" x="128" y="208"> + <properties> + <property name="dialogue length" value="1"/> + <property name="dialogue0" value="Hail to the King!"/> + <property name="direction" value="right"/> + </properties> + </object> + <object name="sprite" type="soldier" gid="74" x="128" y="240"> + <properties> + <property name="dialogue length" value="1"/> + <property name="dialogue0" value="Hail to the King!"/> + <property name="direction" value="right"/> + </properties> + </object> + <object name="sprite" type="soldier" gid="74" x="128" y="144"> + <properties> + <property name="dialogue length" value="1"/> + <property name="dialogue0" value="Hail to the King!"/> + <property name="direction" value="right"/> + </properties> + </object> + <object name="sprite" type="soldier" gid="74" x="128" y="176"> + <properties> + <property name="dialogue length" value="1"/> + <property name="dialogue0" value="Hail to the King!"/> + <property name="direction" value="right"/> + </properties> + </object> + </objectgroup> +</map>
M
resources/tmx/town.tmx
→
resources/tmx/town.tmx
@@ -25,7 +25,7 @@ </data>
</layer> <layer name="Tile Layer 2" width="25" height="51"> <data encoding="base64" compression="zlib"> - eJztVksOwiAQ5RiuDeseSb2gCz9Rqxs/1YOoW+0VnCaQTCYDHQSqNr7khSHCexlhmGqVFxpYoPkGWAK3wB3wCrwB78IY78X6GnmcgBXwDLwAH8AnsBbGeC/Wpz4YtZAcqH4z7hN7cHmk9vimPGIgzSOlj0VTHyvgmolLtM7WQOmILVz1cQAembhC62wNVI7Yl0cbBoYhCNF/16OBq8Y5DA1D9UNzCYXvrUqFfx5y9DGPJfltEag1J/OZGXEeI7KGztvg2t/leeTyoT0qByTfPrGQfmNhjIGTCP02H6sv8fHpF2iNzydWX6m4O1CgUZN5DuR+pyhy3l079rEGU/pJ7nAsfl1fOfRTncPUjDnzoD2WyyO0j7vwqfPuS12kqHPt0VfMXOpF39a23lqQ9RIf7r+Q9NbQ/sit77oHvgDuCY9D + eJztVkFuAjEMzDM4o3Dd/gj6QQ4tFbBwKbDtQwpX4At4pUSyLDtxSNLSFSON4izOOCbxeq2pCwts0HwNbIEb4Bb4AzwCT0obr8X6FsU4ADvgF/AbeAZegFeljddifRoH46okB6rfj5+FY3B5lI7xSHnkQJtHyTgefX0sgSvGbpGfr4FWsD2k+tgB94zdIT9fA51gh/KIYeSYghT9e2P0kGqcw9gxVT81l1SE3lWl8MxDjyHm8UF+WyRqvZP5mxtxHlPiQ+cxSOt/8zxqxaE9qgY03z650H5jYcyArxn6sTheXxMnpN8gn1CcXH1j8u5Ag0ZL5jVQ+z1FUfPu+nGINVgynuYO5+K/6xtBv9Q5zN1YMw/aY7k8Uvu4hL8676HUBVfnkzu0Q/vneuGLUhfvPdZbG+JvCel+pf9C01txbpiGeU79Jc3auAHzA5GD </data> </layer> <layer name="Tile Layer 3" width="25" height="51">@@ -259,12 +259,13 @@ <properties>
<property name="state" value="weapon shop"/> </properties> </object> - <object name="sprite" type="bluedressgirl" gid="124" x="144" y="768"> + <object name="sprite" type="bluedressgirl" gid="124" x="144" y="752"> <properties> <property name="dialogue length" value="3"/> <property name="dialogue0" value="Welcome to our town, traveller!"/> <property name="dialogue1" value="Our King protects us against the evil forces of the outside world."/> <property name="dialogue2" value="As long as we never leave, we have nothing to fear!"/> + <property name="direction" value="right"/> </properties> </object> <object name="sprite" type="femalewarrior" gid="124" x="240" y="640">@@ -384,5 +385,27 @@ <property name="dialogue1" value="Make sure to equip sufficient armor and weapons."/>
<property name="dialogue2" value="Spells and potions are useful too."/> </properties> </object> + <object name="portal" type="castle" gid="139" x="176" y="112"/> + <object name="portal" type="castle" gid="139" x="192" y="112"/> + <object name="start point" gid="123" x="192" y="128"> + <properties> + <property name="state" value="castle"/> + </properties> + </object> + <object name="start point" gid="123" x="176" y="128"> + <properties> + <property name="state" value="castle"/> + </properties> + </object> + <object name="blocker" gid="120" x="240" y="784"/> + <object name="blocker" gid="120" x="224" y="784"/> + <object name="blocker" gid="120" x="208" y="784"/> + <object name="blocker" gid="120" x="208" y="800"/> + <object name="blocker" gid="120" x="160" y="800"/> + <object name="blocker" gid="120" x="160" y="784"/> + <object name="blocker" gid="120" x="144" y="784"/> + <object name="blocker" gid="120" x="128" y="784"/> + <object name="blocker" gid="120" x="112" y="768"/> + <object name="blocker" gid="120" x="112" y="752"/> </objectgroup> </map>