Example #1
0
 def flash(self,
           color,
           player,
           entities,
           level_map,
           colors=True,
           cursor=None,
           line=False,
           delay=2):
     self.flash_console = Console(self.root_console.width,
                                  self.root_console.height, 'F')
     delta = timedelta(seconds=delay)
     start = datetime.now()
     diff = timedelta(seconds=0)
     while diff < delta:
         self.flash_alpha = 1 - ((
             (diff.seconds * 1000000) + diff.microseconds) /
                                 (delay * 1000000))
         self.flash_console.draw_rect(0, 0, self.flash_console.width,
                                      self.flash_console.height, ord(' '),
                                      color, color)
         diff = datetime.now() - start
         self.render_level(player,
                           entities,
                           level_map,
                           colors=colors,
                           cursor=cursor,
                           line=line)
     self.flash_console = None
     self.flash_alpha = 1
Example #2
0
    def render(self, console: Console, context: Context) -> None:
        #render the map first
        self.game_map.render(console)

        context.present(console)

        console.clear()
Example #3
0
    def render(self, console: Console) -> None:
        """
        Визуализирует карту. 
 
        Если плитка в зоне видимости, то она отрисовывается в светлых цветах.  
        Если нет, но она была ранее исследована, тогда отрисовывается темными цветами.
        Во всех других случаях используется SHROUD (по дефолту) (черные плитки).
        """
        console.tiles_rgb[0:self.width, 0:self.height] = np.select(
            # np.select позволяет отрисовывать плитки, которые мы хотим, опираясь на то, что указано в condlist
            condlist=[self.visible, self.explored],
            choicelist=[self.tiles["light"], self.tiles["dark"]],
            default=tile_types.SHROUD,
        )

        entities_sorted_for_rendering = sorted(
            self.entities, key=lambda x: x.render_order.value)

        for entity in entities_sorted_for_rendering:
            # печатает только те объекты, которые находятся в FOV
            if self.visible[entity.x, entity.y]:
                console.print(x=entity.x,
                              y=entity.y,
                              string=entity.char,
                              fg=entity.color)
Example #4
0
    def render(self, console: Console) -> None:
        ''' 
        Sets tiles and entities to the map. 
            - If the tile is in the "visible" array, draw it with the 'light' color.
            - If it isn't, but it's been 'explored', draw it with the 'dark' color.
            - If tile is unexplored, default to "SHROUD".
        Tiles are sorted into Lists:
            - 'condlist': Tiles can be both visible AND explored, so they make up a parent list of conditional states.
            - 'choicelist': Tiles in either of the two color states (sorted depending on FOV calculations).
            - 'default': Any tiles not in the above lists are effectively unexplored. They will render as 'SHROUD' 
        '''
        console.tiles_rgb[0:self.width, 0:self.height] = np.select(
            # Lists to determine tile appearance
            condlist=[self.visible, self.explored],
            choicelist=[self.tiles["light"], self.tiles["dark"]],
            default=tile_types.SHROUD)

        # Determine in what order to render entities:
        entities_sorted_for_rendering = sorted(
            self.entities,  # The Set of entities to sort
            key=lambda x: x.render_order.
            value  # A custom key for sorting by (using 'render_order' module)
        )

        # Iterate through entities and add one to the console if it exists in a 'visible' area of the map.
        for entities in entities_sorted_for_rendering:
            if self.visible[entity.x, entity.y]:
                console.print(x=entity.x,
                              y=entity.y,
                              string=entity.char,
                              fg=entity.color)
Example #5
0
    def render_main(self, console: Console, player: int, x: int, y: int,
                    width: int, height: int) -> None:
        if not self.world.has_component(player, Player):
            return
        player_position = self.world.component_for_entity(player, Position)

        mid_x = x + width // 2
        mid_y = x + height // 2
        for e, (entity_position, entity_renderable,
                entity_selectable) in self.world.get_components(
                    Position, Renderable, Selectable):
            diff_x = entity_position.x - player_position.x
            diff_y = entity_position.y - player_position.y
            pos_x = mid_x + diff_x
            pos_y = mid_y + diff_y

            background_color = colors.BACKGROUND_CLEAR

            if entity_selectable.selected_main:
                background_color = colors.BACKGROUND_SELECTED_MAIN

            if pos_x >= x and pos_y >= y and pos_x <= x + width and pos_y <= y + height:
                console.print(mid_x + diff_x, mid_y + diff_y,
                              entity_renderable.char, entity_renderable.color,
                              background_color)
