def construct_objects(self): stair = entities.Object(self.up[0], self.up[1], char="<", name="stair", colour=libtcod.purple, blocks=False, always_visible=False) self.objects.append(stair) stair = entities.Object(self.down[0], self.down[1], char=">", name="stair", colour=libtcod.red, blocks=False, always_visible=False) self.objects.append(stair) if len(self.rects) > 0: room = self.rects[libtcod.random_get_int(0, 0, len(self.rects) - 1)] item = entities.Item() potion = entities.Object( libtcod.random_get_int(0, room.x, room.x + room.w - 2), libtcod.random_get_int(0, room.y, room.y + room.h - 2), char="!", name="potion", colour=libtcod.orange, blocks=False, always_visible=False, item=item) self.objects.append(potion)
def new_game(): global game_msgs, test_msgs, ui, game_state global world, world_obj, cities, player, selected global tiles, cam_x, cam_y global key, mouse mouse = libtcod.Mouse() key = libtcod.Key() cam_x, cam_y = 0, 0 game_state = "playing" test_msgs = [] world = R.world = worldMap.Map(R.MAP_WIDTH, R.MAP_HEIGHT) world_obj = R.world_obj = [] tiles = R.tiles = world.tiles #make_map() cities = R.cities = world.cities R.ui.message(str(len(cities)) + " cities have been made!", libtcod.green) for city in cities: #print city.name + str(city.x) + "/" + str(city.y) R.ui.message(city.name + str(city.x) + "/" + str(city.y), libtcod.light_grey) city.createBaseRelationships(cities) # for n in range(5): # city = City(name = libtcod.namegen_generate("city"), resource_list =master_resource_list) # cities.append(city) # city = None # for city in cities: # city.createBaseRelationships(cities) selected = cities[0] player = R.player = entities.Object(name="player", player=entities.Player()) world_obj.append(player) for a in range(5): x, y = worldMap.place_on_land() hero = R.hero = entities.Object(x=x, y=y, name="hero " + str(a), pather=entities.Pather(), ai=entities.AI_Hero()) world_obj.append(hero) render_all() world.connect_cities() world.connect_cities() world.connect_cities() # point = (0,0) # diction = dict() # diction[(0,0)] = 10 # print str(diction[point]) #path = hero.pather.find_path((10,10),(0,0)) R.ui.message("welcome and prepare your mind.", libtcod.blue)
def place_objects(room, Game): #choose random number of monsters #max number monsters per room max_monsters = from_dungeon_level([[3, 1], [4, 3], [5, 6], [7, 10]], Game) num_monsters = libtcod.random_get_int(0, 0, max_monsters) monster_chances = get_monster_chances(Game) max_items = from_dungeon_level([[1, 1], [2, 4]], Game) num_items = libtcod.random_get_int(0, 0, max_items) item_chances = get_item_chances(Game) for i in range(num_monsters): #choose random spot for this monster x = libtcod.random_get_int(0, room.x1 + 1, room.x2 - 1) y = libtcod.random_get_int(0, room.y1 + 1, room.y2 - 1) if not entities.is_blocked(x, y, Game): #create a monster choice = random_choice(monster_chances) monster = entities.Object(**entitydata.mobs[choice]) monster.name = choice monster.blocks = True monster.ai = entities.BasicMonster() #how do I set different ai? monster.ai.owner = monster monster.set_location(x, y, Game) #print 'Added a ' + choice Game.objects.append(monster) for i in range(num_items): #choose random spot for this item x = libtcod.random_get_int(0, room.x1 + 1, room.x2 - 1) y = libtcod.random_get_int(0, room.y1 + 1, room.y2 - 1) #only place it if the tile is not blocked if not entities.is_blocked(x, y,Game): #create an item choice = random_choice(item_chances) item = entities.Object(**entitydata.items[choice]) item.always_visible = True item.set_location(x, y, Game) Game.objects.append(item) item.send_to_back(Game) #items appear below other objects
def generate_floors(self, level=1, num=5): for ID in range(num): monster_num = libtcod.random_get_int(0, 10, 25) item_num = libtcod.random_get_int(0, 5, 15) a_items = [] a_monst = [] for n in range(monster_num): key = random.choice(MONSTERS[str(self.level)].keys()) mons = MONSTERS[str(self.level)][key] #not finsiehd yet. colour = libtcod.Color(mons["colour"][0], mons["colour"][1], mons["colour"][2]) temp = entities.Object(0, 0, char=mons["char"], name=mons["name"], colour=colour, blocks=False, always_visible=False) a_monst.append(mons) for n in range(item_num): item = random.choice(ITEMS) #colour = libtcod.Color(item["colour"][0],item["colour"][1],item["colour"][2]) #temp = entities.Object(0,0, char=item["char"], name=item["name"], colour=colour, blocks=False, always_visible=False) a_items.append(item) floor = Floor(ID, a_monst, a_items) self.floors.append(floor)
def new_game(): #create object representing the player fighter_component = entities.Fighter(hp=300, defense=10, power=20, xp=0, xpvalue=0, clan='monster', death_function=entities.player_death, speed = 10) Game.player = entities.Object(data.SCREEN_WIDTH/2, data.SCREEN_HEIGHT/2, '@', 'Roguetato', libtcod.white, tilechar=data.TILE_MAGE, blocks=True, fighter=fighter_component) Game.player.dungeon_level = 1 Game.game_state = data.STATE_PLAYING Game.player.game_turns = 0 Game.dungeon_levelname = data.maplist[Game.player.dungeon_level] Game.map = {} Game.objects = {} Game.upstairs = {} Game.downstairs = {} Game.tick = 0 if data.FREE_FOR_ALL_MODE: #turn on SQL junk and kill player. Game.entity_sql = logging.Sqlobj(data.ENTITY_DB) Game.message_sql = logging.Sqlobj(data.MESSAGE_DB) Game.sql_commit_counter = data.SQL_COMMIT_TICK_COUNT Game.player.fighter.alive = False Game.player.fighter.hp = 0 #generate map (at this point it's not drawn to screen) maplevel.make_dungeon(Game) Game.tick = 1 Game.fov_recompute = True Game.player.fighter.fov = Game.map[Game.dungeon_levelname].fov_map libtcod.console_clear(Game.con) #initial equipment if not data.AUTOMODE: equipment_component = entities.Equipment(slot='wrist', max_hp_bonus = 5) obj = entities.Object(0, 0, '-', 'wristguards of the whale', libtcod.gold, equipment=equipment_component) obj.always_visible = True Game.player.fighter.add_item(obj) equipment_component.equip(Game, Game.player) Game.player.fighter.hp = Game.player.fighter.max_hp(Game) #a warm welcoming message! message('Welcome to MeFightRogues! Good Luck! Don\'t suck!', Game, libtcod.blue) libtcod.console_set_keyboard_repeat(data.KEYS_INITIAL_DELAY,data.KEYS_INTERVAL)
def give_items(Game): #healing potion x = 0 y = 0 for item in entitydata.items: theitem = entities.Object(**entitydata.items[item]) theitem.always_visible = True Game.player.fighter.add_item(theitem)
def new_game(): #create object representing the player fighter_component = entities.Fighter(hp=100, defense=3, power=6, xp=0, death_function=entities.player_death) Game.player = entities.Object(data.SCREEN_WIDTH / 2, data.SCREEN_HEIGHT / 2, '@', 'Roguetato', libtcod.white, tilechar=data.TILE_MAGE, blocks=True, fighter=fighter_component) Game.player.level = 1 #generate map (at this point it's not drawn to screen) Game.dungeon_level = 1 map.make_map(Game) map.initialize_fov(Game) Game.game_state = data.STATE_PLAYING Game.inventory = [] #create the list of the game messages and their colors, starts empty Game.player.game_turns = 0 #initial equipment equipment_component = entities.Equipment(slot='wrist', max_hp_bonus=5) obj = entities.Object(0, 0, '-', 'wristguards of the whale', libtcod.gold, equipment=equipment_component) Game.inventory.append(obj) equipment_component.equip(Game) obj.always_visible = True #a warm welcoming message! message('Welcome to MeFightRogues! Good Luck! Don\'t suck!', Game, libtcod.blue)
def give_items(Game): #healing potion x = 0 y = 0 item_component = entities.Item(use_function=entities.cast_heal) item = entities.Object(x, y, '!', 'healing potion', libtcod.red, always_visible=True, item=item_component) item.always_visible = True Game.inventory.append(item) #lightning scroll item_component = entities.Item(use_function=entities.cast_lightning) item = entities.Object(x, y, '?', 'scroll of lightning bolt', libtcod.yellow, always_visible=True, item=item_component) Game.inventory.append(item) #fireball scroll item_component = entities.Item(use_function=entities.cast_fireball) item = entities.Object(x, y, '?', 'scroll of fireball', libtcod.red, always_visible=True, item=item_component) Game.inventory.append(item) #confusion scroll item_component = entities.Item(use_function=entities.cast_confusion) item = entities.Object(x, y, '?', 'scroll of confusion', libtcod.light_violet, always_visible=True, item=item_component) Game.inventory.append(item) #sword equipment_component = entities.Equipment(slot='right hand', power_bonus=5) item = entities.Object(x, y, '/', 'sword', libtcod.sky, always_visible=True, equipment=equipment_component) Game.inventory.append(item) #create a shield equipment_component = entities.Equipment(slot='left hand', defense_bonus=3) item = entities.Object(x, y, '[', 'shield', libtcod.darker_orange, equipment=equipment_component) Game.inventory.append(item) #wristguards equipment_component = entities.Equipment(slot='wrist', max_hp_bonus=5) item = entities.Object(0, 0, '-', 'wristguards of the whale', libtcod.gold, equipment=equipment_component) Game.inventory.append(item)
def make_map(Game): Game.objects = [Game.player] #fill map with "blocked" tiles Game.map = [[ Tile(True) for y in range(data.MAP_HEIGHT) ] for x in range(data.MAP_WIDTH) ] rooms = [] num_rooms = 0 for r in range(data.MAX_ROOMS): #get random width/height w = libtcod.random_get_int(0, data.ROOM_MIN_SIZE, data.ROOM_MAX_SIZE) h = libtcod.random_get_int(0, data.ROOM_MIN_SIZE, data.ROOM_MAX_SIZE) #get random positions, but stay within map x = libtcod.random_get_int(0, 0, data.MAP_WIDTH - w - 1) y = libtcod.random_get_int(0, 0, data.MAP_HEIGHT - h - 1) new_room = Rect(x, y, w, h) #check for intersection with this room failed = False for other_room in rooms: if new_room.intersect(other_room): failed = True break if not failed: #no intersections create_room(new_room, Game) (new_x, new_y) = new_room.center() #add some contents to the room place_objects(new_room, Game) if num_rooms == 0: #first room. start player here Game.player.x = new_x Game.player.y = new_y else: #for all other rooms, need to connect to previous room with a tunnel #get center coords of previous room (prev_x, prev_y) = rooms[num_rooms -1].center() #flip coin if flip_coin() == 1: #move h then v create_h_tunnel(prev_x, new_x, prev_y, Game) create_v_tunnel(prev_y, new_y, new_x, Game) else: #move v then h create_v_tunnel(prev_y, new_y, prev_x, Game) create_h_tunnel(prev_x, new_x, new_y, Game) #add to rooms list rooms.append(new_room) num_rooms +=1 #create stairs at the center of the last room Game.stairs = entities.Object(new_x, new_y, '>', 'stairs', libtcod.white, always_visible = True) Game.objects.append(Game.stairs) Game.stairs.send_to_back(Game) #so it's drawn below the monsters
def place_objects(room, Game): #choose random number of monsters #max number monsters per room nextid = 1 max_monsters = from_dungeon_level([[10, 1], [40, 3], [50, 6], [70, 10]], data.maplist.index( Game.dungeon_levelname)) num_monsters = libtcod.random_get_int(0, 0, max_monsters) monster_chances = get_monster_chances(Game) max_items = from_dungeon_level([[10, 1], [2, 4]], data.maplist.index(Game.dungeon_levelname)) num_items = libtcod.random_get_int(0, 0, max_items) item_chances = get_item_chances(Game) for i in range(num_monsters): #choose random spot for this monster x = libtcod.random_get_int(0, room.x1 + 1, room.x2 - 1) y = libtcod.random_get_int(0, room.y1 + 1, room.y2 - 1) if not entities.is_blocked(x, y, Game): #create a monster choice = random_choice(monster_chances) monster = entities.Object(**entitydata.mobs[choice]) monster.dungeon_level = data.maplist.index(Game.dungeon_levelname) monster.blocks = True monster.ai = entities.Ai( entities.BasicMonster()) #how do I set different ai? monster.ai.owner = monster monster.id = str(monster.dungeon_level) + '.' + str(nextid) monster.name = choice + '(' + str(monster.id) + ')' if data.FREE_FOR_ALL_MODE: monster.fighter.clan = monster.name nextid += 1 monster.fighter.fov = Game.map[Game.dungeon_levelname].fov_map print 'MAPGEN--\t ' + str( Game.tick ) + '\t' + Game.dungeon_levelname + '\t' + ' made a ' + monster.name #give monster items if they have them if entitydata.mobitems[choice]: for itemname in entitydata.mobitems[choice]: item = entities.Object(**entitydata.items[itemname]) monster.fighter.add_item(item) monster.set_location(x, y, Game) Game.objects[Game.dungeon_levelname].append(monster) for i in range(num_items): #choose random spot for this item x = libtcod.random_get_int(0, room.x1 + 1, room.x2 - 1) y = libtcod.random_get_int(0, room.y1 + 1, room.y2 - 1) #only place it if the tile is not blocked if not entities.is_blocked(x, y, Game): #create an item choice = random_choice(item_chances) item = entities.Object(**entitydata.items[choice]) item.always_visible = True item.set_location(x, y, Game) item.dungeon_level = data.maplist.index(Game.dungeon_levelname) Game.objects[Game.dungeon_levelname].append(item) item.send_to_back(Game) #items appear below other objects
def make_map(Game, levelnum, levelname): Game.objects[Game.dungeon_levelname] = [Game.player] #fill map with "blocked" tiles print 'MAPGEN--\t ' + str( Game.tick ) + '\t' + Game.dungeon_levelname + '\t' + ' creating map:' + str( Game.dungeon_levelname) Game.map[Game.dungeon_levelname] = Maplevel(data.MAP_HEIGHT, data.MAP_WIDTH, levelnum, levelname) rooms = [] num_rooms = 0 for r in range(data.MAX_ROOMS): #get random width/height w = libtcod.random_get_int(0, data.ROOM_MIN_SIZE, data.ROOM_MAX_SIZE) h = libtcod.random_get_int(0, data.ROOM_MIN_SIZE, data.ROOM_MAX_SIZE) #get random positions, but stay within map x = libtcod.random_get_int(0, data.MAP_PAD_W, data.MAP_WIDTH - w - data.MAP_PAD_W) y = libtcod.random_get_int(0, data.MAP_PAD_H, data.MAP_HEIGHT - h - data.MAP_PAD_H) new_room = Rect(x, y, w, h) #check for intersection with this room failed = False for other_room in rooms: if new_room.intersect(other_room): failed = True break if not failed: #no intersections Game.map[Game.dungeon_levelname].create_room(new_room) (new_x, new_y) = new_room.center() #add some contents to the room place_objects(new_room, Game) if num_rooms == 0: #first room. start player here Game.player.x = new_x Game.player.y = new_y #create upstairs at the center of the first room Game.upstairs[Game.dungeon_levelname] = entities.Object( new_x, new_y, '<', 'upstairs', libtcod.white, always_visible=True) Game.objects[Game.dungeon_levelname].append( Game.upstairs[Game.dungeon_levelname]) Game.upstairs[Game.dungeon_levelname].send_to_back( Game) #so it's drawn below the monsters else: #for all other rooms, need to connect to previous room with a tunnel #get center coords of previous room (prev_x, prev_y) = rooms[num_rooms - 1].center() #flip coin if flip_coin() == 1: #move h then v Game.map[Game.dungeon_levelname].create_h_tunnel( prev_x, new_x, prev_y) Game.map[Game.dungeon_levelname].create_v_tunnel( prev_y, new_y, new_x) else: #move v then h Game.map[Game.dungeon_levelname].create_v_tunnel( prev_y, new_y, prev_x) Game.map[Game.dungeon_levelname].create_h_tunnel( prev_x, new_x, new_y) #add to rooms list rooms.append(new_room) num_rooms += 1 #create stairs at the center of the last room Game.downstairs[Game.dungeon_levelname] = entities.Object( new_x, new_y, '>', 'downstairs', libtcod.white, always_visible=True) Game.objects[Game.dungeon_levelname].append( Game.downstairs[Game.dungeon_levelname]) Game.downstairs[Game.dungeon_levelname].send_to_back( Game) #so it's drawn below the monsters Game.map[Game.dungeon_levelname].initialize_fov()