Expanded out the map, added shops
Justin Armstrong justinmeister@gmail.com
Fri, 07 Mar 2014 12:06:10 -0800
11 files changed,
168 insertions(+),
57 deletions(-)
M
data/states/town.py
→
data/states/town.py
@@ -27,19 +27,32 @@
def create_town_sprite_sheet_dict(self): """Create a dictionary of sprite sheet tiles""" - dict = {} + tile_dict = {} tileset1 = setup.GFX['tileset1'] tileset2 = setup.GFX['tileset2'] + sword = setup.GFX['sword'] + shield = setup.GFX['shield'] + potion = setup.GFX['potion'] + gem = setup.GFX['gem'] - - dict['pavement'] = self.get_tile(32, 48, tileset2) - dict['house wall'] = self.get_tile(64, 48, tileset2) - dict['house roof'] = self.get_tile(0, 144, tileset2) - dict['house door'] = self.get_tile(48, 64, tileset2) - dict['tree'] = self.get_tile(80, 48, tileset1, 16, 32) - dict['well'] = self.get_tile(96, 50, tileset1, 16, 32) + tile_dict['pavement'] = self.get_tile(32, 48, tileset2) + tile_dict['house wall'] = self.get_tile(64, 48, tileset2) + tile_dict['house roof'] = self.get_tile(0, 144, tileset2) + tile_dict['house door'] = self.get_tile(48, 64, tileset2) + tile_dict['tree'] = self.get_tile(80, 48, tileset1, 16, 32) + tile_dict['well'] = self.get_tile(96, 50, tileset1, 16, 32) + tile_dict['moat'] = self.get_tile(16, 16, tileset2) + tile_dict['fence'] = self.get_tile(48, 64, tileset1) + tile_dict['grass'] = self.get_tile(0, 16, tileset1) + tile_dict['sword'] = self.get_tile(0, 0, sword, 32, 32) + tile_dict['shield'] = self.get_tile(0, 0, shield, 32, 32) + tile_dict['potion'] = self.get_tile(0, 0, potion, 32, 32) + tile_dict['gem'] = self.get_tile(0, 0, gem, 32, 32) + tile_dict['castle bridge'] = self.get_tile(48, 27, tileset1, 16, 32 ) + tile_dict['flower1'] = self.get_tile(64, 64, tileset2) + tile_dict['flower2'] = self.get_tile(80, 64, tileset2) - return dict + return tile_dict def get_tile(self, x, y, tileset, width=16, height=16):@@ -47,10 +60,10 @@ """Gets the surface and rect for a tile"""
surface = self.get_image(self, x, y, width, height, tileset) rect = surface.get_rect() - dict = {'surface': surface, - 'rect': rect} + tile_dict = {'surface': surface, + 'rect': rect} - return dict + return tile_dict def create_town_map(self):@@ -59,6 +72,7 @@ map = self.create_background()
map = self.create_map_layer1(map) map = self.create_map_layer2(map) map = self.scale_map(map) + map = self.create_map_layer3(map) return map@@ -112,6 +126,19 @@ elif letter == 'W':
tile = self.town_map_dict['well'] self.blit_tile_to_map(tile, row, column, map) + elif letter == 'M': + tile = self.town_map_dict['moat'] + self.blit_tile_to_map(tile, row, column, map) + + elif letter == 'G': + tile = self.town_map_dict['grass'] + self.blit_tile_to_map(tile, row, column, map) + + elif letter == 'B': + tile = self.town_map_dict['castle bridge'] + self.blit_tile_to_map(tile, row, column, map) + + tile_map.close() return map@@ -126,6 +153,15 @@ for column, letter in enumerate(line):
if letter == 'D': tile = self.town_map_dict['house door'] self.blit_tile_to_map(tile, row, column, map) + elif letter == 'F': + tile = self.town_map_dict['fence'] + self.blit_tile_to_map(tile, row, column, map) + elif letter == '$': + tile = self.town_map_dict['flower1'] + self.blit_tile_to_map(tile, row, column, map) + elif letter == '*': + tile = self.town_map_dict['flower2'] + self.blit_tile_to_map(tile, row, column, map) tile_map.close()@@ -140,10 +176,35 @@
return map - def blit_tile_to_map(self, tile, row, column, map): + def create_map_layer3(self, map): + """Layers for images that are already 32x32""" + tile_map = open(os.path.join('data', 'states', 'town_layer3.txt'), 'r') + + for row, line in enumerate(tile_map): + for column, letter in enumerate(line): + if letter == 'W': + tile = self.town_map_dict['sword'] + self.blit_tile_to_map(tile, row, column, map, 32) + elif letter == 'A': + tile = self.town_map_dict['shield'] + self.blit_tile_to_map(tile, row, column, map, 32) + elif letter == 'P': + tile = self.town_map_dict['potion'] + self.blit_tile_to_map(tile, row, column, map, 32) + elif letter == 'M': + tile = self.town_map_dict['gem'] + self.blit_tile_to_map(tile, row, column, map, 32) + + tile_map.close() + + return map + + + + def blit_tile_to_map(self, tile, row, column, map, side_length=16): """Places tile to map""" - tile['rect'].x = column * 16 - tile['rect'].y = row * 16 + tile['rect'].x = column * side_length + tile['rect'].y = row * side_length map['surface'].blit(tile['surface'], tile['rect'])
M
data/states/town_layer2.txt
→
data/states/town_layer2.txt
@@ -17,20 +17,20 @@ 0000000000000000000000000
0000000000000000000000000 0000000000000000000000000 0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 +0333033300000000033303330 +0333033300000000033303330 +0222022200000000022202220 +02D202D20000000002D202D20 +0010001000011000001000100 +0011111111111111111111100 0000000000011000000000000 0000000000011000000000000 +00000000001$*100000000000 +0000000001$*$*10000000 +00000000001$*100000000000 +0000000000011000000000000 +0000000000011000000000000 +MMMMMMMMMMM11MMMMMMMMMMMM 0000000000011000000000000 0000000000011000000000000 0000000000011000000000000
A
data/states/town_layer3.txt
@@ -0,0 +1,50 @@
+0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0333033300000000033303330 +0333033300000000033303330 +02W202A20000000002P202M20 +0222022200000000022202220 +0010001000011000001000100 +0011111111111111111111100 +0000000000011000000000000 +0000000000011000000000000 +00000000001GG100000000000 +0000000001GGGG10000000000 +00000000001GG100000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000333000 +0003330000011000000333000 +0003330000011000000222000 +00022200000110000002D2000 +0002D20000011000000010000 +0000100000011000000010000 +0000111111111111111110000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000
M
data/states/town_map.txt
→
data/states/town_map.txt
@@ -9,42 +9,42 @@ 0000000000000000000000000
0000000000000000000000000 0000000000000000000000000 0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 +00000000000BB000000000000 +MMMMMMMMMMMBBMMMMMMMMMMMM 0000000000000000000000000 0000000000011000000000000 0000000000011000000000000 0000000000011000000000000 0000000000011000000000000 0000000000011000000000000 +T33303330001100003330333T +0333033300011000033303330 +T22202220001100002220222T +0222022200011000022202220 +T01000100001100000100010T +0T111111111111111111111T0 +T00000000001100000000000T +0T000000000110000000000T0 +T0T00000001GG100000000T0T +0T0T000001GGGG1000000T0T0 +T0T00T00001GG1000000T0T0T +0000000000011000000000000 +0000000000011000000000000 +MMMMMMMMMMM11MMMMMMMMMMMM +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 T0T0T00000011000000000000 0T0T000000011000000000000 -T0T0000000011000000333000 -0T03330000011000000333000 -T0T3330000011000000222000 -0T02220000011000000222000 -T0T2220000011000000010000 -0T00100000011000000010000 -T0T0111111111111111110000 -0T00000000011000000000000 -T0T0T00W00011000000000000 -000T000000011000000000000 -0T000T0000011000000T00000 +T0T0000000011000000333T0T +0T033300000110000003330T0 +T0T3330000011000000222T0T +0T022200000110000002220T0 +T0T2220000011000000010T0T +0T0010000001100000001T0T0 +T0T0111111111111111110T0T +0T0000000001100000000T0T0 +T0T0T00W000110000000T0T0T +000T00000001100000000T0T0 +0T000T0000011000000T00T00 0000000000011000000000000