コード例 #1
0
ファイル: render_functions.py プロジェクト: KorwoRig/Sorg
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)

    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)

    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)
コード例 #2
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)
コード例 #3
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)
コード例 #4
0
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()
コード例 #5
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)
コード例 #6
0
def _handle_keyboard_event(event):
    """
    Handles keyboard event

    Args:
        event (Event): Keyboard event to handle
    """
    # Movement
    if event.key == pygame.K_a:
        update_creatures(config.GAME_DATA.creature_data, -1, 0)
    elif event.key == pygame.K_d:
        update_creatures(config.GAME_DATA.creature_data, 1, 0)
    elif event.key == pygame.K_w:
        update_creatures(config.GAME_DATA.creature_data, 0, -1)
    elif event.key == pygame.K_q:
        update_creatures(config.GAME_DATA.creature_data, -1, -1)
    elif event.key == pygame.K_e:
        update_creatures(config.GAME_DATA.creature_data, 1, -1)
    elif event.key == pygame.K_z:
        update_creatures(config.GAME_DATA.creature_data, -1, 1)
    elif event.key == pygame.K_c:
        update_creatures(config.GAME_DATA.creature_data, 1, 1)
    elif event.key == pygame.K_s:
        update_creatures(config.GAME_DATA.creature_data, 0, 1)
    elif event.key == pygame.K_x:
        update_creatures(config.GAME_DATA.creature_data, 0, 0)

    # Mini_map
    elif event.key == pygame.K_m:
        toggle_minimap()

    # Pickup/Drop Item
    elif event.key == pygame.K_t:
        objects_at_player = map_items_at_coord(config.GAME_DATA.item_data,
                                               config.PLAYER.x,
                                               config.PLAYER.y)
        for obj in objects_at_player:
            if obj.item:
                obj.item.pick_up(config.PLAYER)
        update_creatures(config.GAME_DATA.creature_data, 0, 0)

    elif event.key == pygame.K_F12:
        _toggle_wallhack()

    elif event.key == pygame.K_TAB:
        _toggle_camera()

    # Auto move
    elif event.key == pygame.K_v:
        auto_path(config.PATHFINDING)

    # Menu Buttons
    elif event.key == pygame.K_p:
        menu.pause()

    elif event.key == pygame.K_i:
        menu.inventory_menu()

    # Use magic
    elif event.key == pygame.K_SPACE:
        menu.magic_select_menu()

    # Returns to previous level
    elif event.key == pygame.K_1:
        if config.MAP_INFO.tile_array[config.PLAYER.y][
                config.PLAYER.x].type == UPSTAIR:
            config.CURRENT_FLOOR -= 1
            config.GAME_DATA.transition_previous_level()

    # Goes to next level
    elif event.key == pygame.K_2:
        if config.CURRENT_FLOOR < NUM_OF_FLOOR and \
                config.MAP_INFO.tile_array[config.PLAYER.y][config.PLAYER.x].type == DOWNSTAIR:
            config.CURRENT_FLOOR += 1
            config.GAME_DATA.transition_next_level()

    elif event.key == pygame.K_F2:
        save_game()

    elif event.key == pygame.K_F3:
        load_game()
