def draw(self): '''Draws the object to the background console.''' # ONLY draw objects _if_ they are in view of the player if libtcod.map_is_in_fov(self.map.fov_map, self.x, self.y): libtcod.console_set_foreground_color(self.con, self.color) libtcod.console_put_char(self.con, self.x, self.y, self.char, libtcod.BKGND_NONE)
def draw(self): for row in xrange(len(self.explored)): for col in xrange(len(self.explored[row])): char = '#' if self.blocked[row][col] else ' ' if lt.map_is_in_fov(self.fov, col, row): self.explored[row][col] = True lt.console_put_char_ex(self.con, col, row, char, self.f_color, self.b_color) elif self.explored[row][col]: lt.console_put_char_ex(self.con, col, row, char, self.f_color_explored, self.b_color_explored)
def under_mouse(self): mouse = libtcod.mouse_get_status() (x, y) = (mouse.cx, mouse.cy) names = [obj.name for obj in self.map.object_list if obj.x == x and obj.y == y and libtcod.map_is_in_fov(self.map.fov_map, obj.x, obj.y)] names = ', '.join(names) return names.capitalize()
def take_turn(self): mob = self.owner if libtcod.map_is_in_fov(self.owner.map.fov_map, mob.x, mob.y): # Moves towards the player if mob.distance_to(self.owner.map.player) >= 2: mob.move_towards(self.owner.map.player.x, self.owner.map.player.y) # Mob moving towards player, random growls chance = libtcod.random_get_int(0, 1, 100) if chance <= 20: sfx.play('zombie_a') elif chance <= 40: sfx.play('zombie_b') elif chance <= 60: sfx.play('zombie_c') elif self.owner.map.player.fighter.hp > 0: mob.fighter.attack(self.owner.map.player)
def render_all(self): '''Renders all objects and tiles to the root console.''' global color_light_wall, color_dark_wall global color_light_ground, color_dark_ground if self.map.fov_recompute: self.map.fov_recompute = False libtcod.map_compute_fov(self.map.fov_map, self.map.player.x, self.map.player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): visible = libtcod.map_is_in_fov(self.map.fov_map, x, y) wall = self.map.map[x][y].block_sight if not visible: # Not visible, darken the tiles if self.map.map[x][y].explored: if wall: libtcod.console_set_back(self.con, x, y, color_dark_wall, libtcod.BKGND_SET) else: libtcod.console_set_back(self.con, x, y, color_dark_ground, libtcod.BKGND_SET) else: # It's visible, light up the tiles if wall: libtcod.console_set_back(self.con, x, y, color_light_wall, libtcod.BKGND_SET) else: libtcod.console_set_back(self.con, x, y, color_light_ground, libtcod.BKGND_SET) self.map.map[x][y].explored = True # Draw all objects to the screen for object in self.map.object_list: if object != self.map.player: object.draw() self.map.player.draw() # Blit the offscreen console to the root console and flush libtcod.console_blit(self.con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0) # Display Player Stats libtcod.console_set_background_color(self.panel, libtcod.black) libtcod.console_clear(self.panel) # Print the message log y = 1 for (line, color) in game_msgs: libtcod.console_set_foreground_color(self.panel, color) libtcod.console_print_left(self.panel, MSG_X, y, libtcod.BKGND_NONE, line) y += 1 self.render_bar(1, 1, BAR_WIDTH, 'HP', self.map.player.fighter.hp, self.map.player.fighter.max_hp, libtcod.red, libtcod.darker_red) self.render_bar(1, 3, BAR_WIDTH, 'EXP', self.map.player.fighter.exp, self.map.player.fighter.max_exp, libtcod.dark_yellow, libtcod.darker_yellow) self.render_bar(1, 5, BAR_WIDTH, 'Level', self.map.player.fighter.level, 10, libtcod.blue, libtcod.dark_blue) # Check under mouse libtcod.console_set_foreground_color(self.panel, libtcod.light_grey) libtcod.console_print_left(self.panel, 1, 0, libtcod.BKGND_NONE, self.under_mouse()) libtcod.console_blit(self.panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)