Beispiel #1
0
 def render_menu(self, game_state, player):
     if game_state == GameStates.SHOW_INVENTORY:
         text = "Press the key next to an item to use it, or Esc to cancel.\n"
         inventory_menu(self.main_console, text, player, 50,
                        self.screen_width, self.screen_height)
     elif game_state == GameStates.DROP_INVENTORY:
         text = "Press the key net to an item to drop it, or Esc to cancel.\n"
         inventory_menu(self.main_console, text, player, 50,
                        self.screen_width, self.screen_height)
     elif game_state == GameStates.LEVEL_UP:
         level_up_menu(self.main_console,
                       'Level up! Choose a stat to raise:', player, 40,
                       self.screen_width, self.screen_height)
     elif game_state == GameStates.CHARACTER_SCREEN:
         character_screen(player, 30, 10, self.screen_width,
                          self.screen_height)
Beispiel #2
0
def render_all(root_con: tcod.console.Console, con: tcod.console.Console,
               panel: tcod.console.Console, entities, player, game_map,
               fov_map, fov_recompute: bool, message_log, bar_width,
               panel_y: int, mouse_pos, colors, game_state: GameStates):
    """Render characters on the console screen"""
    render_main_map(con, entities, player, game_map, fov_map, fov_recompute,
                    colors)
    con.blit(root_con)
    render_panel(panel, message_log, bar_width, player, mouse_pos, entities,
                 fov_map, game_map.dungeon_level)
    panel.blit(root_con, 0, panel_y)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it, or Esc to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n'
        inventory_menu(root_con, inventory_title, player, 50)
    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(root_con, 'Level up! Choose a stat to raise:', player,
                      40)
    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(root_con, player, 30, 10)
