def spawn_troll(x, y): monster = Entity(x, y, render_order=RenderOrder.ACTOR, components={ 'ai': BasicMonster(), 'fighter': Fighter(hp=30, defense=2, power=8, xp=100), }) monster.set_appearance('T', tcod.darker_green, "Troll") return monster
def spawn_dragon(x, y): monster = Entity(x, y, render_order=RenderOrder.ACTOR, components={ 'ai': BasicMonster(), 'fighter': Fighter(hp=35, defense=4, power=12, xp=300), }) monster.set_appearance('D', tcod.light_flame, "Red Dragon") return monster
def spawn_ogre(x, y): monster = Entity(x, y, render_order=RenderOrder.ACTOR, components={ 'ai': BasicMonster(), 'fighter': Fighter(hp=25, defense=1, power=6, xp=75), }) monster.set_appearance('O', tcod.desaturated_green, "Ogre") return monster
def spawn_kobold(x, y): monster = Entity(x, y, render_order=RenderOrder.ACTOR, components={ 'ai': BasicMonster(), 'fighter': Fighter(hp=10, defense=0, power=3, xp=25), }) monster.set_appearance('k', tcod.desaturated_green, "Kobold") return monster
def spawn_orc(x, y): monster = Entity(x, y, render_order=RenderOrder.ACTOR, components={ 'ai': BasicMonster(), 'fighter': Fighter(hp=20, defense=0, power=4, xp=35), }) monster.set_appearance('o', tcod.desaturated_green, "Orc") return monster
def generate_rooms(self, map_width, map_height, max_rooms, player): self.rooms = [] entities = [] num_rooms = 0 center_of_last_room_x = None center_of_last_room_y = None for r in range(max_rooms): # random width and height w = randint(self.room_min_size, self.room_max_size) h = randint(self.room_min_size, self.room_max_size) # random position without going out of the boundaries of the map x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) new_room = Rect(x, y, w, h) # run through the other rooms and see if they intersect with this one for other_room in self.rooms: if new_room.intersect(other_room): break else: entities.extend(self.place_entities(new_room, player)) entities.extend(self.place_items(new_room)) self.rooms.append(new_room) # center coordinates of new room, will be 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: # connect all rooms after the first to the previous room with a tunnel # center coordinates of previous room (prev_x, prev_y) = self.rooms[num_rooms - 1].center() self.dig_tunnel_to_previous_room(new_x, new_y, prev_x, prev_y) num_rooms += 1 down_stairs = Entity(center_of_last_room_x, center_of_last_room_y, render_order=RenderOrder.STAIRS, components={'stairs': Stairs(self.dungeon_level + 1), }) down_stairs.set_appearance('>', tcod.white, 'Stairs') entities.append(down_stairs) return entities
def get_game_variables(constants): player = Entity(0, 0, blocks_movement=True, render_order=RenderOrder.ACTOR, components={ 'fighter': Fighter(hp=100, defense=1, power=2), 'inventory': Inventory(26), 'level': Level(), 'equipment': Equipment(), }) player.set_appearance('@', tcod.white, 'Player') entities = [player] equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=2) dagger = Entity(0, 0, components={ 'equippable': equippable_component, }) dagger.set_appearance( '-', tcod.sky, 'Dagger', ) player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) game_map = GameMap(constants['map_width'], constants['map_height'], constants['room_min_size'], constants['room_max_size']) entities.extend(game_map.make_map(constants['max_rooms'], player)) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def place_items(self, room): items = [] max_items_per_room = from_dungeon_level([[1, 1], [2, 4]], self.dungeon_level) number_of_items = randint(0, max_items_per_room) item_chances = { 'healing_potion': 35, 'super_healing': from_dungeon_level([[10, 3]], self.dungeon_level), 'lightning_scroll': from_dungeon_level([[25, 4]], self.dungeon_level), 'fireball_scroll': from_dungeon_level([[25, 6]], self.dungeon_level), 'confusion_scroll': from_dungeon_level([[4, 2]], self.dungeon_level), 'short_sword': from_dungeon_level([[5, 2], [10, 3], [5, 5], [0, 6]], self.dungeon_level), 'long_sword': from_dungeon_level([[5, 3], [10, 5], [5, 7], [0, 8]], self.dungeon_level), 'mithril_sword': from_dungeon_level([[5, 6], [10, 7], [5, 9]], self.dungeon_level), 'buckler_shield': from_dungeon_level([[15, 4], [5, 5], [0, 6]], self.dungeon_level), 'small_shield': from_dungeon_level([[15, 6], [5, 8], [0, 9]], self.dungeon_level), 'tower_shield': from_dungeon_level([[5, 8], [10, 10]], self.dungeon_level), 'meteorite_shield': from_dungeon_level([[5, 9], ], self.dungeon_level), } for i in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) equippable_component = None item_component = None item_choice = random_choice_from_dict(item_chances) if item_choice == 'super_healing': name = "Mega Healing Potion" color = tcod.lighter_violet char = '!' item_component = Item(use_function=heal, amount=80) elif item_choice == 'confusion_scroll': name = "Scroll of Confusion" color = tcod.light_pink char = '~' item_component = Item(use_function=cast_confuse, targeting=True, targeting_message=Message( 'Left-click an enemy to confuse it, or right-click to cancel.', tcod.light_cyan)) elif item_choice == 'lightning_scroll': name = "Scroll of Lightning" color = tcod.yellow char = '~' item_component = Item(use_function=cast_lightning, damage=40, maximum_range=5) elif item_choice == 'fireball_scroll': name = "Scroll of Fireball" color = tcod.flame char = '~' item_component = Item( use_function=cast_fireball, targeting=True, targeting_message=Message( "Left-click a target tile for the fireball, or right-click to cancel.", tcod.light_cyan), damage=25, radius=3) elif item_choice == 'short_sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=4) char = ')' color = tcod.light_grey name = 'Short Sword' elif item_choice == 'long_sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=5) char = ')' color = tcod.light_gray name = 'Long Sword' elif item_choice == 'mithril_sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=7) char = ')' color = tcod.dark_sky name = 'Mithril Sword' elif item_choice == 'buckler_shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=1) char = '[' color = tcod.gray name = 'Buckler Shield' elif item_choice == 'small_shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=2) char = '[' color = tcod.darker_orange name = 'Small Shield' elif item_choice == 'tower_shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=4) char = '[' color = tcod.desaturated_orange name = 'Tower Shield' elif item_choice == 'meteorite_shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=6) char = '[' color = tcod.dark_blue name = 'Meteorite Tower Shield' else: # item_choice == 'healing_potion': name = "Healing Potion" color = tcod.violet char = '!' item_component = Item(use_function=heal, amount=40) if not any([entity for entity in items if entity.x == x and entity.y == y]): item = Entity(x, y, render_order=RenderOrder.ITEM, components={ 'item': item_component, 'equippable': equippable_component, }) item.set_appearance(char, color, name) items.append(item) return items