def init_mechanics(): global player global objects global fov_recompute global fov_map global ambient_recompute global game_state global frame_counter global next_random_frame objects = [player] #generate map (at this point it's not drawn to the screen) 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) fov_recompute = True ambient_recompute = True game_state = 'playing' player_action = None frame_counter = 0 next_random_frame = random_frame()
def setup(self): self.__generate_rooms() self.__fov_map = libtcod.map_new(self.__width, self.__height) for y in range(self.__height): for x in range(self.__width): tile = self.__map[y][x] libtcod.map_set_properties(self.__fov_map, x, y, not tile.blocks_sight, not tile.blocked)
def init_fov_map(self): self.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(self.fov_map, x, y, not self[x][y].block_sight, not self[x][y].blocked) self.fov_x = None self.fov_y = None
def initialize_fov(): global fov_recompute, fov_map libtcod.console_clear(con) #reset console to black fov_recompute = True #create the FOV 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 initialize_fov(): global fov_recompute, fov_map fov_recompute = True # 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].block_sight, not map[x][y].blocked) # unexplored areas start black (which is the default background color) libtcod.console_clear(con)
def generate_map(maps_avail): """ Generate a level map, plant trees and objects and NPC's. """ game_map = blank_map() map_from_ascii(game_map, maps_avail) flip_map(game_map) plant_foliage(game_map) build_fence(game_map) fov_map = libtcod.map_new(C.MAP_WIDTH, C.MAP_HEIGHT) for y in range(C.MAP_HEIGHT - 1): for x in range(C.MAP_WIDTH - 1): libtcod.map_set_properties(fov_map, x, y ,game_map[x][y].seethrough ,not game_map[x][y].blocking and \ not game_map[x][y].drinkable) path_map = libtcod.path_new_using_map(fov_map) return game_map, fov_map, path_map
map_gen = BSPGenerator(random) map = map_gen.generate_map(MAP_WIDTH, MAP_HEIGHT, 1) map_gen.run(map) world = Level(MAP_WIDTH, MAP_HEIGHT, con) tiler = TileGenerator() tiler.run(world, map) player = Entity(27, 22, "@", libtcod.white, con, world) npc = Entity(56, 27, "J", libtcod.yellow, con, world) objects = [npc, player] 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 world[x][y].block_sight, not world[x][y].blocked) fov_recompute = True while not libtcod.console_is_window_closed(): libtcod.console_set_default_foreground(0, libtcod.white) if fov_recompute: fov_recompute = False libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO) render_all(fov_map) libtcod.console_flush() for object in objects: