Example #1
0
# LEVEL_GENERATION = [BSPTreeAlgorithm, CellularAutomataAlgorithm, RandomWalkAlgorithm, TunnelingAlgorithm]
# LEVEL_GENERATION = [RandomWalkAlgorithm]
LEVEL_GENERATION = [RandomWalkAlgorithm, TunnelingAlgorithm]
"""
1. Tunneling Algorithm
2. BSP Tree Algorithm
3. Random Walk Algorithm
4. Cellular Automata
5. Room Addition
6. City Buildings
7. Maze with Rooms
8. Messy BSP Tree
"""

MOBS = obtain_mob_table()
ITEMS = obtain_item_table()


class GameMap(Map):
    explored = [[]]  # boolean 2d numpy array of what player has explored
    tileset_tiles = [[]]  # 2d numpy array of indexes from tile_set.json
    map_objects = [
    ]  # list of map object entities that can be interacted with  does not need to be iterated through every frame
    # char_tiles = [[]]  # 2d numpy array of just the glyphs need to see if this is still needed
    level = ''  # name of level generation algorithm
    map = None
    player = None
    stairs = None
    tile_cost = [
        []
    ]  # 2d numpy array of integers of "traversal costs" of each node
Example #2
0
    def make_map(self,
                 max_rooms,
                 room_min_size,
                 room_max_size,
                 map_width,
                 map_height,
                 player,
                 entities,
                 particles,
                 particle_systems,
                 encounters,
                 level=None):
        # Map Generation Variables
        self.game_events = []
        self.player = player
        self.stairs = None
        self.rooms = []
        self.map = None
        self.turn_count = 0
        if encounters:
            self.encounters = encounters
        else:
            self.encounters = []

        mob_table = MOBS
        item_table = obtain_item_table()

        # Obtain only "Objects" from Tile Set
        # furniture_table = {key: val for key, val in self.tile_set.items() if val.get('type') == 'object'}

        # print('level:', level)
        # if level == 'overworld':
        #     self.default_tile = 0
        #     self.initialize_open_map()
        #     self.level = 'overworld'
        #     self.map = Overworld()
        #
        # elif level == 'undergrave':
        #     self.default_tile = 1
        #     self.initialize_closed_map()
        #     self.map = UndergravePrison()
        #     self.level = 'undergrave'
        #
        # elif level == 'resinfaire':
        #     self.default_tile = 13
        #     self.initialize_closed_map()
        #     self.map = ResinFaireForest()
        #     self.level = 'resinfaire'
        #     mob_table = obtain_mob_table("resinfaire_mobs")
        #     item_table = obtain_item_table()
        #
        # else:
        #     self.default_tile = 1
        #     self.initialize_closed_map()
        #     self.map = choice(LEVEL_GENERATION)()
        #     self.level = 'Dungeon'
        print('self.dungeon_level:', self.dungeon_level,
              self.dungeon_level == 0)
        if self.dungeon_level == 0:
            self.level_message = "Arena Level"
            self.default_tile = 1
            self.initialize_closed_map()
            self.map = Arena()
            self.level = 'arena'
            mob_table = {
                **obtain_mob_table("resinfaire_mobs"),
                **obtain_mob_table("yendor_1_mobs"),
                **obtain_mob_table("yendor_2_mobs")
            }
            # for mob, stats in mob_table.items():
            #     print(mob, stats)
            map_width = 30
            map_height = 30
            item_table = obtain_item_table()
        elif self.dungeon_level == 1:
            self.level_message = "You begin your journey to the Castle of Yendor.\n\nThe tales of its plagued forest, massacred-crazed townsfolk and corrupt King perplex you.\n\nIt's time to find out what happened."
            self.default_tile = 13
            self.initialize_closed_map()
            self.map = ResinFaireForest()
            self.level = 'resinfaire'
            mob_table = obtain_mob_table("resinfaire_mobs")
            map_width = 45
            map_height = 45
            item_table = obtain_item_table()
        elif self.dungeon_level == 2:
            self.level_message = "As you continue through Resinfaire Forest, you begin notice the normal denizens look slightly warped.\n\n\"What must've happened?\"\n-you wonder.\n\nYou step forward cautiously\n\nIt's time to get revenge.."
            self.default_tile = 13
            self.initialize_closed_map()
            self.map = ResinFaireForest()
            self.level = 'resinfaire'
            mob_table = obtain_mob_table("resinfaire_mobs")
            item_table = obtain_item_table()
            map_width = 40
            map_height = 55
        elif self.dungeon_level == 3:
            self.level_message = "You see a village in the distance.\n\nIt's time to get revenge."
            self.default_tile = 13
            self.initialize_closed_map()
            self.map = ResinFaireForest()
            self.level = 'resinfaire'
            mob_table = obtain_mob_table("resinfaire_mobs")
            item_table = obtain_item_table()
            map_width = 55
            map_height = 55
        elif self.dungeon_level == 4:
            self.level_message = "You enter Resinfaire Castle\n\nYou feel darkness envelops you as you hear faint voices and make out figures in the distance. They haven't noticed your arrival yet.\n\nIt's time to get revenge."
            self.default_tile = 52
            self.initialize_closed_map()
            self.map = YendorCastleOuter()
            self.level = 'yendor castle inner'
            mob_table = obtain_mob_table("yendor_1_mobs")
            item_table = obtain_item_table()
            map_width = 55
            map_height = 55
        elif self.dungeon_level == 5:
            self.level_message = "You feel the eyes of the entire castle, are fastened on you.\n\nYou peer into the darkness ready for the onslaught of corrupted knights coming your way.\n\nIt's time to get revenge."
            self.default_tile = 52
            self.initialize_closed_map()
            self.map = YendorCastleInner()
            self.level = 'yendor castle inner'
            mob_table = obtain_mob_table("yendor_2_mobs")
            item_table = obtain_item_table()
            map_width = 60
            map_height = 60
        else:
            self.level_message = "The journey continues. You clench your weapon tightly and trudge forward."
            self.default_tile = 1
            self.initialize_closed_map()
            self.map = choice(LEVEL_GENERATION)()
            self.level = 'Dungeon'

        print('\n\nGeneration Type for Dungeon Level %s: %s' %
              (self.dungeon_level, self.map.__class__))
        self.map.generate_level(self, self.dungeon_level, max_rooms,
                                room_min_size, room_max_size, map_width,
                                map_height, player, entities, particles,
                                particle_systems, item_table, mob_table)

        # If any Other Entities Escaped to the Next Level, Add them and Find a Suitable Place
        if self.next_floor_entities:
            print('\n\nThere are next floor entities!!!')
            for e in self.next_floor_entities:
                print('\t{}'.format(e.name))
            # entities.extend(deepcopy(self.next_floor_entities))
        self.next_floor_entities = []
