def compute_fov(self): for x in range (M.MAP_WIDTH): for y in range (M.MAP_HEIGHT): if M.gameworld[x][y].is_floor(): libtcod.map_set_properties (self.fov, x , y, True, True) libtcod.map_compute_fov (self.fov, self.x, self.y, self.view_distance, True,libtcod.FOV_DIAMOND)
def draw (self): # Light map libtcod.map_compute_fov( self.map.fov, self.player.x, self.player.y, self.options['fov_torch_radius'], self.options['fov_light_walls'], 1) # Draw the map self.map.draw()
def display(self, con): if self.game.fov_recompute: #recompute FOV if needed (the player moved or something) self.game.fov_recompute = False libtcod.map_compute_fov(self.map.fov_map, self.game.player.x, self.game.player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO) for y in range(self.height): for x in range(self.width): map_x, map_y = x + self.x_offset, y + self.y_offset if self.map.in_bounds(map_x, map_y): visible = libtcod.map_is_in_fov(self.map.fov_map, map_x, map_y) tt = self.map.tiles[map_x][map_y].type if visible: libtcod.console_set_char_background(con, x, y, tt.bg_color_lit, libtcod.BKGND_SET) libtcod.console_set_default_foreground(con, tt.fg_color_lit) libtcod.console_put_char(con, x, y, tt.char, libtcod.BKGND_NONE) # TODO: Doing this here bugs it if the player's light radius is not on screen self.map.tiles[map_x][map_y].explored = True elif self.map.tiles[map_x][map_y].explored: libtcod.console_set_char_background(con, x, y, tt.bg_color, libtcod.BKGND_SET) libtcod.console_set_default_foreground(con, tt.fg_color) libtcod.console_put_char(con, x, y, tt.char, libtcod.BKGND_NONE) else: libtcod.console_set_char_background(con, x, y, void_color, libtcod.BKGND_SET) libtcod.console_put_char(con, x, y, ' ', libtcod.BKGND_NONE) else: libtcod.console_set_char_background(con, x, y, void_color, libtcod.BKGND_SET) libtcod.console_put_char(con, x, y, ' ', libtcod.BKGND_NONE) for object in self.map.objects: object.draw(con, self.x_offset, self.y_offset) libtcod.console_blit(con, 0, 0, self.width, self.height, 0, 0, 0) libtcod.console_flush()
def fire(self, x, y, dx, dy): # The distance this bullet has traveled. steps = 0 shot_accuracy=self.accuracy libtcod.map_compute_fov (P.player.fov, x, y, int(P.player.view_distance*1.5), True,libtcod.FOV_SHADOW) R.render() libtcod.line_init(x, y, dx, dy) lx,ly=libtcod.line_step() while (not lx is None): steps = steps + 1 if not M.gameworld[lx][ly].characters: libtcod.console_set_char_background( cons.game_console, lx, ly, libtcod.white, libtcod.BKGND_OVERLAY) libtcod.console_blit(cons.game_console,0,0,M.MAP_WIDTH,M.MAP_HEIGHT,0,0,0,1) libtcod.console_flush() lx,ly=libtcod.line_step() else: if random.random() <= shot_accuracy: S.add_status("You hit!") libtcod.console_set_char_background( cons.game_console, lx, ly, libtcod.red, libtcod.BKGND_OVERLAY) libtcod.console_blit(cons.game_console,0,0,M.MAP_WIDTH,M.MAP_HEIGHT,0,0,0,1) libtcod.console_flush() M.gameworld[lx][ly].characters[-1].take_damage( int(self.damage*random.uniform(self.accuracy, 1.0))) else: S.add_status("You fire and miss!") break self.ammo = self.ammo-1 self.owner.name = self.owner.name.rsplit('(')[0] + '(' + str(self.ammo) + ')' P.player.compute_fov()
def compute_fov(self, x, y): libtcod.map_compute_fov(self.fov, x, y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO)
def recompute_fov(self, radius, light_walls=True, fov_algo=0): ltc.map_compute_fov(self.fov_map, self.player.x, self.player.y, radius, light_walls, fov_algo)
def compute_fov_map(self): """Recompute FOV map for player.""" tcod.map_compute_fov(self.fov_map, self.x, self.y, radius=15, light_walls=True, algo=tcod.FOV_BASIC)