Example #6
0
    def render(self, console: tConsole, x: int, y: int, width: int,
               height: int) -> None:
        console.print(x, y, f"NAV TARGET: {self._get_nav_target_name()}")

        text.with_highlighting(console, x, y + 2, "[F]OLLOW")
        console.print(x + 9, y + 2, self._get_highlighted_name())
        text.with_highlighting(console, x, y + 3, "[S]TOP")
Example #7
0
    def render(self, console: Console, context: Context) -> None:
        self.game_map.render(console)

        render_menu(console=console,
                    map_height=self.game_map.height,
                    menu_width=100)

        self.message_log.render(console=console)

        # If the current event handler is the Inventory handler, show the inventory screen.
        if isinstance(self.event_handler, InventoryEventHandler):
            render_inventory_menu(console=console, engine=self)

        render_bar(console=console,
                   character=self.player,
                   current_value=self.player.fighter.hp,
                   maximum_value=self.player.fighter.max_hp,
                   total_width=20)

        render_names_at_mouse_location(console=console,
                                       x=21,
                                       y=44,
                                       engine=self)

        context.present(console)

        console.clear()
Example #8
0
    def render(self, console: Console) -> None:
        """
        Renders the map.

        tiles in the 'visible' array are drawn with 'light' colors.
        nonvisible but explored tiles are drawn with the 'dark colors'
        otherwise default to SHROUD.
        """
        # console.tiles_rgb[0:self.width, 0:self.height] = self.tiles["dark"]
        console.tiles_rgb[0:self.width, 0:self.height] = np.select(
            condlist=[self.visible, self.explored],
            choicelist=[self.tiles["light"], self.tiles["dark"]],
            default=tile_types.SHROUD,
        )

        entities_sorted = sorted(self.entities,
                                 key=lambda x: x.render_order.value)

        for entity in entities_sorted:
            # Only print entities in current Field of View
            if self.visible[entity.x, entity.y]:
                console.print(x=entity.x,
                              y=entity.y,
                              string=entity.char,
                              fg=entity.color)
Example #9
0
    def __mockup_render(self, console: tConsole) -> None:
        values = self.world.component_for_entity(self.player_ship,
                                                 Destructable)

        console.print(SCREEN_WIDTH - SIDEBAR_WIDTH + 1,
                      SCREEN_HEIGHT - STATUS_HEIGHT,
                      "CORE",
                      fg=(235, 164, 52))
        primitives.bar(console, SCREEN_WIDTH - SIDEBAR_WIDTH + 6,
                       SCREEN_HEIGHT - STATUS_HEIGHT, 28,
                       values.core_percentage, (235, 164, 52))

        console.print(SCREEN_WIDTH - SIDEBAR_WIDTH + 1,
                      SCREEN_HEIGHT - STATUS_HEIGHT + 1,
                      "HULL",
                      fg=(168, 168, 168))
        primitives.bar(console, SCREEN_WIDTH - SIDEBAR_WIDTH + 6,
                       SCREEN_HEIGHT - STATUS_HEIGHT + 1, 28,
                       values.hull_percentage, (168, 168, 168))

        console.print(SCREEN_WIDTH - SIDEBAR_WIDTH + 1,
                      SCREEN_HEIGHT - STATUS_HEIGHT + 2,
                      "SHLD",
                      fg=(109, 182, 214))
        primitives.bar(console, SCREEN_WIDTH - SIDEBAR_WIDTH + 6,
                       SCREEN_HEIGHT - STATUS_HEIGHT + 2, 28,
                       values.shield_percentage, (109, 182, 214))

        console.print(0,
                      SCREEN_HEIGHT - 1,
                      "[F1] MAIN",
                      fg=colors.TEXT_HIGHLIGHT)
        console.print(10, SCREEN_HEIGHT - 1, "[F2] COMM")
        console.print(20, SCREEN_HEIGHT - 1, "[F3] MODS")
