def render_units(self, tiles, map_id, cam_x, cam_y, x0, x1, y0, y1): units = [ (eid, health, position, render, info) for eid, (health, position, render, info) in join(self.engine.healths, self.engine.positions, self.engine.renders, self.engine.infos) if position.map_id == self.engine.world.id and (position.x, position.y) in tiles and x0 <= position.x < x1 and y0 <= position.y < y1 ] # look for all positions not in tile positions and visibilities. # if their positions match and map is visible then show the unit enemy_count = 0 for eid, health, position, render, info in units: # current_map_id = position.map_id == map_id visibility = tiles[(position.x, position.y)] # inbounds = x0 <= position.x < x1 and y0 <= position.y < y1 # if visibility and inbounds: if visibility.level == 2: color = colors.get(info.name, 0) else: color = 0 self.render_char(self.map_x + position.x - cam_x, self.map_y + position.y - cam_y, render.char, curses.color_pair(color)) # check if enemy needs to added to the panel non_player = eid != self.engine.player.id description_space = enemy_count < self.enemy_panel_height - 1 if non_player: enemy_count += int( self.render_enemy_panel_detail(enemy_count, render, info, health)) else: self.render_player_panel_details(render, info, health)
def render_items(self, tiles, map_id, cam_x, cam_y, x0, x1, y0, y1): items = join(self.engine.items, self.engine.positions, self.engine.renders, self.engine.infos) item_positions = set() for _, (_, position, render, info) in items: current_map = position.map_id == self.engine.world.id visibility = tiles.get((position.x, position.y), None) inbounds = x0 <= position.x < x1 and y0 <= position.y < y1 if current_map and visibility and inbounds: color = colors.get(info.name, 0) self.render_char(self.map_x + position.x - cam_x, self.map_y + position.y - cam_y, render.char, curses.color_pair(color))
def render_enemy_panel_detail(self, enemy_count, render, info, health) -> bool: if enemy_count < self.enemy_panel_height - 1: # enemy character eg. goblin => <green>g</green> self.render_char(self.enemy_item_x + 1, self.enemy_item_y + enemy_count, render.char, curses.color_pair(colors.get(info.name, 240))) # enemy character current health self.render_string(self.enemy_item_x + 4, self.enemy_item_y + enemy_count, str(health.cur_hp), curses.color_pair(197)) # enemy character maximum health self.render_string(self.enemy_item_x + len(str(health.cur_hp)) + 5, self.enemy_item_y + enemy_count, f"/ {health.max_hp}", curses.color_pair(125)) return True return False
def render_map(self, map_id, cam_x, cam_y, x0, x1, y0, y1): border(self.terminal, self.map_panel_x, self.map_panel_y, self.map_panel_width, self.map_panel_height) tiles = join(self.engine.visibilities, self.engine.positions, self.engine.renders, self.engine.infos) for _, (visibility, position, render, info) in tiles: current_map_id = position.map_id == map_id visible = visibility.level > 0 xbounds = x0 <= position.x < x1 ybounds = y0 <= position.y < y1 inbounds = xbounds and ybounds if current_map_id and visible and inbounds: if visibility.level == 2: color = colors.get(info.name, 240) else: color = 240 self.render_char(position.x + self.map_x - cam_x, position.y + self.map_y - cam_y, render.char, curses.color_pair(color))
def render_effects(self, tiles, map_id, cam_x, cam_y, x0, x1, y0, y1): # eid, effect = self.engine.effects. for eid, effect in self.engine.effects.components.items(): position = self.engine.positions.find(eid=effect.entity_id) render = self.engine.renders.find(eid=effect.entity_id) info = self.engine.infos.find(eid=effect.entity_id) visibility = tiles.get((position.x, position.y), None) inbounds = x0 <= position.x < x1 and y0 <= position.y < y1 # only shows if inside the view area and space is lighted if visibility and inbounds: self.render_char(self.map_x + position.x - cam_x, self.map_y + position.y - cam_y, effect.char) self.terminal.noutrefresh() curses.doupdate() time.sleep(.085) self.render_char(self.map_x + position.x - cam_x, self.map_y + position.y - cam_y, render.char, curses.color_pair(colors.get(info.name, 0))) self.terminal.noutrefresh() curses.doupdate()