def render_all(root_console: tcod.console.Console,
               offscreen_console: tcod.console.Console,
               viewport_console: tcod.console.Console,
               status_console: tcod.console.Console,
               log_console: tcod.console.Console,
               entity_console: tcod.console.Console, player: Entity,
               game_map: GameMap, mouse_tx: int, mouse_ty: int,
               fov_recompute: bool, game_messages: MessageLog, box_text: str,
               game_state: GameState, camera: "Camera") -> None:

    screen_height = const.SCREEN_HEIGHT
    screen_width = const.SCREEN_WIDTH
    bar_width = const.BAR_WIDTH

    status_console.clear()
    log_console.clear()
    entity_console.clear()

    if fov_recompute:

        # Show nothing by default
        viewport_console.ch[:] = 0
        viewport_console.fg[:] = (0, 0, 0)
        viewport_console.bg[:] = (0, 0, 0)

        # Move camera to follow the player
        camera.move_camera(player.x, player.y, game_map.width, game_map.height)
        cam_x, cam_y = camera.x, camera.y
        cam_x2, cam_y2 = camera.x2, camera.y2

        # Translate map coordinates to camera coordinates
        cam_fov = game_map.fov_map.fov[cam_x:cam_x2 + 1, cam_y:cam_y2 + 1]
        cam_explored = game_map.explored[cam_x:cam_x2 + 1, cam_y:cam_y2 + 1]
        cam_glyph = game_map.tile_map.glyph[cam_x:cam_x2 + 1, cam_y:cam_y2 + 1]
        cam_fg = game_map.tile_map.fg[cam_x:cam_x2 + 1, cam_y:cam_y2 + 1]
        cam_bg = game_map.tile_map.bg[cam_x:cam_x2 + 1, cam_y:cam_y2 + 1]

        # If a tile is explored but not visible, render it in dark colors.
        viewport_console.fg[cam_explored == True] = np.multiply(
            cam_fg[cam_explored == True], 0.50).astype(np.int)
        viewport_console.bg[cam_explored == True] = np.multiply(
            cam_bg[cam_explored == True], 0.50).astype(np.int)
        viewport_console.ch[cam_explored == True] = cam_glyph[cam_explored ==
                                                              True]

        # If a tile is visible then render it in light colors.
        viewport_console.fg[cam_fov == True] = cam_fg[cam_fov == True]
        viewport_console.bg[cam_fov == True] = cam_bg[cam_fov == True]
        viewport_console.ch[cam_fov == True] = cam_glyph[cam_fov == True]
        # viewport_console.ch[cam_transparent == False] = 178

        # If a tile is visible, then it is now explored.
        game_map.explored[game_map.fov_map.fov == True] = True

    # Draw all entities in the list
    entities_in_render_order = sorted(game_map.entities,
                                      key=lambda x: x.entity_type.value)

    for entity in entities_in_render_order:
        draw_entity(viewport_console, entity, game_map, camera)

    render_bar(status_console, 1, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, tcod.light_red, tcod.darker_red)
    status_console.print(1, 3, f"Dungeon Level: {game_map.dungeon_level}")

    status_console.print(1,
                         0,
                         get_names_under_mouse(mouse_tx, mouse_ty,
                                               game_map.entities, game_map),
                         fg=(128, 128, 128))

    y = 0
    for message in game_messages.messages:
        log_console.print(game_messages.x, y, message.text, fg=message.color)
        y += 1

    entity_console.print(5, 0, "Visible:", (128, 128, 128))

    visible_entities = [
        entity for entity in entities_in_render_order
        if tcod.map_is_in_fov(game_map.fov_map, entity.x, entity.y)
    ]

    for index, entity in enumerate(visible_entities, start=1):
        if entity.entity_type not in [EntityType.PLAYER, EntityType.CORPSE]:
            entity_str = f"{chr(entity.glyph)}: {entity.name.capitalize()}"
            entity_console.print(1, index, entity_str, entity.fg)

    draw_frames(offscreen_console)

    # offscreen_console.print(0, screen_height - 1, f"{mouse_tx}, {mouse_ty}")

    viewport_console.blit(offscreen_console, 1, 1)
    status_console.blit(offscreen_console, const.VIEWPORT_WIDTH + 2, 1)
    log_console.blit(offscreen_console, 1, const.VIEWPORT_HEIGHT + 2)
    entity_console.blit(offscreen_console, const.VIEWPORT_WIDTH + 2,
                        const.STATUS_HEIGHT + 2)
    offscreen_console.blit(root_console)

    if game_state in [GameState.SHOW_INVENTORY, GameState.DROP_INVENTORY]:
        if game_state == GameState.SHOW_INVENTORY:
            inventory_title = "Press the key next to an item to use it, ESC to cancel.\n"
        else:
            inventory_title = "Press the key next to an item to drop it, ESC to cancel.\n"

        inventory_menu(root_console, inventory_title, player, 50, screen_width,
                       screen_height)

    elif game_state == GameState.LEVEL_UP:
        level_up_menu(root_console, "Level up! Choose a stat to raise:",
                      player, 40, screen_width, screen_height)

    elif game_state == GameState.CHARACTER_SCREEN:
        character_screen(root_console, player, 30, 10, screen_width,
                         screen_height)

    elif game_state == GameState.MESSAGE_BOX:
        message_box(root_console, box_text, len(box_text),
                    const.VIEWPORT_WIDTH, const.VIEWPORT_HEIGHT)

    if SHOW_STATS:
        fps = tcod.sys_get_fps()
        if fps > 0:
            fps_str = f"FPS: {fps} ({1000 / fps:.2f} ms/frame)"
            root_console.print(0,
                               const.SCREEN_HEIGHT - 1,
                               fps_str,
                               fg=(255, 255, 255))

    tcod.console_flush()