Example #10
0
    def render(self, console: Console, context: Context) -> None:
        for entity in self.entities:
            console.print(entity.x, entity.y, entity.char, fg=entity.color)

        context.present(console)

        console.clear()
    def render_center(self, console: Console, player_pos: Tuple[int,
                                                                int]) -> None:
        """Render functions which follows the player.

        The player will always be at the center, except at the edges of the map.

        x_pos and y_pos is used to adjust for printing entities on console.

        args:
        player_pos = player position on the game map (x, y)
        """
        x, y = player_pos
        left_render = right_render = top_render = bottom_render = 0
        HALF_WIDTH = int(CONSOLE_WIDTH / 2)
        HALF_HEIGHT = int(CONSOLE_HEIGHT / 2)

        x_pos = 0
        y_pos = 0

        if 0 <= x <= HALF_WIDTH:
            # If the player is at the left-most wall
            left_render = 0
            right_render = CONSOLE_WIDTH
        elif (self.width - HALF_WIDTH) <= x <= self.width:
            # If the player is at the right-most wall
            left_render = self.width - CONSOLE_WIDTH
            right_render = self.width
            x_pos = self.width - CONSOLE_WIDTH
        else:
            # If the player is in between values above
            left_render = x - HALF_WIDTH
            right_render = x + HALF_WIDTH
            x_pos = x - HALF_WIDTH

        if 0 <= y <= HALF_HEIGHT:
            # If the player is at the top wall
            top_render = 0
            bottom_render = CONSOLE_HEIGHT
        elif (self.height - HALF_HEIGHT) <= y <= self.height:
            # If the player is at the bottom wall
            top_render = self.height - CONSOLE_HEIGHT
            bottom_render = self.height
            y_pos = self.height - CONSOLE_HEIGHT
        else:
            # If the player is in between the values above
            top_render = y - HALF_HEIGHT
            bottom_render = y + HALF_HEIGHT
            y_pos = y - HALF_HEIGHT

        console.tiles_rgb[0:self.width, 0:self.height] = self.tiles['light'][
            left_render:right_render, top_render:bottom_render]

        entities_sorted = sorted(self.entities,
                                 key=lambda _x: _x.render_order.value)
        for entity in entities_sorted:
            console.print(x=entity.x - x_pos,
                          y=entity.y - y_pos,
                          string=entity.char,
                          fg=(255, 0, 0))
Example #12
0
def bar(console: Console, x: int, y: int, width: int, fill: float,
        color: Tuple[int, int, int]) -> None:
    for cx in range(x, x + width):
        percentage = (cx - x) / width
        if percentage <= fill:
            console.print(cx, y, "█", fg=color)
        else:
            console.print(cx, y, "▒", fg=color)
Example #13
0
 def __init__(self, object, part, width, height, x, y):
     self.object = object
     self.part = part
     self.width = width
     self.height = height
     self.console = Console(width, height)
     self.selected_index = 0
     self.x = x
     self.y = y
Example #14
0
    def render(self, console: Console, context: Context):
        self.game_map.render(console)

        for entity in self.entities:
            if self.game_map.visible[entity.x, entity.y]:
                console.print(entity.x, entity.y, entity.char, fg=entity.color)

        context.present(console)
        console.clear()
    def render(self, console: Console) -> None:
        console.tiles_rgb[0:self.width, 0:self.height] = self.tiles['light']

        entities_sorted = sorted(self.entities,
                                 key=lambda x: x.render_order.value)
        for entity in entities_sorted:
            console.print(x=entity.x,
                          y=entity.y,
                          string=entity.char,
                          fg=entity.color)
Example #16
0
    def render(self, console: Console) -> None:
        console.tiles_rgb[0:self.width, 0:self.height] = np.select(
            condlist=[self.visible, self.explored],
            choicelist=[self.tiles["light"], self.tiles["dark"]],
            default=tile_types.SHROUD
        )

        for entity in self.entities:
            if self.visible[entity.x, entity.y]:
                console.print(x= entity.x, y=entity.y, string=entity.char, fg=entity.color)
Example #17
0
    def render(self, console: Console, context: Context) -> None:
        self.game_map.render(console)
        for entity in self.entities:
            # Only print entities that are in the FOV
            if self.game_map.visible[entity.x, entity.y]:
                console.print(entity.x, entity.y, entity.char, fg=entity.color)

        context.present(console)

        console.clear()
Example #18
0
    def render(self, console: Console, context: Context) -> None:
        """Method for rendering objects in TCOD terminal"""
        self.g_map.render(console)

        console.print(x=1, y=47,
                        string=f"HP: {self.player.stats.hp}/{self.player.stats.max_hp}")

        context.present(console)

        console.clear()
