def fill_tiles(self, dungeon_type, subtype, node_power): rooms = [] num_rooms = 0 center_of_last_room_x = None center_of_last_room_y = None for r in range(MAX_ROOMS): w = randint(ROOM_MIN_SIZE, ROOM_MAX_SIZE) h = randint(ROOM_MIN_SIZE, ROOM_MAX_SIZE) # random position without going out of boundaries of the map x = randint(0, self.width - w - 1) y = randint(0, self.height - h - 1) new_room = Rect(x, y, w, h) for other_room in rooms: if new_room.intersect(other_room): break else: # No intersections, ergo valid room # "paint" to map's tiles self.create_room(new_room, dungeon_type, subtype) # center coordinates of new room, useful later (new_x, new_y) = new_room.center() center_of_last_room_x = new_x center_of_last_room_y = new_y if num_rooms == 0: # First room, where player starts self.entrance = (new_x, new_y) else: # all rooms after first # connect it to previous room with a tunnel # center of previous room (prev_x, prev_y) = rooms[num_rooms - 1].center() # flip a coin if randint(0, 1) == 1: # first horizontal, then vertical self.create_h_tunnel(prev_x, new_x, prev_y, dungeon_type, subtype) self.create_v_tunnel(prev_y, new_y, new_x, dungeon_type, subtype) else: # first vertical, then horizontal self.create_v_tunnel(prev_y, new_y, prev_x, dungeon_type, subtype) self.create_h_tunnel(prev_x, new_x, new_y, dungeon_type, subtype) # append room to list # self.place_entities(new_room, dungeon_type, subtype, node_power) rooms.append(new_room) self.exit = (center_of_last_room_x, center_of_last_room_y) num_rooms += 1
def get_major_road(self, outer_scenery_dim): rect = Rect(outer_scenery_dim, int(self.height / 2) - 2, self.width - outer_scenery_dim * 2, 4) road = MajorRoad(rect, self.node) road.set_transitions('vertical') return road
class TownAlphaInn(PrefabStructure): _floors = inn_floor_array() _blockers = inn_blocker_array() _overhead = inn_overhead_array() rect = Rect(76, 42, 11, 10) is_interior = True def __init__(self): super().__init__() self.set_transitions() def set_transitions(self): pass
class TownAlphaOrphanage(PrefabStructure): _floors = orphanage_floor_array() _blockers = orphanage_blocker_array() _overhead = orphanage_overhead_array() rect = Rect(69, 14, 13, 10) is_interior = True def __init(self): super().__init__() self.set_transitions() def set_transitions(self): pass
class TownAlphaChurch(PrefabStructure): _floors = church_floor_array() _blockers = church_blocker_array() _overhead = church_overhead_array() rect = Rect(84, 18, 7, 13) is_interior = True def __init(self): super().__init__() self.set_transitions() def set_transitions(self): pass
class TownAlphaGuardHut(PrefabStructure): _floors = guard_hut_floor_array() _blockers = guard_hut_blocker_array() _overhead = guard_hut_overhead_array() rect = Rect(14, 42, 7, 15) is_interior = True def __init(self): super().__init__() self.set_transitions() def set_transitions(self): pass
class TownAlphaMayorHouse(PrefabStructure): _floors = mayor_house_floor_array() _blockers = mayor_house_blocker_array() _overhead = mayor_house_overhead_array() rect = Rect(43, 7, 14, 12) is_interior = True def __init(self): super().__init__() self.set_transitions() def set_transitions(self): pass
class TownAlphaTavern(PrefabStructure): _floors = tavern_floor_array() _blockers = tavern_blocker_array() _overhead = tavern_overhead_array() rect = Rect(72, 53, 17, 9) is_interior = True def __init(self): super().__init__() self.set_transitions() def set_transitions(self): pass
class OverworldTown(PrefabStructure): """Fills tiles with generic townfloor image, fills floor transitions based on given plot node""" _floors = None _decorations = [[OverworldTownTileFloor(img) for img in row] for row in OVERWORLD_TOWN] _blockers = None _overhead = None rect = Rect(0, 0, len(_decorations[0]), len(_decorations)) is_interior = False def __init__(self, node): super().__init__() self.set_transitions(node) def set_transitions(self, node): trans = Transition('The entrance to ' + node.name.capitalize(), BUNDLE_ALPHA, node.name, 0, (node.entrance[0], node.entrance[1])) for row in self.tiles: for tile in row: tile.floor.transition = trans
def get_town_walls(self, outer_scenery_dim): rect = Rect(outer_scenery_dim, outer_scenery_dim, self.width - outer_scenery_dim * 2, self.height - outer_scenery_dim * 2) walls = TownWalls(rect, 'stone') return walls
def get_structures(): inn_road = Road(Rect(87, 45, 3, 3)) mage_garden = Road(Rect(20, 7, 10, 8)) mage_road = Road(Rect(11, 16, 3, 19)) mayor_road = Road(Rect(49, 19, 3, 16)) guard_grounds = Road(Rect(8, 59, 13, 7)) guard_road1 = Road(Rect(8, 39, 3, 12)) guard_road2 = Road(Rect(11, 48, 3, 3)) church_graveyard = Road(Rect(83, 8, 9, 8)) church_road = Road(Rect(86, 31, 3, 4)) market = Road(Rect(36, 30, 28, 14)) orphan_road = Road(Rect(74, 24, 3, 11)) inntavern_road = Road(Rect(90, 39, 3, 28)) tavern_road1 = Road(Rect(79, 64, 11, 3)) tavern_road2 = Road(Rect(79, 62, 3, 2)) structures = [ TownAlphaInn(), inn_road, TownAlphaMageHouse(), mage_garden, mage_road, TownAlphaMayorHouse(), mayor_road, TownAlphaGuardHut(), guard_grounds, guard_road1, guard_road2, TownAlphaTavern(), TownAlphaChurch(), church_graveyard, church_road, market, TownAlphaOrphanage(), orphan_road, inntavern_road, tavern_road1, tavern_road2 ] return structures