Beispiel #4
0
def render_all(con, panel, entities, player, game_map, fov_recompute,
               root_console, message_log, screen_width, screen_height,
               bar_width, panel_height, panel_y, mouse_coordinates, colors,
               game_state):
    if fov_recompute:
        # draw all map tiles
        for x, y in game_map:
            wall = not game_map.transparent[x, y]

            if game_map.fov[x, y]:
                if wall:
                    con.draw_char(x,
                                  y,
                                  None,
                                  fg=None,
                                  bg=colors.get('light_wall'))
                else:
                    con.draw_char(x,
                                  y,
                                  None,
                                  fg=None,
                                  bg=colors.get('light_ground'))

                game_map.explored[x][y] = True

            elif game_map.explored[x][y]:
                if wall:
                    con.draw_char(x,
                                  y,
                                  None,
                                  fg=None,
                                  bg=colors.get('dark_wall'))
                else:
                    con.draw_char(x,
                                  y,
                                  None,
                                  fg=None,
                                  bg=colors.get('dark_ground'))

    # ordering the entities if stacked
    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    # Draw all entities in list
    for entity in entities_in_render_order:
        draw_entity(con, entity, game_map)

    root_console.blit(con, 0, 0, screen_width, screen_height)

    panel.clear(fg=colors.get('white'), bg=colors.get('black'))

    # print game messages, one line at a time
    y = 1
    for message in message_log.messages:
        panel.draw_str(message_log.x,
                       y,
                       message.text,
                       bg=None,
                       fg=message.color)
        y += 1

    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, colors.get('light_red'),
               colors.get('darker_red'), colors.get('white'))

    panel.draw_str(1,
                   3,
                   'Dungeon Level: {0}'.format(game_map.dungeon_level),
                   fg=colors.get('white'),
                   bg=None)

    panel.draw_str(
        1, 0, get_names_under_mouse(mouse_coordinates, entities, game_map))

    root_console.blit(panel, 0, panel_y, screen_width, panel_height, 0, 0)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):

        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it, or ESC to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it, or ESC to cancel.\n'

        inventory_menu(con, root_console, inventory_title, player.inventory,
                       50, screen_width, screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, root_console, 'Level up! Chose a stat to raise:',
                      player, 40, screen_width, screen_height)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(root_console, player, 30, 10, screen_width,
                         screen_height)
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height, bar_width,
               panel_height, panel_y, mouse, game_state):
    
    # Define colors of walls and floors
    colors = {
        'dark_wall': from_dungeon_level([[tc.darkest_grey,1], [tc.desaturated_orange,4], [tc.darker_azure,7], [tc.darkest_fuchsia,10], [tc.darkest_flame,13]], game_map.dungeon_level),
        'dark_ground': from_dungeon_level([[tc.darker_sepia,1], [tc.darkest_grey,4], [tc.darkest_grey,7], [tc.darkest_sepia,10], [tc.darkest_grey,13]], game_map.dungeon_level),
        'light_wall': from_dungeon_level([[tc.dark_grey,1], [tc.brass,4], [tc.dark_azure,7], [tc.desaturated_fuchsia,10], [tc.dark_flame,13]], game_map.dungeon_level),
        'light_ground': from_dungeon_level([[tc.dark_sepia,1], [tc.darker_grey,4], [tc.darker_grey,7], [tc.darker_sepia,10], [tc.darker_grey,13]], game_map.dungeon_level),
        'burning_ground': tc.dark_flame
    }
    
    # Draw the game map
    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                game_map.tiles[x][y].take_turn()
                visible = tc.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight
                if visible:
                    if wall:
                        tc.console_set_default_foreground(con, colors.get('light_wall'))
                        tc.console_put_char(con, x, y, '#', tc.BKGND_NONE)
                    elif game_map.tiles[x][y].burning:
                        tc.console_set_default_foreground(con, colors.get('burning_ground'))
                        tc.console_put_char(con, x, y, '_', tc.BKGND_NONE)
                    else:
                        tc.console_set_default_foreground(con, colors.get('light_ground'))
                        tc.console_put_char(con, x, y, '_', tc.BKGND_NONE)
                        
                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    if wall:
                        tc.console_set_default_foreground(con, colors.get('dark_wall'))
                        tc.console_put_char(con, x, y, '#', tc.BKGND_NONE)
                    else:
                        tc.console_set_default_foreground(con, colors.get('dark_ground'))
                        tc.console_put_char(con, x, y, '_', tc.BKGND_NONE)
            
    entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value)
    
    # Draw all entities in the list
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map, colors)
        
    tc.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)
    
    tc.console_set_default_background(panel, tc.black)
    tc.console_clear(panel)
    
    # Print game messages
    y = 1
    for message in message_log.messages:
        tc.console_set_default_foreground(panel, message.color)
        tc.console_print_ex(panel, message_log.x, y, tc.BKGND_NONE, tc.LEFT, message.text)
        y += 1
    
    render_bar(panel, 1, 3, bar_width, 'HP', player.fighter.hp, player.fighter.max_hp,
               tc.light_red, tc.darker_red)
    render_bar(panel, 1, 5, bar_width, 'XP', player.level.current_xp, player.level.experience_to_next_level,
               tc.light_green, tc.darker_green)
    tc.console_print_ex(panel, 1, 1, tc.BKGND_NONE, tc.LEFT, 'Dungeon level: {0}'.format(game_map.dungeon_level))
    
    tc.console_set_default_foreground(panel, tc.light_gray)
    tc.console_print_ex(panel, 1, 0, tc.BKGND_NONE, tc.LEFT,
                        get_names_under_mouse(mouse, entities, fov_map))
    
    tc.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y)
    
    if game_state in (GameState.SHOW_INVENTORY, GameState.DROP_INVENTORY):
        if game_state == GameState.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it, or Esc to exit.\n'
        else:
            inventory_title = 'Press the key next to na item to drop it, or Esc to exit.\n'
            
        inventory_menu(con, inventory_title, player, 50, screen_width, screen_height)
    elif game_state == GameState.LEVEL_UP:
        level_up_menu(con, 'Level up! Choose a stat to raise:', player, 40, screen_width, screen_height)
    elif game_state == GameState.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)
    elif game_state == GameState.PAUSE:
        pause_menu(con, 'Game paused', 30, screen_width, screen_height)
