Finished house, added columns in castle, divided the levels into background and foreground so the player can walk behind things (specifially the castle columns).
jump to
@@ -376,6 +376,12 @@ def __init__(self, x, y, direction='down', state='autoresting'):
super(Devil, self).__init__('devil', x, y, direction, state) +class OldMan(Person): + """Old man villager""" + def __init__(self, x, y, direction='down', state='resting'): + super(OldMan, self).__init__('oldman', x, y, direction, state) + + class Well(pg.sprite.Sprite): """Talking well""" def __init__(self, x, y):
@@ -126,7 +126,8 @@ """Checks for the creation of Dialogue boxes"""
if keys[pg.K_SPACE] and not self.textbox: for sprite in self.sprites: if (current_time - self.last_textbox_timer) > 300: - self.check_for_dialogue(sprite) + if self.player.state == 'resting': + self.check_for_dialogue(sprite) if self.textbox: self.textbox.update(keys, current_time)
@@ -6,22 +6,22 @@ 000BBBBBBBBBBBBBBBBBBB000
000BHHHHHHPFFFAHHHHHHB000 000BHHHHHHPFFFAHHHHHHB000 000BHHHHHHPFFFAHHHHHHB000 -000BHHHHHHPFFFAHHHHHHB000 -000BHHHHHHPFFFAHHHHHHB000 -000BHHHHHHPFFFAHHHHHHB000 -000BHHHHHHPFFFAHHHHHHB000 +000BHBHHHHPFFFAHHHHBHB000 000BHHHHHHPFFFAHHHHHHB000 000BHHHHHHPFFFAHHHHHHB000 000BHHHHHHPFFFAHHHHHHB000 000BHHHHHHPFFFAHHHHHHB000 +000BHBHHHHPFFFAHHHHBHB000 000BHHHHHHPFFFAHHHHHHB000 000BHHHHHHPFFFAHHHHHHB000 000BHHHHHHPFFFAHHHHHHB000 000BHHHHHHPFFFAHHHHHHB000 +000BHBHHHHPFFFAHHHHBHB000 000BHHHHHHPFFFAHHHHHHB000 000BHHHHHHPFFFAHHHHHHB000 000BHHHHHHPFFFAHHHHHHB000 000BHHHHHHPFFFAHHHHHHB000 +000BHBHHHHPFFFAHHHHBHB000 000BHHHHHHPFFFAHHHHHHB000 000BHHHHHHPFFFAHHHHHHB000 000BBBBBBBRDDDUBBBBBBB000
@@ -0,0 +1,28 @@
+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 +
@@ -1,25 +1,25 @@
-0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000A00B00C00A00B00C00000 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
@@ -7,21 +7,21 @@ 0000000000000000000000000
000000000000C000000000000 0000000000000000000000000 0000000000000000000000000 -0000000A000000000B0000000 +00000000A0000000B00000000 0000000000000000000000000 -0000000A000000000B0000000 +00000000A0000000B00000000 0000000000000000000000000 -0000000A000000000B0000000 +00000000A0000000B00000000 0000000000000000000000000 -0000000A000000000B0000000 +00000000A0000000B00000000 0000000000000000000000000 -0000000A000000000B0000000 +00000000A0000000B00000000 0000000000000000000000000 -0000000A000000000B0000000 +00000000A0000000B00000000 0000000000000000000000000 -0000000A000000000B0000000 +00000000A0000000B00000000 0000000000000000000000000 -0000000A000000000B0000000 +00000000A0000000B00000000 0000000000000000000000000 0000000000000000000000000 000000000000P000000000000
@@ -3,16 +3,16 @@ 0000000000000000000000000
0000000000000000000000000 0000000000000000000000000 00000000BBBBBBBBB00000000 -0000000B11111111B00000000 -0000000B11111111B00000000 -0000000B11111111B00000000 -0000000B11111111B00000000 -0000000B11111111B00000000 -0000000B11111111B00000000 -0000000B11111111B00000000 -0000000B11111111B00000000 -0000000B11111111B00000000 -00000000BBB11BBB000000000 +000000B11B1111111B0000000 +000000B11B1111111B0000000 +000000B11B1111111B0000000 +000000B11B1111111B0000000 +000000BBBB1111111B0000000 +000000B1111111111B0000000 +000000B1111111111B0000000 +000000B1111111111B0000000 +000000B1111111111B0000000 +0000000BBBB11BBBB00000000 0000000000000000000000000 0000000000000000000000000 0000000000000000000000000
@@ -19,4 +19,6 @@
def set_sprite_dialogue(self): """Sets unique dialogue for each sprite""" for sprite in self.sprites: - pass + if sprite.location == [14, 6]: + sprite.dialogue = ["There are evil forces encroaching on our town.", + "Trust no one and you may leave these lands alive."]
@@ -3,16 +3,16 @@ 0000000000000000000000000
0000000000000000000000000 0000000000000000000000000 0000000000000000000000000 -00000000BBBBBBBB000000000 -00000000BBBBBBBB000000000 -00000000BBBBBBBB000000000 -00000000BBBBBBBB000000000 -00000000BBBBBBBB000000000 -00000000BBBBBBBB000000000 -00000000BBBBBBBB000000000 -00000000BBBBBBBB000000000 -00000000BBBQEBBB000000000 -00000000KKKKKKKK000000000 +0000000BBBBBBBBBB00000000 +0000000BBBBBBBBBB00000000 +0000000BBBBBBBBBB00000000 +0000000BBBBBBBBBB00000000 +0000000BBBBBBBBBB00000000 +0000000BBBBBBBBBB00000000 +0000000BBBBBBBBBB00000000 +0000000BBBBBBBBBB00000000 +0000000BBBBQEBBBB00000000 +0000000KKKKKKKKKK00000000 0000000000000000000000000 0000000000000000000000000 0000000000000000000000000
@@ -0,0 +1,19 @@
+0000000000000000000000000 +0000000G00000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000E11111111100000000 +000000011111J111100000000 +0000000111111111100000000 +0000000111111111100000000 +0000000111111111100000000 +0000000111111111100000000 +0000000111111111100000000 +0000000111111111100000000 +0000000111111111100000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000
@@ -0,0 +1,19 @@
+0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000111111111100000000 +0000000111111111100000000 +0000000111111111100000000 +0000000111111111100000000 +0000000111111111100000000 +0000000111111111100000000 +0000000111111111100000000 +0000000111111111100000000 +0000000111111111100000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000
@@ -4,7 +4,7 @@ 0000000000000000000000000
0000000000000000000000000 0000000000000000000000000 0000000000000000000000000 -0000000000S00000000000000 +00000000000000H0000000000 0000000000000000000000000 0000000000000000000000000 0000000000000000000000000
@@ -28,12 +28,15 @@ self.game_data = game_data
print(game_data['player inventory']) self.current_time = current_time self.state = 'normal' - self.town_map = tm.make_level_map(self.name, - self.map_width, - self.map_height) - self.viewport = tm.create_viewport(self.town_map) + self.background = tm.create_map_layer1(self.name, + self.map_width, + self.map_height) + self.foreground = tm.create_map_layer2(self.name, + self.map_width, + self.map_height) + self.viewport = tm.create_viewport(self.background) self.blockers = tm.create_blockers(self.name) - self.level_surface = tm.make_level_surface(self.town_map) + self.level_surface = tm.make_level_surface(self.background) self.level_rect = self.level_surface.get_rect() self.player = person.Player(game_data['last direction']) self.sprites = pg.sprite.Group()@@ -140,9 +143,10 @@
def draw_level(self, surface): """Blits all images to screen""" - self.level_surface.blit(self.town_map['surface'], self.viewport, self.viewport) + self.level_surface.blit(self.background, self.viewport, self.viewport) self.level_surface.blit(self.player.image, self.player.rect) self.sprites.draw(self.level_surface) + self.level_surface.blit(self.foreground, self.viewport, self.viewport) surface.blit(self.level_surface, (0, 0), self.viewport) self.dialogue_handler.draw(surface)
@@ -0,0 +1,50 @@
+#T000000000000000000T000# +000000000L00R0000000000#0 +#0W0000M0000000000000W#0# +0#W000000000000000000W0#0 +#0V000T00Q0O00Q0T0000V#0# +0#V000000000000000000V0#0 +#0V000000000000000000V#0# +00V000000000000000000V0#0 +#TV00000000000000000TV00# +00000000000000000000000#0 +#00000000000000000000000# +0000000000000000000000000 +@@@@@@@@@@@00@@@@@@@@@@@@ +0000000000000000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0333033300011000033303330 +0333033300011000033303330 +0222022200011000022202220 +02D202D20001100002D202D20 +0010001000011000001000100 +0011111111111111111111100 +0000000000011000000000000 +0000000000011000000000000 +00000000001$*100000000000 +0000000001$*$*10000000000 +00000000001$*100000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000033333000 +0003330000011000033333000 +0003330000011000022222000 +00022200000110000222D2000 +0002D20000011000000010000 +0000100000011000000010000 +0000111111111111111110000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000
@@ -1,50 +0,0 @@
-#T000000000000000000T000# -000000000L00R0000000000#0 -#0W0000M0000000000000W#0# -0#W000000000000000000W0#0 -#0V000T00Q0O00Q0T0000V#0# -0#V000000000000000000V0#0 -#0V000000000000000000V#0# -00V000000000000000000V0#0 -#TV00000000000000000TV00# -00000000000000000000000#0 -#00000000000000000000000# -0000000000000000000000000 -@@@@@@@@@@@00@@@@@@@@@@@@ -0000000000000000000000000 -0000000000011000000000000 -0000000000011000000000000 -0000000000011000000000000 -0000000000011000000000000 -0000000000011000000000000 -0333033300011000033303330 -0333033300011000033303330 -0222022200011000022202220 -02D202D20001100002D202D20 -0010001000011000001000100 -0011111111111111111111100 -0000000000011000000000000 -0000000000011000000000000 -00000000001$*100000000000 -0000000001$*$*10000000000 -00000000001$*100000000000 -0000000000011000000000000 -0000000000011000000000000 -0000000000011000000000000 -0000000000011000000000000 -0000000000011000000000000 -0000000000011000000000000 -0000000000011000000000000 -0000000000011000000000000 -0000000000011000033333000 -0003330000011000033333000 -0003330000011000022222000 -00022200000110000222D2000 -0002D20000011000000010000 -0000100000011000000010000 -0000111111111111111110000 -0000000000011000000000000 -0000000000011000000000000 -0000000000011000000000000 -0000000000011000000000000 -0000000000011000000000000
@@ -16,6 +16,7 @@ tileset3 = setup.GFX['tileset3']
shopsigns = setup.GFX['shopsigns'] castle_door = setup.GFX['castledoor'] medieval_signs = setup.GFX['medievalsigns'] + house = setup.GFX['house'] tile_dict['pavement'] = get_tile(32, 48, tileset2) tile_dict['house wall'] = get_tile(64, 48, tileset2)@@ -58,6 +59,12 @@ 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) return tile_dict@@ -85,17 +92,6 @@
return new_dict -def make_level_map(state, width, height): - """Blits the different layers of the map onto one surface""" - map = make_background(state, width, height) - map = create_map_layer1(map, state) - map = create_map_layer2(map, state) - map = scale_map(map) - map = create_map_layer3(map, state) - - return map - - def make_background(state_name, width, height): """Creates the background surface that the rest of the town map will be blitted on"""@@ -115,17 +111,14 @@ rect.y = row * 16
rect.x = column * 16 surface.blit(tile, rect) - surface_rect = surface.get_rect() + return surface - background_dict = {'surface': surface, - 'rect': surface_rect} - return background_dict - - -def create_map_layer1(map, state): +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):@@ -224,12 +217,20 @@
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(map, state): +def create_map_layer2(state, width, height, file_name='layer2.txt'): """Creates doors and other items on top of the rest of the map""" - tile_map = open(os.path.join('data', 'states', state, 'layer2.txt'), 'r') + map = make_background(None, width, height) + map.set_colorkey(c.BLACK_BLUE) + + 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):@@ -278,16 +279,37 @@ blit_tile_to_map(tile, row, column, map)
elif letter == 'C': tile = tile_dict['banner3'] blit_tile_to_map(tile, row, column, map) + elif letter == 'E': + tile = tile_dict['bed'] + blit_tile_to_map(tile, row, column, map) + elif letter == 'G': + tile = tile_dict['shelves'] + blit_tile_to_map(tile, row, column, map) + elif letter == 'H': + tile = tile_dict['chair'] + blit_tile_to_map(tile, row, column, map) + elif letter == 'I': + tile = tile_dict['table'] + blit_tile_to_map(tile, row, column, map) + elif letter == 'J': + tile = tile_dict['fancy carpet'] + blit_tile_to_map(tile, row, column, map) + elif letter == 'K': + tile = tile_dict['column'] + 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['surface'] = pg.transform.scale2x(map['surface']) - map['rect'] = map['surface'].get_rect() + map = pg.transform.scale2x(map) return map@@ -313,6 +335,10 @@ blit_tile_to_map(tile, row, column, map, 32)
elif letter == 'I': tile = tile_dict['inn sign'] blit_tile_to_map(tile, row, column, map, 32) + elif letter == 'B': + tile = tile_dict['chair'] + blit_tile_to_map(tile, row, column, map, 32) + tile_map.close()@@ -325,7 +351,7 @@ """Places tile to map"""
tile['rect'].x = column * side_length tile['rect'].y = row * side_length - map['surface'].blit(tile['surface'], tile['rect']) + map.blit(tile['surface'], tile['rect']) def create_blockers(state):@@ -346,15 +372,17 @@
def make_level_surface(map): """Creates the surface all images are blitted to""" - width = map['rect'].width - height = map['rect'].height + map_rect = map.get_rect() + size = map_rect.size + - return pg.Surface((width, height)).convert() + return pg.Surface(size).convert() def create_viewport(map): """Create the viewport to view the level through""" - return setup.SCREEN.get_rect(bottom=map['rect'].bottom) + map_rect = map.get_rect() + return setup.SCREEN.get_rect(bottom=map_rect.bottom) def set_sprite_positions(player, level_sprites, state, game_data):@@ -392,6 +420,9 @@ 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) tile_map.close()