Example #3
0
    def designate_rooms(self, entities, game_map, no_entrances, one_entrances,
                        two_entrances, three_entrances, multi_entrances,
                        no_entrances_room, one_entrances_room,
                        two_entrances_room, three_entrances_room,
                        multi_entrances_room):
        print('\nDesignate Rooms:')
        print(
            'No Entrances: %s\nOne Entrance: %s\nTwo Entrances: %s\nThree Entrances: %s\nMulti Entrances: %s'
            % (no_entrances, one_entrances, two_entrances, three_entrances,
               multi_entrances))

        mob_table = obtain_mob_table()
        item_table = obtain_item_table()

        # Obtain only "Objects" from Tile Set
        object_table = {
            key: val
            for key, val in game_map.tile_set.items()
            if val.get('type') == 'object'
        }

        monster_chances = {
            mob:
            spawn_chance([stats for stats in mob_stats.get('spawn_chance')],
                         self.dungeon_level)
            for mob, mob_stats in mob_table.items()
        }
        object_chances = {
            object: spawn_chance([[
                object_stats.get('spawn_chance'),
                object_stats.get('item_level')
            ]], self.dungeon_level)
            for object, object_stats in object_table.items()
        }

        item_chances = {
            item: spawn_chance([[
                item_stats.get('spawn_chance'),
                item_stats.get('item_level')
            ]], self.dungeon_level)
            for item, item_stats in item_table.items()
        }

        # generate_items(entities, game_map, room, number_of_items, item_chances, item_table):
        # generate_mobs(entities, game_map, room, number_of_mobs, monster_chances, mob_table, encounter_type, encounter):
        # generate_objects(entities, game_map, room, number_of_items, object_chances, object_table):

        for room in no_entrances_room:
            c = choice(
                ['treasure_room', 'hard_monster_room', 'dead_prisoner_room'])
            encounter_type = None
            encounter = None
            number_of_items = 0
            number_of_objects = 0
            number_of_mobs = 0
            if c == 'treasure_room':
                number_of_items = randint(1, 5)
                number_of_objects = randint(2, 5)
            elif c == 'hard_monster_room':
                encounter_type = DefensiveMob
                encounter = Encounter(room, len(game_map.encounters),
                                      encounter_type)
                number_of_objects = randint(1, 2)
                number_of_mobs = 1
            generate_mobs(entities, game_map, room, number_of_mobs,
                          monster_chances, mob_table, encounter_type,
                          encounter)
            generate_items(entities, game_map, room, number_of_items,
                           item_chances, item_table)
            generate_objects(entities, game_map.map_objects, game_map, room,
                             number_of_objects, object_chances, object_table)
            room.room_type = c

        for room in one_entrances_room:
            c = choice([
                'alarm_room', 'small_jail_cell', 'supply_room',
                'food_storage_room', 'office_room'
            ])
            encounter_type = None
            encounter = None
            number_of_items = 0
            number_of_objects = 0
            number_of_mobs = 0
            if c == 'alarm_room':
                encounter_type = DefensiveMob
                encounter = Encounter(room, len(game_map.encounters),
                                      encounter_type)
                number_of_items = randint(0, 2)
                number_of_objects = randint(2, 5)
                number_of_mobs = randint(0, 1)
            elif c == 'small_jail_cell':
                encounter_type = DefensiveMob
                encounter = Encounter(room, len(game_map.encounters),
                                      encounter_type)
                number_of_items = randint(0, 2)
                number_of_objects = randint(2, 5)
                number_of_mobs = randint(1, 2)
            elif c == 'supply_room':
                number_of_items = randint(2, 5)
                number_of_objects = randint(5, 7)
            elif c == 'food_storage_room':
                number_of_items = randint(2, 5)
                number_of_objects = randint(5, 7)
            elif c == 'office_room':
                number_of_items = randint(2, 3)
                number_of_objects = randint(5, 7)
            generate_mobs(entities, game_map, room, number_of_mobs,
                          monster_chances, mob_table, encounter_type,
                          encounter)
            generate_items(entities, game_map, room, number_of_items,
                           item_chances, item_table)
            generate_objects(entities, game_map.map_objects, game_map, room,
                             number_of_objects, object_chances, object_table)
            room.room_type = c

        for room in two_entrances_room:
            c = choice(['small_jail_cell', 'medium_jail_cell'])
            encounter_type = None
            encounter = None
            number_of_items = 0
            number_of_objects = 0
            number_of_mobs = 0
            if c == 'small_jail_cell':
                pop = [DefensiveMob, PatrolMob]
                weights = [80, 20]
                encounter_type = choices(population=pop, weights=weights,
                                         k=1)[0]

                encounter = Encounter(room, len(game_map.encounters),
                                      encounter_type)
                number_of_items = randint(0, 2)
                number_of_objects = randint(2, 5)
                number_of_mobs = randint(0, 1)
            elif c == 'medium_jail_cell':
                pop = [DefensiveMob, PatrolMob]
                weights = [80, 20]
                encounter_type = choices(population=pop, weights=weights,
                                         k=1)[0]

                encounter = Encounter(room, len(game_map.encounters),
                                      encounter_type)
                number_of_items = randint(0, 2)
                number_of_objects = randint(2, 5)
                number_of_mobs = randint(0, 3)
            room.room_type = c
            generate_mobs(entities, game_map, room, number_of_mobs,
                          monster_chances, mob_table, encounter_type,
                          encounter)
            generate_items(entities, game_map, room, number_of_items,
                           item_chances, item_table)
            generate_objects(entities, game_map.map_objects, game_map, room,
                             number_of_objects, object_chances, object_table)

        for room in three_entrances_room + multi_entrances_room:
            c = choice(['medium_jail_cell', 'large_jail_cell'])
            encounter_type = None
            encounter = None
            number_of_items = 0
            number_of_objects = 0
            number_of_mobs = 0

            if c == 'medium_jail_cell':
                pop = [DefensiveMob, PatrolMob]
                weights = [80, 20]
                encounter_type = choices(population=pop, weights=weights,
                                         k=1)[0]

                encounter = Encounter(room, len(game_map.encounters),
                                      encounter_type)
                number_of_items = randint(0, 2)
                number_of_objects = randint(2, 5)
                number_of_mobs = randint(0, 3)
            elif c == 'large_jail_cell':
                pop = [DefensiveMob, PatrolMob]
                weights = [80, 20]
                encounter_type = choices(population=pop, weights=weights,
                                         k=1)[0]

                encounter = Encounter(room, len(game_map.encounters),
                                      encounter_type)
                number_of_items = randint(0, 4)
                number_of_objects = randint(4, 7)
                number_of_mobs = randint(0, 5)

            generate_items(entities, game_map, room, number_of_items,
                           item_chances, item_table)
            generate_mobs(entities, game_map, room, number_of_mobs,
                          monster_chances, mob_table, encounter_type,
                          encounter)
            generate_objects(entities, game_map.map_objects, game_map, room,
                             number_of_objects, object_chances, object_table)
            room.room_type = c
        """