Beispiel #6
0
    def __render_all(self, state):
        con = self.owner.con
        panel = self.owner.panel
        hotkeys = self.owner.hotkeys
        upper_bar = self.owner.upper_bar
        colors = CONFIG.get('COLORS')

        if state.game_state == GameStates.PLAYER_DEAD:
            self.__show_stats(con, state)
            tcod.console_set_default_foreground(upper_bar, tcod.white)
            tcod.console_set_default_background(upper_bar, tcod.black)
            tcod.console_clear(upper_bar)
            tcod.console_blit(self.owner.upper_bar, 0, 0, CONFIG.get('WIDTH'),
                              CONFIG.get('UPPER_BAR_HEIGHT'), 0, 0, 0)
        else:
            offset_mouse_x = state.mouse_x
            offset_mouse_y = state.mouse_y - CONFIG.get('MAP_Y')
            if self.fov_recompute or state.game_state == GameStates.TARGETING or self.redraw:
                for y in range(state.game_map.height):
                    for x in range(state.game_map.width):
                        visible = tcod.map_is_in_fov(self.fov_map, x, y)
                        wall = state.game_map.tiles[x][y].block_sight
                        if visible:
                            if wall:
                                tcod.console_set_char_background(
                                    con, x, y, colors.get('light_wall'),
                                    tcod.BKGND_SET)
                            else:
                                tcod.console_set_char_background(
                                    con, x, y, colors.get('light_ground'),
                                    tcod.BKGND_SET)
                                if state.game_state == GameStates.TARGETING:
                                    if state.targeting_area and self.distance(
                                            x, y, offset_mouse_x,
                                            offset_mouse_y
                                    ) <= state.targeting_radius:
                                        tcod.console_set_char_background(
                                            con, x, y, tcod.light_red,
                                            tcod.BKGND_SET)
                                    elif x == offset_mouse_x and y == offset_mouse_y:
                                        tcod.console_set_char_background(
                                            con, x, y, tcod.light_red,
                                            tcod.BKGND_SET)

                                if state.game_state == GameStates.TARGETING and x == offset_mouse_x and y == offset_mouse_y:
                                    if state.targeting_area:
                                        radius = state.targeting_radius
                                    tcod.console_set_char_background(
                                        con, x, y, tcod.light_red,
                                        tcod.BKGND_SET)
                            state.game_map.tiles[x][y].explored = True
                            if self.redraw and state.game_state in (
                                    GameStates.PLAYERS_TURN,
                                    GameStates.TARGETING):
                                tcod.console_put_char(con, x, y, ' ',
                                                      tcod.BKGND_NONE)
                        elif state.game_map.tiles[x][y].explored:
                            if wall:
                                tcod.console_set_char_background(
                                    con, x, y, colors.get('dark_wall'),
                                    tcod.BKGND_SET)
                            else:
                                tcod.console_set_char_background(
                                    con, x, y, colors.get('dark_ground'),
                                    tcod.BKGND_SET)
                            if self.redraw and state.game_state in (
                                    GameStates.PLAYERS_TURN,
                                    GameStates.TARGETING):
                                tcod.console_put_char(con, x, y, ' ',
                                                      tcod.BKGND_NONE)
                        elif self.redraw and state.game_state in (
                                GameStates.PLAYERS_TURN, GameStates.TARGETING):
                            tcod.console_put_char(con, x, y, ' ',
                                                  tcod.BKGND_NONE)

            tcod.console_set_default_background(hotkeys, tcod.black)
            tcod.console_clear(hotkeys)
            tcod.console_set_default_background(panel, tcod.black)
            tcod.console_clear(panel)
            for e in sorted(state.entities,
                            key=lambda x: x.render_order.value):
                #if tcod.map_is_in_fov(self.self.fov_map, e.x, e.y) or (e.stairs and self.game_map.tiles[e.x][e.y].explored):
                if tcod.map_is_in_fov(self.fov_map, e.x, e.y) or (e.stairs):
                    tcod.console_set_default_foreground(con, e.color)
                    tcod.console_put_char(con, e.x, e.y, e.char,
                                          tcod.BKGND_NONE)

            # Monster scan
            monster_scan = 1
            max_monster_scan = 4
            item_scan = 1
            max_item_scan = 6
            tcod.console_set_default_foreground(hotkeys, tcod.light_grey)
            hotkeys.print_(22, monster_scan, "Monster Scan", tcod.BKGND_NONE)

            tcod.console_set_default_foreground(panel, tcod.light_grey)
            tcod.console_print_ex(panel, 1, 1, tcod.BKGND_NONE, tcod.LEFT,
                                  "Ground Scan")

            for e in reversed(
                    sorted(state.entities,
                           key=lambda x: x.render_order.value)):
                if tcod.map_is_in_fov(self.fov_map, e.x, e.y) or (e.stairs):
                    if monster_scan < max_monster_scan and e.ai is not None and e.fighter is not None:
                        monster_scan += 1
                        hotkeys.print_box(22, monster_scan, 20, 1, e.name,
                                          tcod.white, tcod.black,
                                          tcod.BKGND_NONE, tcod.RIGHT)
                        tcod.console_set_default_foreground(hotkeys, e.color)
                        tcod.console_put_char(hotkeys, 43, monster_scan,
                                              e.char, tcod.BKGND_NONE)
                        render_bar(hotkeys, 45, monster_scan, 30, 'HP',
                                   e.fighter.hp, e.fighter.max_hp,
                                   tcod.light_red, tcod.darker_red)

                    if item_scan < max_item_scan and e.ai is None and e != state.player:
                        item_scan += 1
                        tcod.console_set_default_foreground(panel, e.color)
                        tcod.console_put_char(panel, 1, item_scan, e.char,
                                              tcod.BKGND_NONE)
                        tcod.console_set_default_foreground(panel, tcod.white)
                        tcod.console_print_ex(panel, 3, item_scan,
                                              tcod.BKGND_NONE, tcod.LEFT,
                                              e.name[:19])
            #tcod.console_set_char_background(panel, 10, 10, tcod.violet, tcod.BKGND_SET)

            # Message Log
            y = 1
            for message in state.message_log.messages:
                tcod.console_set_default_foreground(panel, message.color)
                tcod.console_print_ex(panel, state.message_log.x, y,
                                      tcod.BKGND_NONE, tcod.LEFT, message.text)
                y += 1

            # Hotkeys
            slot_pos = 0
            for slot in state.player.inventory.tome_slots:
                rel_pos = (slot_pos * 3)
                hotkeys.draw_frame(rel_pos + 1, 1, 3, 3, str(slot_pos + 1),
                                   True, tcod.white, tcod.grey)
                if slot.quantity > 0:
                    tcod.console_set_default_foreground(
                        hotkeys, slot.item.color)
                else:
                    tcod.console_set_default_foreground(
                        hotkeys, tcod.light_grey)
                tcod.console_print_ex(hotkeys, rel_pos + 2, 2, tcod.BKGND_NONE,
                                      tcod.LEFT, "#")
                tcod.console_set_default_foreground(hotkeys, tcod.white)
                tcod.console_print_ex(hotkeys, rel_pos + 1, 4, tcod.BKGND_NONE,
                                      tcod.LEFT, "x%i" % slot.quantity)
                slot_pos += 1

            # Upper bar (health and stats)
            tcod.console_set_default_foreground(upper_bar, tcod.white)
            tcod.console_set_default_background(upper_bar, tcod.black)
            tcod.console_clear(upper_bar)
            tcod.console_print_ex(upper_bar, 1, 1, tcod.BKGND_NONE, tcod.LEFT,
                                  'Player')
            tcod.console_set_default_foreground(upper_bar, tcod.black)
            tcod.console_set_default_background(upper_bar, tcod.white)
            tcod.console_print_ex(upper_bar, 7, 1, tcod.BKGND_SET, tcod.LEFT,
                                  '@')
            tcod.console_set_default_foreground(upper_bar, tcod.white)
            tcod.console_set_default_background(upper_bar, tcod.black)

            render_bar(upper_bar, 12, 1, CONFIG.get('BAR_WIDTH'), 'HP',
                       state.player.fighter.hp, state.player.fighter.max_hp,
                       tcod.light_red, tcod.darker_red)

            upper_bar.print_box(35, 1, 14, 1, 'Dungeon Level:',
                                tcod.light_grey, tcod.black, tcod.BKGND_NONE,
                                tcod.RIGHT)
            upper_bar.print_box(35, 2, 14, 1, 'Gold Coins:', tcod.light_grey,
                                tcod.black, tcod.BKGND_NONE, tcod.RIGHT)
            tcod.console_set_default_foreground(upper_bar, tcod.light_yellow)
            tcod.console_print_ex(upper_bar, 49, 1, tcod.BKGND_NONE, tcod.LEFT,
                                  '%i' % state.game_map.dungeon_level)
            tcod.console_print_ex(upper_bar, 49, 2, tcod.BKGND_NONE, tcod.LEFT,
                                  '%i' % state.player.purse.coins)

            upper_bar.print_box(60, 1, 9, 1, 'Power:', tcod.light_grey,
                                tcod.black, tcod.BKGND_NONE, tcod.RIGHT)
            upper_bar.print_box(60, 2, 9, 1, 'Defense:', tcod.light_grey,
                                tcod.black, tcod.BKGND_NONE, tcod.RIGHT)
            upper_bar.print_box(60, 3, 9, 1, 'Magic:', tcod.light_grey,
                                tcod.black, tcod.BKGND_NONE, tcod.RIGHT)
            tcod.console_set_default_foreground(upper_bar, tcod.white)
            tcod.console_print_ex(upper_bar, 69, 1, tcod.BKGND_NONE, tcod.LEFT,
                                  '%i' % state.player.fighter.base_power)
            tcod.console_print_ex(upper_bar, 69, 2, tcod.BKGND_NONE, tcod.LEFT,
                                  '%i' % state.player.fighter.base_defense)
            tcod.console_print_ex(upper_bar, 69, 3, tcod.BKGND_NONE, tcod.LEFT,
                                  '%i' % state.player.fighter.base_magic)

            # Print all consoles
            tcod.console_blit(self.owner.upper_bar, 0, 0, CONFIG.get('WIDTH'),
                              CONFIG.get('UPPER_BAR_HEIGHT'), 0, 0, 0)
            tcod.console_blit(self.owner.con, 0, 0, CONFIG.get('WIDTH'),
                              CONFIG.get('MAP_HEIGHT'), 0, 0,
                              CONFIG.get('MAP_Y'))
            tcod.console_blit(self.owner.panel, 0, 0, CONFIG.get('WIDTH'),
                              CONFIG.get('PANEL_HEIGHT'), 0, 0,
                              CONFIG.get('PANEL_Y'))
            tcod.console_blit(self.owner.hotkeys, 0, 0, CONFIG.get('WIDTH'),
                              CONFIG.get('ACTION_HEIGHT'), 0, 0,
                              CONFIG.get('ACTION_Y'))

            # Overlay menus
            if state.game_state == GameStates.INSTRUCTIONS:
                help_menu(con, CONFIG.get('WIDTH'))

            if state.game_state == GameStates.SHOP:
                shop_menu(con, state.player, state.game_map.shopkeeper.shop,
                          CONFIG.get('WIDTH'), CONFIG.get('HEIGHT'))

            if state.game_state in (GameStates.INVENTORY,
                                    GameStates.DROP_INVENTORY):
                if state.game_state == GameStates.INVENTORY:
                    title = 'Press the key next to an item to use it or I again to leave\n'
                else:
                    title = 'Press the key next to an item to drop it or O again to leave\n'
                inventory_menu(con, title, state.player, 50,
                               CONFIG.get('WIDTH'), CONFIG.get('HEIGHT'))

            if state.game_state == GameStates.CHARACTER_SCREEN:
                character_screen(state.player, 30, 10, CONFIG.get("WIDTH"),
                                 CONFIG.get("HEIGHT"))

            if state.game_state == GameStates.LEVEL_UP:
                level_up_menu(self.owner.con,
                              'Level Up! Choose a stat to raise:',
                              state.player, 40, CONFIG.get('WIDTH'),
                              CONFIG.get('HEIGHT'))
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute,
               message_log, screen_width, screen_height, bar_width,
               panel_height, panel_y, mouse, colors, game_state):
    if fov_recompute:
        # Draw all the tiles in the game map
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('light_wall'),
                            libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('light_ground'),
                            libtcod.BKGND_SET)

                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('dark_wall'),
                            libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('dark_ground'),
                            libtcod.BKGND_SET)

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

    # Draw all entities in the list
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

    libtcod.console_set_default_background(panel, libtcod.black)
    libtcod.console_clear(panel)

    # Print the game messages, one line at a time
    y = 1
    for message in message_log.messages:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, message.text)
        y += 1

    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)

    render_bar(panel, 1, 3, bar_width, 'SP', player.fighter.sp,
               player.fighter.max_sp, libtcod.green, libtcod.darkest_green)

    render_bar(panel, 1, 5, bar_width, 'MP', player.fighter.mp,
               player.fighter.max_mp, libtcod.light_blue, libtcod.dark_blue)

    libtcod.console_print_ex(
        panel, 62, 5, libtcod.BKGND_NONE, libtcod.LEFT,
        'Dungeon level: {0}'.format(game_map.dungeon_level))

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0,
                         panel_y)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it, or Esc to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n'

        inventory_menu(con, inventory_title, player.inventory, 50,
                       screen_width, screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up! Choose a stat to raise:', player, 40,
                      screen_width, screen_height)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)