Example #19
0
    def render(self, console: Console, viewport_width: int,
               viewport_height: int) -> None:
        """
        Renders the map

        If a tile is visible, draw w/ light colors
        If it isn't but is explored, draw w/ dark colors
        Otherwise, draw as SHROUD
        """
        self.adjust_viewport_anchor(self.engine.player.x, self.engine.player.y,
                                    viewport_width, viewport_height)

        # bounds of the viewport in map-space, clamped to the map bounds
        x_start = max(self.viewport_anchor_x, 0)
        x_end = min(self.viewport_anchor_x + viewport_width, self.width)
        y_start = max(self.viewport_anchor_y, 0)
        y_end = min(self.viewport_anchor_y + viewport_height, self.height)

        # init a new viewport buffer on the assumption that everything's off the map
        new_tiles = np.full((viewport_width, viewport_height),
                            fill_value=tile_types.EXTERNAL,
                            order="F")

        # blit the map rectangle onto the new viewport buffer
        new_tiles[x_start - self.viewport_anchor_x:x_end -
                  self.viewport_anchor_x,
                  y_start - self.viewport_anchor_y:y_end -
                  self.viewport_anchor_y, ] = np.select(
                      condlist=[
                          self.visible[x_start:x_end, y_start:y_end],
                          self.explored[x_start:x_end, y_start:y_end],
                      ],
                      choicelist=[
                          self.tiles[x_start:x_end, y_start:y_end]["light"],
                          self.tiles[x_start:x_end, y_start:y_end]["dark"],
                      ],
                      default=tile_types.SHROUD,
                  )

        console.tiles_rgb[0:viewport_width, 0:viewport_height] = new_tiles

        sorted_entities = sorted(self.entities,
                                 key=lambda x: x.render_order.value)

        for entity in sorted_entities:
            # only draw visible entities in the viewport
            if (self.visible[entity.x, entity.y]
                    and x_start <= entity.x < x_end
                    and y_start <= entity.y < y_end):
                console.print(
                    entity.x - self.viewport_anchor_x,
                    entity.y - self.viewport_anchor_y,
                    entity.char,
                    fg=entity.color,
                )
Example #20
0
    def render_map(self, console: Console) -> None:

        # The tiles_rgb function from tcod quickly renders the whole map using the assigned tiles
        # In other words it takes the widght and height we used when initializing the map. It then renders everything much more
        # efficiently than the console.print function.
        console.tiles_rgb[0:self.width, 0:self.height] = self.tiles["dark"]

        for entity in self.entities:
            console.print(
                entity.x, entity.y, entity.charTile, fg=entity.color
            )  # The print function is not as efficient as tiles_rgb, but can be used to render entities.
Example #21
0
    def render(self, console: Console, context: Context) -> None:
        """The render function renders the tcod console and tcod context for us.
        by doing this it can display all the entities and respond to actions for us.
        The rendering function is run each game loop to update what is displayed to the user
        """
        # Shall call the game renderer object to render the different elements of the game, including the game map, the entities and the console.
        
        self.game_map.render_map(console)

        context.present(console)
        console.clear()
Example #22
0
    def render(self, console: Console, context: Context) -> None:
        self.game_map.render(console)

        console.print(
            x=1,
            y=47,
            string=f"HP: {self.player.fighter.hp}/{self.player.fighter.max_hp}",
        )

        context.present(console)

        console.clear()
Example #23
0
 def __init__(self,
              root_console: Console,
              ui_manager: UIManager,
              debug=False):
     self.debug = debug
     self.root_console = root_console
     self.flash_console = None
     self.flash_alpha = 1
     self.width = self.root_console.width
     self.height = self.root_console.height
     self.map_dest_coords = (0, 1)
     self.ui_manager = ui_manager
     self.vision_console = Console(60, 60, 'F')
