def __init__(self, width, height): self.x1 = 0 self.y1 = 0 self.x2 = width self.y2 = height self.houses = [None] self.theMap = [[ Tile(False) for y in range(self.y2)] for x in range(self.x2)] #TODO: mark tiles for transporting to a new map instead of blocking for y in range (self.y2): self.theMap[self.x1][y].blocked = True self.theMap[self.x2 - 1][y].blocked = True for x in range (self.x2): self.theMap[x][self.y1].blocked = True self.theMap[x][self.y2 - 1].blocked = True #Set up doodads self.doodads =[] #fill with grass for x in range(self.x2): for y in range(self.y2): grassDoodad = doodad.Grass(x, y) self.doodads.append(grassDoodad) #create other doodads otherDoodadsCount = libtcod.random_get_int(0, 0, 130) for i in range(otherDoodadsCount): doodadType = libtcod.random_get_int(0,0,1) if doodadType == 0: #make a tree theDoodad = doodad.Tree(libtcod.random_get_int(0, self.x1, self.x2), libtcod.random_get_int(0, self.y1, self.y2)) elif doodadType == 1: #make a lake theDoodad = doodad.Lake(libtcod.random_get_int(0, self.x1, self.x2), libtcod.random_get_int(0, self.y1, self.y2)) #check doodad for blocked status blocked = False for x in range(theDoodad.tileSize / 2): for y in range(theDoodad.tileSize / 2): if theDoodad.x + x > self.x1 or theDoodad.y + y > self.y1: continue if self.theMap[theDoodad.x + x][theDoodad.y + y].blocked: blocked = True break if blocked: continue else: # block tiles for x in range(theDoodad.tileSize / 2): for y in range(theDoodad.tileSize / 2): if theDoodad.x + x > self.x2 - 1 or theDoodad.y + y > self.y2 - 1: continue self.theMap[theDoodad.x + x][theDoodad.y + y].blocked = theDoodad.blocks self.theMap[theDoodad.x + x][theDoodad.y + y].block_sight = theDoodad.blockSight self.doodads.append(theDoodad) #set up FOV for player self.fovMap = libtcod.map_new(width, height) for y in range(height): for x in range(width): libtcod.map_set_properties(self.fovMap, x, y, not self.theMap[x][y].block_sight, not self.theMap[x][y].blocked)
def create_path(self, gamemap_instance): mymap = gamemap_instance.level #Create the path map self.path_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for x in range(1, MAP_WIDTH): for y in range(1, MAP_HEIGHT): libtcod.map_set_properties(self.path_map, x, y, not mymap[x][y].block_sight, not mymap[x][y].blocked) print 'Builder created self.path_map' self.is_pathmap_created = True # now use the path map to create the path from the explorer's current position to another spot: self.path = libtcod.path_new_using_map(self.path_map) destinationx, destinationy = self.pick_spot_to_work(gamemap_instance) if destinationx is not None: self.work_target = (destinationx, destinationy) print 'Builder chose a work target at ' + str(self.work_target[0]) +', ' + str(self.work_target[1]) + '.' libtcod.path_compute(self.path, self.owner.x, self.owner.y, destinationx, destinationy) #originx, originy = libtcod.path_get_origin(self.path) #destx, desty = libtcod.path_get_destination(self.path) elif destinationx is None: print 'destinationx is None.'
def useStairs(obj): # Handles going up/down stairs and loading the new map. global floor, fovCompute print(obj.tile.stairs) if obj.tile.stairs == "UP": floor += 1 spawn, exit = createMapFromFile() player.move(spawn[0], spawn[1]) else: if floor > 1: floor -= 1 spawn, exit = createMapFromFile() player.move(exit[0], exit[1]) for tile in tiles: libtcod.map_set_properties(fovMap, tile.x, tile.y, tile.tile.isTransparent, tile.tile.isWalkable) fovCompute = True
def open(self): x = self.owner.x y = self.owner.y self.owner.char = '/' self.owner.blocks = False map[x][y].block_sight = False libtcod.map_set_properties(fov_map, x, y, not map[x][y].block_sight, not map[x][y].blocked)
def update_entity_fov(entity_list, a_map, fov_map): """Update fov_map for all entities in entity_list""" for _entity in entity_list: tcod.map_set_properties(fov_map, _entity.x, _entity.y, _entity.is_transparent and a_map.data[_entity.y][_entity.x].is_transparent, _entity.is_walkable and a_map.data[_entity.y][_entity.x].is_walkable) return fov_map
def read_zone(self, zone): """Read the zone and adjust map values accordingly""" self.map = libtcod.map_new(zone.width, zone.height) for y in range(zone.height): for x in range(zone.width): #libtcode requires the opposite values, so invert them! libtcod.map_set_properties(self.map, x, y, not zone[x][y].block_sight, not zone[x][y].blocked)
def update_fov_map(a_map, fov_map): """Updates the fov map with all map information in a_map""" for y in xrange(a_map.height): for x in xrange(a_map.width): tcod.map_set_properties(fov_map, x, y, a_map.data[y][x].is_transparent, a_map.data[y][x].is_walkable) return fov_map
def update_dungeon_map_point(self, x, y): dungeon_level = self.parent.dungeon_level.value terrain = dungeon_level.get_tile_or_unknown((x, y)).get_terrain() dungeon_feature = dungeon_level.get_tile_or_unknown((x, y)).get_dungeon_feature() is_opaque = terrain.has("is_opaque") or (dungeon_feature and dungeon_feature.has("is_opaque")) libtcod.map_set_properties(self.dungeon_map, x, y, 0 if is_opaque else 1, self.parent.mover.can_pass_terrain(terrain))
def gen_map(): global tile_map global explore_map global path_map global base_path gen_colors() tile_map = [[ wall_tile for y in range(MAP_HEIGHT) ] for x in range(MAP_WIDTH) ] explore_map = [[ False for y in range(MAP_HEIGHT) ] for x in range(MAP_WIDTH) ] rooms = [] num_rooms = 0 for r in range(dungeon_level+1): w = random.randint(ROOM_MIN_SIZE, ROOM_MAX_SIZE) h = random.randint(ROOM_MIN_SIZE, ROOM_MAX_SIZE) x = random.randint(1, MAP_WIDTH - w - 2) y = random.randint(1, MAP_HEIGHT - h - 2) new_room = Rect(x, y, w, h) failed = False for other_room in rooms: if new_room.intersect(other_room): failed = True break if not failed: carve_room(new_room) (new_x, new_y) = new_room.center() if num_rooms == 0: player.x = new_x player.y = new_y else: populate(new_room) (prev_x, prev_y) = rooms[num_rooms-1].center() if random.randint(0,1) == 1: carve_h_tunnel(prev_x, new_x, prev_y) carve_v_tunnel(prev_y, new_y, new_x) else: carve_h_tunnel(prev_x, new_x, new_y) carve_v_tunnel(prev_y, new_y, prev_x) rooms.append(new_room) num_rooms += 1 last_room = rooms[num_rooms-1] (stairs_x, stairs_y) = last_room.center() tile_map[stairs_x][stairs_y] = stair_tile path_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): libtcod.map_set_properties(path_map, x, y, not tile_map[x][y].blocks, not tile_map[x][y].blocks_sight) base_path = libtcod.path_new_using_map(path_map)
def generate_land(self): for x in range(self.width): for y in range(self.height): f = [self.noise_zoom * x / self.width, self.noise_zoom * y / self.height] value = libtcod.noise_get_fbm(self.world_noise, f, self.noise_octaves, libtcod.NOISE_PERLIN) #Threshold c = ((value + 1.0) / 2.0) col = libtcod.color_lerp(libtcod.dark_green, libtcod.black, c) self.map_list[x][y].land_type = 'grass' c = int((value + 1.0) / 2.0 * 200) c = c - int(self.dist(x,y))/1.5 #This is a beach if c < 28: col = libtcod.lightest_amber self.map_list[x][y].land_type = 'beach' #This is water if c < 20: coef = self.dist(x,y) / 320 col = libtcod.color_lerp(libtcod.azure, libtcod.darkest_azure * (c/2), coef) if c > 5: self.map_list[x][y].land_type = 'shallow_water' else: self.map_list[x][y].land_type = 'deep_water' libtcod.map_set_properties(self.deepsea_map, x, y, False, True) if self.map_list[x][y].land_type == 'grass' or self.map_list[x][y].land_type == 'beach': libtcod.map_set_properties(self.ground_map, x, y, False, True) self.map_list[x][y].color = col libtcod.image_put_pixel(self.world_img, x, y, self.map_list[x][y].color)
def close(self): x = self.owner.x y = self.owner.y self.owner.char = '+' self.owner.blocks = True map[x][y].block_sight = True libtcod.map_set_properties(fov_map, x, y, not map[x][y].block_sight, not map[x][y].blocked)
def make_fov_map(self): self.fov_recompute = True fov_map = libtcod.map_new(self.width, self.height) for y in range(self.height): for x in range(self.width): libtcod.map_set_properties(fov_map, x, y, not self.map[x][y].block_sight, not self.map[x][y].blocked) return fov_map
def __init__(self): #create new fov_map for area around planted node #add to array of nodes, have render_all cycle through all nodes self.fov_map = libtcod.map_new(config.MAP_WIDTH, config.MAP_HEIGHT) for y in range(config.MAP_HEIGHT): for x in range(config.MAP_WIDTH): libtcod.map_set_properties(self.fov_map, x, y, not config.map[x][y].block_sight, not config.map[x][y].blocked)
def initialize_field_of_view(): global fovMap fovMap = tcod.map_new(data.map_width, data.map_height) for y in range(data.map_height): for x in range(data.map_width): tcod.map_set_properties(fovMap, x, y, not maps.field[x][ y].block_sight, not maps.field[x][y].blocked)
def update_fovmap(): '''Call whenever a tile changes its block_sight status.''' global fov_map for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): libtcod.map_set_properties(fov_map, x, y, not map[x][y].block_sight, not map[x][y].blocked)
def move_astar(self, target): fov = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) #set move, sight blockers for y1 in range(MAP_HEIGHT): for x1 in range(MAP_WIDTH): libtcod.map_set_properties(fov, x1, y1, not map[x1][y1].sight_blocker, not map[x1][y1].move_blocker) #Treat tiles occupied by monsters as move blocked for obj in objects: if obj.move_blocker and obj != self and obj != target: libtcod.map_set_properties(fov, obj.x, obj.y, True, False) #Allocate path. Use roguelike geometry (diagonals = cardinals). my_path = libtcod.path_new_using_map(fov, 1.0) #Compute path libtcod.path_compute(my_path, self.x, self.y, target.x, target.y) #Confirm path was found, and is short, then take step. if not libtcod.path_is_empty(my_path) and libtcod.path_size(my_path) < MAX_ASTAR_PATH_LENGTH: x, y = libtcod.path_walk(my_path, True) if x or y: #self.move takes dx, dy so don't use that self.x = x self.y = y #If the path is bad, take direct path to player. #This happens if, say, player is behind a monster in a corridor. else: self.move_towards(target.x, target.y) #Deallocate path memory libtcod.path_delete(my_path)
def update_fov(self): for x in xrange(self.width): for y in xrange(self.height): tile = self.tile_at(x, y, self.player.z) lbt.map_set_properties(self.fov_map, x, y, not tile.blocks_sight, not tile.blocks)
def init_fov(self): libtcod.map_clear(self.fov_map) #self.fov_map = libtcod.map_new(self.map.width, self.map.height) for x,y,cell in self.map.iter_cells_with_coords(): libtcod.map_set_properties(self.fov_map, x,y, not cell.block_sight, not cell.blocked )
def create_fov(self): self.fov_map = tcod.map_new(engine.dun_level.MAP_W, engine.dun_level.MAP_H) for y in xrange(engine.dun_level.MAP_H): for x in xrange(engine.dun_level.MAP_W): tcod.map_set_properties(self.fov_map, x, y, engine.dun_level.map[x][y].transparent, engine.dun_level.map[x][y].walkable)
def new_fov_pathing_map(map): width = MAP_WIDTH height = MAP_HEIGHT fov_pathing_map = libtcod.map_new(width, height) for y in range(height): for x in range(width): libtcod.map_set_properties(fov_pathing_map, x, y, not map[x][y].block_sight, (not map[x][y].blocked and map[x][y].explored)) return fov_pathing_map
def new_fov_map(game): width = game.map_width height = game.map_height fov_map = libtcod.map_new(width, height) for y in range(height): for x in range(width): libtcod.map_set_properties(fov_map, x, y, not game.map[x][y].block_sight, not game.map[x][y].blocked) return fov_map
def __init__(self): self.lifespan = 50 self.radius = config.FLARE_RADIUS self.fov_map = libtcod.map_new(config.MAP_WIDTH, config.MAP_HEIGHT) for y in range(config.MAP_HEIGHT): for x in range(config.MAP_WIDTH): libtcod.map_set_properties(self.fov_map, x, y, not config.map[x][y].block_sight, not config.map[x][y].blocked)
def init_fov(self): self.fov_map = libtcod.map_new(self.map_width, self.map_height) for y in range(self.map_height): for x in range(self.map_width): libtcod.map_set_properties(self.fov_map, x, y, not self.level_map[x][y].tile_property["blocks_walking"], not self.level_map[x][y].tile_property["blocks_visibility"])
def make_fov_map(self): for x in range(len(self.map)): for y in range(len(self.map[0])): if self.map[x][y] == 0: libtcod.map_set_properties(self.fov_map, x, y, True, True) else: libtcod.map_set_properties(self.fov_map, x, y, False, False)
def initialize_fov(): global fov_recompute, fov_map fov_recompute = True #create the DOV map, according to generated map fov_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): libtcod.map_set_properties(fov_map, x, y, not map[x][y].block_sight, not map[x][y].blocked)
def BuildNavMapEmpty(self): for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): libtcod.map_set_properties(self.navmap,x,y,True,True) del self.currentpath print('Finished creating blank NavMap for ' + self.owner.name) self.currentpath = libtcod.dijkstra_new(self.navmap,DIAGONAL_COST) self.UpdateNavMapLocation()
def initialize_fov(): global fov_recompute, fov_map libtcod.console_clear(con) fov_recompute = True fov_map = libtcod.map_new(opt.MAP_WIDTH, opt.MAP_HEIGHT) for y in range(opt.MAP_HEIGHT): for x in range(opt.MAP_WIDTH): libtcod.map_set_properties(fov_map, x, y, not map[x][y].block_sight, not map[x][y].blocked)
def set_dijkstra_map(self): fov_map = libtcod.map_new(game.WORLDMAP_WIDTH, game.WORLDMAP_HEIGHT) for y in range(game.WORLDMAP_HEIGHT): for x in range(game.WORLDMAP_WIDTH): libtcod.map_set_properties(fov_map, x, y, True, True) path = libtcod.dijkstra_new(fov_map) libtcod.dijkstra_compute(path, self.originx, self.originy) return path
def populate_map(self, world, abs_x_start, abs_y_start): self.x_start = abs_x_start self.y_start = abs_y_start log.info("game width %d", Game.game_width) log.info("game height %d", Game.game_height) for x in range(Game.game_width): for y in range(Game.game_height): is_walkable = not is_obstacle_abs(world, abs_x_start + x, abs_y_start + y) libtcod.map_set_properties(self.fov_map, x, y, True, is_walkable)
def gen_map():#generate map (at this point it's not drawn to the screen) global fov_map, map make_map() #create the FOV map, according to the generated map fov_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): libtcod.map_set_properties(fov_map, x, y, not map[x][y].blocked, not map[x][y].block_sight)
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, tile_data): 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) x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) if randint(0, 1): #Make either a rectangular or circular room new_room = Room(x, y, w, h) else: new_room = Room.make_circle_room(x, y, min(w, h)) for other_room in rooms: if new_room.intersect(other_room): break else: self.place_room(new_room, tile_data) (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: player.x = new_x player.y = new_y else: (prev_x, prev_y) = rooms[num_rooms - 1].center() if randint(0, 1) == 1: self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) self.place_entities(new_room, entities) rooms.append(new_room) num_rooms += 1 stairs_component = Stairs(self.floor + 1) down_stairs = Entity(center_of_last_room_x, center_of_last_room_y, '>', lc.white, 'Stairs', render_order=RenderOrder.STAIRS, stairs=stairs_component) entities.append(down_stairs) #Check to make sure a path exists from the player to the down stairs fov_map = lc.map_new(self.width, self.height) for y in range(0, self.height): for x in range(0, self.width): lc.map_set_properties(fov_map, x, y, True, not self.tiles[x][y].blocked) lc.map_compute_fov(fov_map, 0, 0, 100, True, 0) path = lc.path_new_using_map(fov_map, 1) lc.path_compute(path, player.x, player.y, down_stairs.x, down_stairs.y) if lc.path_is_empty( path): #If no path exists, make a tunnel to the down stairs if randint(0, 1) == 1: self.create_h_tunnel(down_stairs.x, player.x, down_stairs.y) self.create_v_tunnel(down_stairs.y, player.y, player.x) else: self.create_v_tunnel(down_stairs.y, player.y, down_stairs.x) self.create_h_tunnel(down_stairs.x, player.x, player.y)
def _update_fov_map_cell_opacity(self, x,y, value): libtcod.map_set_properties( self.fov_map, x, y, value, True)
def main(): player = Object(1, 1, '@', libtcod.red) libtcod.console_set_custom_font( 'arial12x12.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) # specify screen size, title and whether or not fullscreen for root console libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'maze game', False) # off-screen console for the map con = libtcod.console_new(MAP_WIDTH, MAP_HEIGHT) # off-screen console for display panel panel = libtcod.console_new(SCREEN_WIDTH, PANEL_HEIGHT) # Only for real time, Frames per second libtcod.sys_set_fps(LIMIT_FPS) fov_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) global compute_fov compute_fov = False cells = [[Cell() for y in range(MAP_COLS)] for x in range(MAP_ROWS)] make_map(cells) msgs = [] choice = 0 global move_count move_count = 0 while True: msgs.append(("Which algorithm would you like to generate the maze?", libtcod.white)) msgs.append(("[1]. Kruskal's algorithm", libtcod.white)) msgs.append(("[2]. Prim's algorithm", libtcod.white)) msgs.append(("[3]. Binary tree method", libtcod.white)) msgs.append(("[4]. Random method", libtcod.white)) render_all(player, con, panel, fov_map, True, msgs) libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0) libtcod.console_flush() msgs = [] form_messages = [ ("Maze has been formed by Kruskal's method", libtcod.green), ("Maze has been formed by Prim's method", libtcod.green), ("Maze has been formed by Binary tree method", libtcod.green) ] key = libtcod.console_wait_for_keypress(True) if key.vk == libtcod.KEY_1: choice = 1 if key.vk == libtcod.KEY_2: choice = 2 if key.vk == libtcod.KEY_3: choice = 3 if key.vk == libtcod.KEY_4: choice = random.randint(0, 3) if choice in [1, 2, 3]: print "User's choice for maze generation is " + str(choice) msgs.append(form_messages[choice - 1]) break else: msgs.append(("Sorry that is not an option!", libtcod.red)) msgs.append(("", libtcod.red)) if choice == 1: (edges, cell_set, cell_list, cells) = kruskal.init_variables(MAP_ROWS, MAP_COLS) while cell_set.size() != 1: cells = kruskal.generate_maze(edges, cell_set, cell_list, cells) if choice == 2: (wall_set, cells_finished, cells) = prim.init_variables(MAP_ROWS, MAP_COLS) while len(cells_finished) != MAP_ROWS * MAP_COLS: cells = prim.generate_maze(wall_set, cells_finished, cells, MAP_ROWS, MAP_COLS) if choice == 3: (cells) = bt.init_variables(MAP_ROWS, MAP_COLS) for x in range(MAP_ROWS - 1, -1, -1): for y in range(MAP_COLS): cells = bt.generate_maze(cells, x, y, MAP_ROWS, MAP_COLS) make_map(cells) msgs = in_game_messages(msgs) for y in xrange(MAP_HEIGHT): for x in xrange(MAP_WIDTH): libtcod.map_set_properties(fov_map, x, y, not map[x][y].wall, not map[x][y].wall) render_all(player, con, panel, fov_map, True, msgs) libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0) libtcod.console_flush() global fog_of_war fog_of_war = True while not libtcod.console_is_window_closed(): if player.x == MAP_WIDTH - 2 and player.y == MAP_HEIGHT - 2: msgs = [] msgs.append( ("Congratulations! You have won the game", libtcod.purple)) msgs.append(("", libtcod.white)) msgs.append( ("Displaying player's route in green", libtcod.light_green)) msgs.append(("", libtcod.white)) msgs.append(("Press any key to exit game now", libtcod.white)) render_all(player, con, panel, fov_map, False, msgs) render_travelled(con) libtcod.console_put_char_ex(con, 1, 1, 'S', libtcod.pink, libtcod.black) player.draw(con) libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0) libtcod.console_flush() key = libtcod.console_wait_for_keypress(True) break render_all(player, con, panel, fov_map, fog_of_war, msgs) libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0) libtcod.console_flush() player.erase(con) quit = keyboard_input(player, con) if quit: quit_msgs = [] quit_msgs.append(("Are you sure you want to quit?", libtcod.red)) quit_msgs.append(("", libtcod.red)) quit_msgs.append(("Enter Esc again to display solution and exit", libtcod.white)) quit_msgs.append(("Enter any other key otherwise", libtcod.white)) render_all(player, con, panel, fov_map, True, quit_msgs) libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0) libtcod.console_flush() key = libtcod.console_wait_for_keypress(True) if key.vk == libtcod.KEY_ESCAPE: quit_msgs = [] quit_msgs.append(("Displaying solution in blue", libtcod.sky)) quit_msgs.append(("", libtcod.green)) quit_msgs.append(( "Displaying player's route (not overlapping with solution) in green", libtcod.light_green)) quit_msgs.append(("", libtcod.green)) quit_msgs.append( ("Press any key to exit game now", libtcod.white)) render_all(player, con, panel, fov_map, False, quit_msgs) render_travelled(con) render_solution(cells, con) player.draw(con) libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0) libtcod.console_flush() key = libtcod.console_wait_for_keypress(True) break
libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/libtcod tutorial', False) con = libtcod.console_new(MAP_WIDTH, MAP_HEIGHT) libtcod.sys_set_fps(LIMIT_FPS) #the coords here are the player starting location fighter_component = Fighter(hp=30, defense=2, power=5, death_function=player_death) player = Object(0, 0, '@', 'Seth', libtcod.white, blocks=True, fighter=fighter_component) npc = Object(SCREEN_WIDTH/2-5, SCREEN_HEIGHT/2, '&', 'Chuckes', libtcod.red, blocks=True) objects = [player, npc] #generate starting map make_map() fov_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): libtcod.map_set_properties(fov_map, x, y, not map[x][y].block_sight, not map[x][y].blocked) fov_recompute = False panel = libtcod.console_new(SCREEN_WIDTH, PANEL_HEIGHT) inventory = [] game_msgs = [] message("Welcome stranger! Prepare to perish in the Tombs of the Ancient Kings.", libtcod.red) mouse = libtcod.Mouse() key = libtcod.Key() ####################################################### # The Main Loop! #######################################################
def changeFOVMap(x, y): libtcod.map_set_properties(FOVMap, x, y, not getMap()[x][y].BlockSight, not getMap()[x][y].BlockMove)
def init_fov(): global fov_map, map fov_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): libtcod.map_set_properties(fov_map, x, y, not map[x][y].block_sight, not map[x][y].blocked)
def add_walkable_tile(self, pos): x, y, z = pos tcod.map_set_properties(self.path_map[z], x, y, False, True)
def update_tile_walkability(self, pos): x, y, z = pos tcod.map_set_properties(self.path_map[z], x, y, False, self[pos].is_walkable())
player = Object(0, 0, '@', 'Player', libtcod.white, blocks=True, fighter=player_fighter) objects = [player] inventory = [] make_map() fov_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): libtcod.map_set_properties( fov_map, x, y, not gameMap[offset(x, y, MAP_WIDTH)].block_sight, not gameMap[offset(x, y, MAP_WIDTH)].blocked) fov_recompute = True mouse = libtcod.Mouse() key = libtcod.Key() game_state = GameStates.PLAYING player_action = PlayerActions.NONE message( 'Welcome stranger! Prepare to perish in the Tombs of the Ancient Kings.', libtcod.red) while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE,
def set_path_map(self, x, y, path): libtcod.map_set_properties(self.path_map, x, y, True, path)
def calculateFOVMap(): for y in range(MapHeight): for x in range(MapWidth): libtcod.map_set_properties(FOVMap, x, y, not getMap()[x][y].BlockSight, not getMap()[x][y].BlockMove)
def construct_fov(self): for y in range(self.height): for x in range(self.width): T.map_set_properties(self.fov_map, x, y, not self.map[y][x].blocked, self.map[y][x].walkable)