Beispiel #8
0
def render_all(
    console,
    panel,
    entities,
    player,
    game_map,
    fov_map,
    fov_recompute,
    message_log,
    screen_width,
    screen_height,
    bar_width,
    panel_height,
    panel_y,
    mouse,
    colors,
    game_state,
):
    """ Draw all entities

    """

    # Draw all tiles
    if fov_recompute:
        for y_pos in range(game_map.height):
            for x_pos in range(game_map.width):
                visible = tcod.map_is_in_fov(fov_map, x_pos, y_pos)
                wall = game_map.tiles[x_pos][y_pos].block_sight

                if visible:
                    if wall:
                        tcod.console_set_char_background(
                            console,
                            x_pos,
                            y_pos,
                            colors.get("light_wall"),
                            tcod.BKGND_SET,
                        )
                    else:
                        tcod.console_set_char_background(
                            console,
                            x_pos,
                            y_pos,
                            colors.get("light_ground"),
                            tcod.BKGND_SET,
                        )
                    game_map.tiles[x_pos][y_pos].explored = True
                elif game_map.tiles[x_pos][y_pos].explored:
                    if wall:
                        tcod.console_set_char_background(
                            console,
                            x_pos,
                            y_pos,
                            colors.get("dark_wall"),
                            tcod.BKGND_SET,
                        )
                    else:
                        tcod.console_set_char_background(
                            console,
                            x_pos,
                            y_pos,
                            colors.get("dark_ground"),
                            tcod.BKGND_SET,
                        )

    # Draw all entities
    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    for entity in entities_in_render_order:
        draw_entity(console, entity, fov_map, game_map)

    tcod.console_blit(console, 0, 0, screen_width, screen_height, 0, 0, 0)

    tcod.console_set_default_background(panel, tcod.black)
    tcod.console_clear(panel)

    # Print the game messages, one line at a time
    y = 1
    for message in message_log.messages:
        tcod.console_set_default_foreground(panel, message.color)
        tcod.console_print_ex(panel, message_log.x, y, tcod.BKGND_NONE,
                              tcod.LEFT, message.text)
        y += 1

    render_bar(
        panel,
        1,
        1,
        bar_width,
        "HP",
        player.fighter.hp,
        player.fighter.max_hp,
        tcod.light_red,
        tcod.darker_red,
    )
    tcod.console_print_ex(panel, 1, 3, tcod.BKGND_NONE, tcod.LEFT,
                          f'Dungeon level {game_map.dungeon_level}')

    tcod.console_set_default_foreground(panel, tcod.light_gray)
    tcod.console_print_ex(
        panel,
        1,
        0,
        tcod.BKGND_NONE,
        tcod.LEFT,
        get_names_under_mouse(mouse, entities, fov_map),
    )

    tcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = (
                "Press the key next to an item to use it, or Esc to cancel\n")
        else:
            inventory_title = (
                "Press the key next to an item to drop it, or Esc to cancel\n")
        inventory_menu(console, inventory_title, player.inventory, 50,
                       screen_width, screen_height)
    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(console, 'Level up! Choose a stat to raise:', player, 40,
                      screen_width, screen_height)