Example #24
0
    def render(self, console: Console, context: Context) -> None:
        self.game_map.progress_redraw_all_transition()
        self.game_map.render(console, self.time_of_day)

        for entity in self.intelligent_entities:
            if self.game_map.tiles[entity.y][
                    entity.x].explored or not self.settings["show-fog"]:
                if entity.name in maps.entity_overview_map:
                    if not self.settings["entity-visibility"][
                            maps.entity_overview_map[entity.name]]:
                        continue

                if (isinstance(entity, rbt.Rabbit) and entity.asleep):
                    continue

                console.print(entity.x,
                              entity.y,
                              entity.char,
                              fg=entity.color,
                              bg=entity.bg_color)

        if self.selected_entity != None:
            entity = self.selected_entity

            if not isinstance(entity, rbt.Burrow) and not isinstance(
                    entity, bb.BerryBush) and not isinstance(entity, cp.Camp):
                render_selected = True

                if entity.name in maps.entity_overview_map:
                    render_selected = self.settings["entity-visibility"][
                        maps.entity_overview_map[entity.name]]

                if render_selected:
                    console.print(entity.x,
                                  entity.y,
                                  entity.char,
                                  fg=entity.color,
                                  bg=entity.bg_color)

        if self.settings["show-ui"]:
            self.stats_panel.render(console)
            self.hover_panel.render(console)
            self.selection_panel.render(console)
            self.action_log_panel.render(console)
            self.game_menu_panel.render(console)
            self.controls_panel.render(console)

            if self.settings["show-entity-overview"]:
                self.entity_overview_panel.render(console)

        context.present(console)
Example #25
0
    def render(self, console: tConsole, context: Context) -> None:
        self.__mockup_render(console)
        self.screen.render_main(console, self.player_ship, 1, 1,
                                SCREEN_WIDTH - SIDEBAR_WIDTH - 1,
                                SCREEN_HEIGHT - CONSOLE_HEIGHT - 2)
        self.sidebar.render(console, SCREEN_WIDTH - SIDEBAR_WIDTH + 1, 1,
                            SIDEBAR_WIDTH - 2, SCREEN_HEIGHT - 8)
        self.console.render(console, 1, SCREEN_HEIGHT - CONSOLE_HEIGHT,
                            CONSOLE_HEIGHT - 2,
                            SCREEN_WIDTH - SIDEBAR_WIDTH - 1)
        self.render_frames(console)

        context.present(console)
        console.clear()
Example #26
0
    def render(self, console: Console, context: Context) -> None:
        ''' 
        GameMap instance renders independently using its own .render() method. 
        Then 'tcod.context' displays the console to the screen. 
        '''
        self.game_map.render(console)

        console.print(
            x=1,
            y=47,
            string=
            f"HP: {self.player.fighter.hp} / {self.player.fighter.max_hp}")

        context.present(console)
        console.clear()
Example #27
0
 def render(self, console: Console, use_fov: bool = True) -> None:
     """Render everything visible or memorized to the console."""
     if use_fov:
         console.tiles_rgb[0:self.width, 0:self.height] = np.select(
             [self.visible, self.explored],
             [self.tiles["light"], self.tiles["dark"]],
             default=tile_types.FOG,
         )
     else:
         console.tiles_rgb[0:self.width,
                           0:self.height] = self.tiles["light"]
     for e in self.entities:
         # Only show entities in the player's field of view
         if not use_fov or self.visible[e.x, e.y]:
             console.print(e.x, e.y, e.char, fg=e.color)
Example #28
0
    def render(self, console: Console) -> None:
        console.tiles_rgb[0:self.width, 0:self.height] = np.select(
            condlist=[self.visible, self.explored],
            choicelist=[self.tiles["color_light"], self.tiles["color_dark"]],
            default=tile_type.fog_of_war,
        )

        entities_sorted = sorted(self.entities, key=lambda x: x.r_order.value)

        for entity in entities_sorted:
            if self.visible[entity.x, entity.y]:
                console.print(x=entity.x,
                              y=entity.y,
                              string=entity.char,
                              fg=entity.color)
Example #29
0
    def render(self, console: Console) -> None:
        """
        Renders map.
        If tile in "visible" array, draw with "light" colors,
        otherwise, if it is "explored" array, draw with "dark" colors,
        otherwise, default is "SHROUD".
        """
        console.tiles_rgb[0:self.width, 0:self.height] = np.select(
            condlist=[self.visible, self.explored],
            choicelist=[self.tiles["light"], self.tiles["dark"]],
            default=tile_types.SHROUD)

        for entity in self.entities:
            #Only print entities in FOV
            if self.visible[entity.x, entity.y]:
                console.print(entity.x, entity.y, entity.char, fg=entity.color)
Example #30
0
 def render_entity_detail(self, highlighted_path, target,
                          console: Console) -> None:
     if highlighted_path:
         for x, y in highlighted_path:
             console.bg[x, y] = COLORS.get('show_entity_track')
     if target:
         console.bg[target.x, target.y] = tcod.black