コード例 #7
0
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)
コード例 #8
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'))
コード例 #9
0
def render_all(entities, player, game_map, message_log, bar_width, panel_y,
               coordinates, camera, game_state, targeting_item):

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

    camera_moved = camera.move_camera(player.x, player.y, game_map)

    terminal.layer(RenderLayer.MAP.value)

    if camera_moved:
        clear_map_layer()

    game_map.render_from_camera(camera)

    # Draw all entities in the list
    terminal.layer(RenderLayer.ENTITIES.value)
    for entity in entities_in_render_order:
        entity.draw(camera, game_map)

    terminal.layer(RenderLayer.OVERLAY.value)
    clear_layer()

    for efx in game_map.effects:
        efx.update()
        if efx.expired:
            game_map.effects.remove(efx)
        elif efx.render:
            (term_x, term_y) = camera.map_to_term_coord(efx.x, efx.y)
            terminal.put(term_x, term_y, efx.gfx_effect_tile)

    if game_state == GameStates.TARGETING:
        from entity import get_blocking_entities_at_location
        terminal.composition(terminal.TK_ON)

        mouse_map_x = int(coordinates[0] / 4)
        mouse_map_y = int(coordinates[1] / 2)

        mouse_map_x += camera.camera_x
        mouse_map_y += camera.camera_y

        line = tcod.line_iter(player.x, player.y, mouse_map_x, mouse_map_y)

        for coord in line:
            if coord[0] == player.x and coord[1] == player.y:
                continue
            cell_term_x, cell_term_y = camera.map_to_term_coord(
                coord[0], coord[1])
            if coord[0] == mouse_map_x and coord[
                    1] == mouse_map_y and game_map.fov[
                        coord[0], coord[1]] and not game_map.is_blocked(
                            coord[0], coord[1]):
                terminal.color(terminal.color_from_argb(125, 0, 255, 0))
            elif get_blocking_entities_at_location(entities, coord[0],
                                                   coord[1]):
                terminal.color(terminal.color_from_argb(125, 255, 0, 0))
            elif not game_map.fov[coord[0], coord[1]] or game_map.is_blocked(
                    coord[0], coord[1]):
                terminal.color(terminal.color_from_argb(125, 255, 0, 0))
            else:
                terminal.color(terminal.color_from_argb(125, 255, 255, 0))
            terminal.put(x=cell_term_x, y=cell_term_y, c=0x3014)
            terminal.composition(terminal.TK_OFF)

        if targeting_item:
            function_kwargs = targeting_item.item.function_kwargs
            if function_kwargs:
                radius = function_kwargs.get("radius")
                if radius:
                    for cell_x, cell_y in disk(mouse_map_x, mouse_map_y,
                                               radius, game_map.width,
                                               game_map.height):
                        (cell_term_x, cell_term_y) = camera.map_to_term_coord(
                            cell_x, cell_y)
                        if cell_term_x and cell_term_y:  # Omit cells outside of the terminal window
                            if get_blocking_entities_at_location(
                                    entities, cell_x,
                                    cell_y) and game_map.fov[cell_x, cell_y]:
                                terminal.color(
                                    terminal.color_from_argb(125, 0, 255, 0))
                            else:
                                terminal.color(
                                    terminal.color_from_argb(125, 139, 0, 0))
                            terminal.put(x=cell_term_x,
                                         y=cell_term_y,
                                         c=0x3014)

    terminal.layer(RenderLayer.HUD.value)
    clear_layer()

    # HP bar
    render_bar(1, panel_y + 6, bar_width, 'HP', player.fighter.current_hp,
               player.fighter.max_hp, "red", "darker red")

    terminal.printf(1, panel_y + 7, f"Dungeon Level: {game_map.dungeon_level}")

    entity_names = get_names_under_mouse(coordinates, camera, entities,
                                         game_map)
    terminal.printf(1, panel_y, f"[color=white]{entity_names.title()}")

    terminal.layer(RenderLayer.HUD.value)
    line_y = panel_y + 1
    for message in message_log.messages:
        terminal.color(terminal.color_from_name(message.color))
        print_shadowed_text(message_log.x, line_y, message.text)
        line_y += 1

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            title = "INVENTORY – press key next to item to use it"
        elif game_state == GameStates.DROP_INVENTORY:
            title = "INVENTORY – press key next to item to drop it"
        inventory_menu(player, title).draw()
コード例 #10
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)
コード例 #11
0
def playing_input():
    # movement keys
    is_direction = handle_direction_keys()
    if is_direction is not None:
        return is_direction
    key_char = chr(settings.key.c)
    if key_char == 'g':
        for obj in settings.objects:
            if obj.x == settings.player.x and obj.y == settings.player.y and obj.item:
                obj.item.pick_up(settings.player)
                break
    if key_char == 'i':
        chosen_item = inventory_menu(
            'Press the key next to the item to use it, or any other key to cancel.\n'
        )
        if chosen_item is not None:
            chosen_item.use(settings.player)
            end_player_turn()
    if key_char == 's':
        chosen_ability = abilities_menu(
            'Press the key next to the skill to use it, or any other key to cancel.\n'
        )
        if chosen_ability is not None:
            for ability in settings.player.combatant.abilities:
                if ability == chosen_ability:
                    ability.use(settings.player)
    if key_char == 'd':
        chosen_item = inventory_menu(
            "Press the letter next to the item to drop it.\n")
        if chosen_item is not None:
            chosen_item.drop(settings.player)
    if key_char == 'l':
        settings.game_state = 'looking'
        settings.highlight_state = 'look'
    if key_char == '.' and settings.key.shift:
        if settings.stairs_down.x == settings.player.x and settings.stairs_down.y == settings.player.y:
            next_level()
    if key_char == ',' and settings.key.shift:
        if settings.stairs_up.x == settings.player.x and settings.stairs_up.y == settings.player.y:
            if settings.dungeon_level != 1:
                previous_level()
            else:
                if settings.boner_dome in settings.player.combatant.inventory:
                    msgbox("You escape with the Dome of Boners!")
                    return 'exit'
                else:
                    msgbox(
                        "You cannot leave until you have the Dome of Boners")
    if key_char == ',':
        settings.game_state = 'running'
        settings.running_direction = prompt_user_for_direction()
        run_in_direction(settings.running_direction)
    if key_char == 'c':
        # show character stats
        character_menu("Details about your character.\n")
    if key_char == 't':
        settings.player.combatant.set_target()
    if key_char == 'o':
        message('target is ' + settings.player.combatant.target.name,
                tcod.blue)

    settings.selection_coordinates = (settings.mouse.cx, settings.mouse.cy)