Пример #1
0
    def render(self, pokeball: Pokeball, percent_complete: float, message: str) -> libtcod.console:
        """
            Render the area and return the full console
        """
        rows_complete = int(len(CatchGraphicRenderer.graphic) * (percent_complete / 100))

        libtcod.console_clear(self.console)
        libtcod.console_set_default_background(self.console, settings.CATCH_GRAPHIC_BG_COLOR)
        libtcod.console_set_default_foreground(self.console, settings.LINE_COLOR)
        libtcod.console_print_frame(self.console, 0, 0, CatchGraphicRenderer.width, CatchGraphicRenderer.height)

        for y, row in enumerate(CatchGraphicRenderer.graphic):
            for x, cell in enumerate(row):
                if cell[0] != '':
                    if len(CatchGraphicRenderer.graphic) - y <= rows_complete:
                        if cell[1] == "upper":
                            color = pokeball.top_color
                        elif cell[1] == "lower":
                            color = pokeball.bottom_color
                        else:
                            color = cell[1]
                    else:
                        color = libtcod.gray

                    libtcod.console_set_default_foreground(self.console, color)
                    libtcod.console_put_char(self.console, x + self.x_offset, y + self.y_offset, cell[0])

        if message:
            libtcod.console_print_rect_ex(self.console,
                                          CatchGraphicRenderer.width // 2, CatchGraphicRenderer.height - 3, 
                                          CatchGraphicRenderer.width - 2, 2, 
                                          libtcod.BKGND_NONE, libtcod.CENTER, message)

        return self.console
Пример #2
0
 def _render_summary(self, creature: Creature, prev_level: int):
     """
         Render the summary line at the top of the console.
     """
     summary_str = "Level {0} -> {1}".format(prev_level, creature.level)
     libtcod.console_set_default_foreground(self.console, settings.BATTLE_TEXT_COLOR)
     libtcod.console_print(self.console, 5, 3, summary_str)
def main_menu():
    img = libtcod.image_load('menu_background.png')
 
    while not libtcod.console_is_window_closed():
        #show the background image, at twice the regular console resolution
        libtcod.image_blit_2x(img, 0, 0, 0)
 
        #show the game's title, and some credits!
        libtcod.console_set_default_foreground(0, libtcod.light_yellow)
        libtcod.console_print_ex(0, SCREEN_WIDTH//2, SCREEN_HEIGHT//2-4, libtcod.BKGND_NONE, libtcod.CENTER,
            'TOMBS OF THE ANCIENT KINGS')
        libtcod.console_print_ex(0, SCREEN_WIDTH//2, SCREEN_HEIGHT-2, libtcod.BKGND_NONE, libtcod.CENTER,
            'By Jotaf')
 
        #show options and wait for the player's choice
        choice = menu('', ['Play a new game', 'Continue last game', 'Quit'], 24)
 
        if choice == 0:  #new game
            new_game()
            play_game()
        if choice == 1:  #load last game
            try:
                load_game()
            except:
                msgbox('\n No saved game to load.\n', 24)
                continue
            play_game()
        elif choice == 2:  #quit
            break
 def draw(self):
     #only show if it's visible to the player; or it's set to "always visible" and on an explored tile
     if (libtcod.map_is_in_fov(fov_map, self.x, self.y) or
         (self.always_visible and map[self.x][self.y].explored)):
         #set the color and then draw the character that represents this object at its position
         libtcod.console_set_default_foreground(con, self.color)
         libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_NONE)
Пример #5
0
    def _render_map(self, map_data: MapData):
        for y in range(self.start_y, self.start_y + settings.SCREEN_HEIGHT):
            for x in range(self.start_x, self.start_x + settings.SCREEN_WIDTH):
                if len(map_data.tiles) > y >= 0 and len(map_data.tiles[y]) > x >= 0:
                    cell = map_data.tiles[y][x]

                    libtcod.console_set_default_foreground(self.console, cell.color)
                    libtcod.console_put_char(self.console, x - self.start_x, y - self.start_y, cell.display_character)
Пример #6
0
 def _render_lines(self):
     """
         Render the lines which make up the structure of the pokedex.
     """
     libtcod.console_set_default_foreground(self.console, settings.POKEDEX_LINE_COLOR)
     libtcod.console_hline(self.console, 0, PokedexRenderer.header_height, PokedexRenderer.width)
     for i in range(PokedexRenderer.column_width, PokedexRenderer.width, PokedexRenderer.column_width):
         libtcod.console_vline(self.console, i, PokedexRenderer.header_height + 1, PokedexRenderer.column_height)
Пример #7
0
    def _render_stats(self, creature: Creature, prev_level: int):
        """
            Render the statistics lines one by one.
        """
        libtcod.console_set_default_foreground(self.console, settings.BATTLE_TEXT_COLOR)

        for idx, stat in enumerate([stat for stat in creature.stats if stat.short_name is not None and stat.short_name != ""]):
            stat_str = "{0:7s}: {1:3d} -> {2:3d}".format(stat.short_name, creature.max_stat(stat, level=prev_level), creature.max_stat(stat))

            libtcod.console_print(self.console, 5, 4 + idx, stat_str)
Пример #8
0
 def _render_health_values(self, creature: Creature, x: int, y: int):
     """
         Utility function to render the health values <current>/<max> at 
         the given x,y coordinates.
     """
     hp_stat = self.game.static_game_data.stat(data.HP_STAT)
     current = creature.current_stat(hp_stat)
     max_hp = creature.max_stat(hp_stat)
     
     libtcod.console_set_default_foreground(self.console, settings.BATTLE_TEXT_COLOR)
     libtcod.console_print(self.console, x, y, "{0}/{1}".format(current, max_hp))
Пример #9
0
    def _render_creature_details(self, creature: Creature, x: int, y: int, include_health_values: bool=False):
        """
            Renders the creature box for the defending creature.
        """
        height = BattleRenderer.creature_details_height_w_hp if include_health_values else BattleRenderer.creature_details_height_no_hp

        libtcod.console_set_default_foreground(self.console, settings.BATTLE_TEXT_COLOR)
        libtcod.console_print_frame(self.console, x, y, BattleRenderer.creature_details_width, height)
        libtcod.console_print(self.console, x + 1, y + 1, creature.nickname[:10])
        libtcod.console_print(self.console, x + BattleRenderer.creature_details_width - 6, y + 1, "LV.{0}".format(creature.level))
        
        self._render_health_bar(creature, BattleRenderer.creature_details_width - 2, x + 1, y + 3)
        if include_health_values:
            self._render_health_values(creature, x + BattleRenderer.creature_details_width - 8, y + 5)
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
    #render a bar (HP, experience, etc). first calculate the width of the bar
    bar_width = int(float(value) // maximum * total_width)
 
    #render the background first
    libtcod.console_set_default_background(panel, back_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False, libtcod.BKGND_SCREEN)
 
    #now render the bar on top
    libtcod.console_set_default_background(panel, bar_color)
    if bar_width > 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False, libtcod.BKGND_SCREEN)
 
    #finally, some centered text with the values
    libtcod.console_set_default_foreground(panel, libtcod.white)
    libtcod.console_print_ex(panel, x + total_width // 2, y, libtcod.BKGND_NONE, libtcod.CENTER,
        name + ': ' + str(value) + '/' + str(maximum))
def render_all():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute
 
    if fov_recompute:
        #recompute FOV if needed (the player moved or something)
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO)
 
        #go through all tiles, and set their background color according to the FOV
        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = map[x][y].block_sight
                if not visible:
                    #if it's not visible right now, the player can only see it if it's explored
                    if map[x][y].explored:
                        if wall:
                            libtcod.console_set_char_background(con, x, y, color_dark_wall, libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_char_background(con, x, y, color_dark_ground, libtcod.BKGND_SET)
                else:
                    #it's visible
                    if wall:
                        libtcod.console_set_char_background(con, x, y, color_light_wall, libtcod.BKGND_SET )
                    else:
                        libtcod.console_set_char_background(con, x, y, color_light_ground, libtcod.BKGND_SET )
                    #since it's visible, explore it
                    map[x][y].explored = True
 
    #draw all objects in the list, except the player. we want it to
    #always appear over all other objects! so it's drawn later.
    for object in objects:
        if object != player:
            object.draw()
    player.draw()
 
    #blit the contents of "con" to the root console
    libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)
 
    #show the player's stats
    libtcod.console_set_default_foreground(con, libtcod.white)
    libtcod.console_print_ex(0, 1, SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.LEFT,
        'HP: ' + str(player.fighter.hp) + '/' + str(player.fighter.max_hp))
def menu(header, options, width):
    if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.')
 
    #calculate total height for the header (after auto-wrap) and one line per option
    header_height = libtcod.console_get_height_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height
 
    #create an off-screen console that represents the menu's window
    window = libtcod.console_new(width, height)
 
    #print the header, with auto-wrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)
 
    #print all the options
    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text)
        y += 1
        letter_index += 1
 
    #blit the contents of "window" to the root console
    x = SCREEN_WIDTH//2 - width//2
    y = SCREEN_HEIGHT//2 - height//2
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
 
    #present the root console to the player and wait for a key-press
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)
 
    if key.vk == libtcod.KEY_ENTER and key.lalt:  #(special case) Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
 
    #convert the ASCII code to an index; if it corresponds to an option, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options): return index
    return None
Пример #13
0
 def _render_health_bar(self, creature: Creature, max_length: int, x: int, y: int):
     """
         Utility function to render a health bar for the given creature at
         the given x and y coordinates.
     """
     hp_stat = self.game.static_game_data.stat(data.HP_STAT)
     health_bars = int((creature.current_stat(hp_stat) / creature.max_stat(hp_stat)) * max_length)
     
     if health_bars > max_length / 2:
         color = settings.GOOD_HEALTH_COLOR
     elif health_bars > max_length / 4:
         color = settings.HALF_HEALTH_COLOR
     else:
         color = settings.LOW_HEALTH_COLOR
         
     libtcod.console_set_default_foreground(self.console, color)
     for i in range(x, x + health_bars):
         libtcod.console_put_char(self.console, i, y, '=')
         
     libtcod.console_set_default_foreground(self.console, settings.BLANK_HEALTH_COLOR)
     for i in range(x + health_bars, x + max_length):
         libtcod.console_put_char(self.console, i, y, '=')
Пример #14
0
    def _render_details_box(self, species, status):
        """
            If a pokemon has been selected then this is called to display a 
            box with the specific details as an overlay on top of the pokedex.
        """
        libtcod.console_set_default_foreground(self.console, settings.POKEDEX_LINE_COLOR)
        libtcod.console_print_frame(self.console, 19, 15, 43, 16)  # TODO: Generalise to widths
        
        libtcod.console_print(self.console, 23, 16, u"No. {0.pokedex_number:0=3d}  {0.name}".format(species))

        if status == 2:
            libtcod.console_print(self.console, 23, 17, u"  {0.genus} Pokemon".format(species))
            libtcod.console_print(self.console, 23, 18, u"Type(s): {0}".format(', '.join(str(t) for t in species.types)))
            libtcod.console_print(self.console, 23, 19, "Height: {0}".format(species.imperial_height_str()))
            libtcod.console_print(self.console, 23, 20, "Weight: {0}".format(species.imperial_weight_str()))
            
            libtcod.console_print_rect(self.console, 20, 22, 41, 14, species.flavor_text)
        elif status == 1:
            libtcod.console_print(self.console, 23, 17, "  ????? Pokemon".format(species))
            libtcod.console_print(self.console, 23, 18, "Type(s): ?????")
            libtcod.console_print(self.console, 23, 19, "Height: ??'??\"")
            libtcod.console_print(self.console, 23, 20, "Weight: ????.? lbs.")
Пример #15
0
 def _render_species(self, pokedex, left_most_column):
     """
         Iterate over all species and put them onto the screen in the 
         appropriate location.
         
         Only displays seen and known species. Each of these can be 
         displayed differently.
     """
     for pokedex_number in pokedex:
         status, species = pokedex[pokedex_number]
     
         name = "???"
         color = settings.POKEDEX_UNKNOWN_COLOR
         if status == 1:
             name = species.name
             color = settings.POKEDEX_SEEN_COLOR
         elif status == 2:
             name = species.name
             color = settings.POKEDEX_KNOWN_COLOR
 
         column, row = self.calculate_position_of_pokedex_number(pokedex_number - 1, left_most_column)
         
         libtcod.console_set_default_foreground(self.console, color)
         libtcod.console_print(self.console, column * PokedexRenderer.column_width + 1, row + PokedexRenderer.header_height + 1, str(pokedex_number) + ". " + name)
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:
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = tcod.map_is_in_fov(fov_map, x, y)
                wall = 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)

                    game_map.tiles[x][y].explored = True
                elif 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)

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

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

    # Draws player health
    tcod.console_set_default_foreground(con, tcod.white)
    tcod.console_print_ex(
        con, 1, screen_height - 2, tcod.BKGND_NONE, tcod.LEFT,
        'HP: {0:02}/{1:02}'.format(player.fighter.hp, player.fighter.max_hp))

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

    # Draws status panel at bottom
    tcod.console_set_default_background(panel, tcod.black)
    tcod.console_clear(panel)

    # Prints 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

    # Renders the HP bar and current dungeon level
    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,
                          'Dungeon level: {0}'.format(game_map.dungeon_level))

    # Displays entity name on mouse-over
    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)

    # Displays inventory
    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, 50, screen_width,
                       screen_height)

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

    # Displays character screen
    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 11, screen_width, screen_height)
Пример #17
0
 def draw(self, con):
     # set the color and then draw the character that represents this object at its position
     tcod.console_set_default_foreground(con, self.color)
     tcod.console_put_char(con, self.x, self.y, self.char, tcod.BKGND_NONE)
Пример #18
0
def print_entity(entity):
    global field
    tcod.console_set_default_foreground(field, entity.color)
    tcod.console_put_char(field, entity.x, entity.y, entity.char,
                          tcod.BKGND_NONE)
Пример #19
0
def draw_s(menu_console, menu_selection):
    tcod.console_set_default_foreground(menu_console, constants.COLORS[14])
    menu_console.put_char(2, constants.SETTINGS[menu_selection]["yval"], 16,
                          tcod.BKGND_DEFAULT)
Пример #20
0
def render_all(god, con, panel, sidebar, entities, player, game_map, fov_map, fov_recompute, msg_log, mouse, game_state):
    ''' 
    Draw all the tiles and entities in the game map, taking the console, all entities, game_map, screen vars and colors as input
    Starting to draw stats on the screen! Think carefully about this and change stuff acordingly, probably move the UI part into another file
    '''
    zeit = datetime.now()
    if game_state == GameStates.TARGETING_MODE:
        blink=True
    else:
        blink=False
    if fov_recompute:
        for y in range(const['map_height']):
            for x in range(const['map_width']):
                visible = tcod.map_is_in_fov(fov_map, x, y)
                wall = 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)
                
                    game_map.tiles[x][y].explored = True

                elif game_map.tiles[x][y].explored or god.sight:
                    if wall:
                        tcod.console_set_char_background(con, x, y, colors['dark_wall'], tcod.BKGND_SET)
                    else:
                        tcod.console_set_char_background(con, x, y, colors['dark_ground'], tcod.BKGND_SET)

                else:# if god mode is turned off, it will make all non explored stuff turn black again
                    tcod.console_set_char_background(con, x, y, colors['black'], tcod.BKGND_SET)
    
    entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value)

    for entity in entities_in_render_order:
        draw_entity(god, con, entity, fov_map)

    '''
    ############## BLINKING SHENANIGANS WHEN TARGETING
    '''

    mouse_x, mouse_y = get_mouse_xy(mouse)
    if blink and round(zeit.microsecond/900000): #this just gets it every half secondish
        tcod.console_set_char_background(con, mouse_x, mouse_y, colors.get('blink'), tcod.BKGND_SET)
                    
    ############# Bliting the Main Console

    tcod.console_blit(con, 0, 0, const['screen_width'], const['screen_height'], 0, 0, const['panel_height'])


    ######################## PANEL  ############################3

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

    #print the game msgs, one line at a time, at the apropriate x, and y (message_x and y)
    y = 1
    for msg in msg_log.msgs:
        tcod.console_set_default_foreground(panel, msg.color)
        tcod.console_print_ex(panel, msg_log.x, y, tcod.BKGND_NONE, tcod.LEFT, msg.text)
        y+=1

    #renders hp bar
    render_bar(panel, 1, 1, const['bar_width'], 'HP', player.actor.hp, player.actor.max_hp, 
                tcod.light_red, tcod.darker_red)  

    #prints names under mouse
    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(god, mouse, entities, fov_map))
    
    #Prints info on the player
    player = entities[0]
    '''
    tcod.console_print_ex(panel, 1, 3, tcod.BKGND_NONE, tcod.LEFT,
                            f'SPI = {player.actor.spiritual} DEF = {player.actor.def_stat}')
    tcod.console_print_ex(panel, 1, 4, tcod.BKGND_NONE, tcod.LEFT,
                            f'PHY = {player.actor.physical} SPD = {player.actor.spd_stat}')
    tcod.console_print_ex(panel, 1, 5, tcod.BKGND_NONE, tcod.LEFT,
                            f'MEN = {player.actor.mental} ATK = {player.actor.atk_stat}')
    '''
    
    tcod.console_blit(panel, 0, 0, const['screen_width'], const['panel_height'], 0, 0, 0)

    ############################## SIDEBAR ##################################3

    tcod.console_set_default_background(sidebar, tcod.grey)
    tcod.console_clear(sidebar)

    y = 1    
    tcod.console_set_default_foreground(sidebar, tcod.yellow)
    for skill in player.knowledge.skill_forest.skills:
        tcod.console_print_ex(sidebar, 0, y, tcod.BKGND_NONE, tcod.LEFT, skill.name)
        y += 2

    tcod.console_blit(sidebar, 0, 0, const['sidebar_width'], const['sidebar_height'], 0, const['sidebar_x'], const['sidebar_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'
        elif game_state == GameStates.DROP_INVENTORY:
            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)
Пример #21
0
def drawEntity(console, entity):
    tcod.console_set_default_foreground(console, entity.color)
    tcod.console_put_char(console, entity.x, entity.y, entity.char,
                          tcod.BKGND_NONE)
Пример #22
0
    def render_stats(self):
        tcod.console_set_default_background(self.stat_console, tcod.black)
        tcod.console_clear(self.stat_console)
        bar_width = int(
            float(self.player.entity.get_hp()) /
            self.player.entity.get_max_hp() * (stat_console_width - 6))
        tcod.console_set_default_background(self.stat_console, tcod.red)
        tcod.console_rect(self.stat_console, 5, 5, (stat_console_width - 6), 1,
                          False, tcod.BKGND_SCREEN)
        tcod.console_set_default_background(self.stat_console, tcod.green)
        if bar_width > 0:
            tcod.console_rect(self.stat_console, 5, 5, bar_width, 1, False,
                              tcod.BKGND_SCREEN)

        tcod.console_print_ex(self.stat_console, 1, 5, tcod.BKGND_NONE,
                              tcod.LEFT, 'HP:')
        tcod.console_set_default_foreground(self.stat_console, tcod.black)
        tcod.console_print_ex(
            self.stat_console, 5, 5, tcod.BKGND_NONE, tcod.LEFT,
            '{0: 3}/{1: 3}'.format(
                self.player.entity.get_hp(),
                self.player.entity.get_max_hp(),
            ))
        tcod.console_set_default_foreground(self.stat_console, tcod.white)

        tcod.console_print_ex(
            self.stat_console, 1, 1, tcod.BKGND_NONE,
            tcod.LEFT, 'Race:  {0}'.format(
                str.upper(self.player.entity.monster_race.name)))
        class_name = 'None'
        if self.player.entity.monster_class is not None:
            class_name = str.upper(self.player.entity.monster_class.name)
        level = self.player.entity.get_level()
        tcod.console_print_ex(self.stat_console, 1, 2, tcod.BKGND_NONE,
                              tcod.LEFT, 'Class: {0}'.format(class_name))
        tcod.console_print_ex(self.stat_console, 1, 3, tcod.BKGND_NONE,
                              tcod.LEFT, 'Level: {0}'.format(str(level)))
        tcod.console_print_ex(
            self.stat_console, 1, 4, tcod.BKGND_NONE,
            tcod.LEFT, 'Exp: {0} / {1}'.format(
                self.player.entity.current_exp,
                self.player.entity.get_exp_to_next_level()))
        tcod.console_print_ex(
            self.stat_console, 1, 7, tcod.BKGND_NONE, tcod.LEFT,
            'STR {0:02} DEX {1:02} CON {2:02} INT {3:02}'.format(
                self.player.entity.get_strength(),
                self.player.entity.get_dexterity(),
                self.player.entity.get_constitution(),
                self.player.entity.get_intelligence(),
            ))
        tcod.console_print_ex(self.stat_console, 1, 9, tcod.BKGND_NONE,
                              tcod.LEFT, 'Equipment:')
        console_y = 10
        if self.player.entity.equip_slots:
            for slot in self.player.entity.equip_slots:
                slot_name = get_message('equip.slot.' + str(slot.value) +
                                        '.truncate')
                equip = self.player.entity.inventory.get_equip(slot)
                if equip:
                    equip_name = equip.get_name()
                else:
                    equip_name = get_message('equip.no_equipment')
                tcod.console_print_ex(
                    self.stat_console, 1, console_y, tcod.BKGND_NONE,
                    tcod.LEFT, ' {0}: {1}'.format(slot_name, equip_name))
                console_y += 1
        else:
            slot_name = get_message('equip.slot.none')
            tcod.console_print_ex(self.stat_console, 1, console_y,
                                  tcod.BKGND_NONE, tcod.LEFT,
                                  ' {0}'.format(slot_name))
            console_y += 1

        console_y += 1

        tcod.console_print_ex(self.stat_console, 1, console_y, tcod.BKGND_NONE,
                              tcod.LEFT, 'Traits:')
        console_y += 1
        for trait in self.player.entity.traits:
            tcod.console_print_ex(self.stat_console, 1, console_y,
                                  tcod.BKGND_NONE, tcod.LEFT,
                                  ' {0}'.format(trait.name))
            console_y += 1

        under_mouse_lines = textwrap.wrap(self.under_mouse, stat_console_width)

        i_line = 0
        for line in under_mouse_lines:
            tcod.console_print_ex(self.stat_console, 1,
                                  field_console_height + i_line,
                                  tcod.BKGND_NONE, tcod.LEFT, line)
            i_line += 1

        tcod.console_blit(self.stat_console, 0, 0, stat_console_width,
                          stat_console_height, 0, field_console_width, 0)
Пример #23
0
def test_console_defaults(console, fg, bg):
    libtcodpy.console_set_default_foreground(console, fg)
    libtcodpy.console_set_default_background(console, bg)
    libtcodpy.console_clear(console)
    assert_char(console, 0, 0, None, fg, bg)
Пример #24
0
 def draw(self):
     tcod.console_set_default_foreground(con, self.color)
     tcod.console_put_char(con, self.x, self.y, self.char, tcod.BKGND_NONE)
Пример #25
0
def draw_entity_part(con, alt_x, alt_y, entity_part, part_color):
    tcod.console_set_default_foreground(con, part_color)
    tcod.console_put_char(con, alt_x, alt_y, entity_part, tcod.BKGND_NONE)
Пример #26
0
def test_console_defaults(console, fg, bg):
    libtcodpy.console_set_default_foreground(console, fg)
    libtcodpy.console_set_default_background(console, bg)
    libtcodpy.console_clear(console)
    assert_char(console, 0, 0, None, fg, bg)
        playerx -= 1
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
        playerx += 1
 
 
#############################################
# Initialization & Main Loop
#############################################
 
libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/libtcod tutorial', False)
libtcod.sys_set_fps(LIMIT_FPS)
 
playerx = SCREEN_WIDTH//2
playery = SCREEN_HEIGHT//2
 
while not libtcod.console_is_window_closed():
 
    libtcod.console_set_default_foreground(0, libtcod.white)
    libtcod.console_put_char(0, playerx, playery, '@', libtcod.BKGND_NONE)
 
    libtcod.console_flush()
 
    libtcod.console_put_char(0, playerx, playery, ' ', libtcod.BKGND_NONE)
 
    #handle keys and exit game if needed
    exit = handle_keys()
    if exit:
        break
Пример #28
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, colors, game_state):
    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = fov_map.fov[y][x]
                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)

    for entity in entities_in_render_order:
        if fov_map.fov[entity.y][entity.x] or (
                entity.stairs and game_map.tiles[entity.x][entity.y].explored):
            draw_entity(con, entity)

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

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

    libtcod.console_print_ex(
        panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
        "Dungeon level: {}".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))

    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

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

    inventory_title = None
    if game_state == GameStates.SHOW_INVENTORY:
        inventory_title = "Press the key next to an item to use it, or Esc to cancel.\n"
    elif game_state == GameStates.DROP_INVENTORY:
        inventory_title = "Press the key next to an item to drop it, or Esc to cancel.\n"

    if inventory_title != None:
        inventory_menu(con, inventory_title, player, player.inventory, 50,
                       screen_width, screen_height)

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

    if game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)
 def draw(self):
     #only show if it's visible to the player
     if libtcod.map_is_in_fov(fov_map, self.x, self.y):
         #set the color and then draw the character that represents this object at its position
         libtcod.console_set_default_foreground(con, self.color)
         libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_NONE)
Пример #30
0
 def _render_selection(self, selected_row, selected_column, left_most_column):
     """
         Render the information on which row, column is currently selected.
     """
     libtcod.console_set_default_foreground(self.console, settings.POKEDEX_LINE_COLOR)
     libtcod.console_put_char(self.console, (selected_column - left_most_column) * PokedexRenderer.column_width + 19, selected_row + PokedexRenderer.header_height + 1, '<')
def render_all():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute
 
    if fov_recompute:
        #recompute FOV if needed (the player moved or something)
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO)
 
        #go through all tiles, and set their background color according to the FOV
        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = map[x][y].block_sight
                if not visible:
                    #if it's not visible right now, the player can only see it if it's explored
                    if map[x][y].explored:
                        if wall:
                            libtcod.console_set_char_background(con, x, y, color_dark_wall, libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_char_background(con, x, y, color_dark_ground, libtcod.BKGND_SET)
                else:
                    #it's visible
                    if wall:
                        libtcod.console_set_char_background(con, x, y, color_light_wall, libtcod.BKGND_SET )
                    else:
                        libtcod.console_set_char_background(con, x, y, color_light_ground, libtcod.BKGND_SET )
                    #since it's visible, explore it
                    map[x][y].explored = True
 
    #draw all objects in the list, except the player. we want it to
    #always appear over all other objects! so it's drawn later.
    for object in objects:
        if object != player:
            object.draw()
    player.draw()
 
    #blit the contents of "con" to the root console
    libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0)
 
 
    #prepare to render the GUI panel
    libtcod.console_set_default_background(panel, libtcod.black)
    libtcod.console_clear(panel)
 
    #print the game messages, one line at a time
    y = 1
    for (line, color) in game_msgs:
        libtcod.console_set_default_foreground(panel, color)
        libtcod.console_print_ex(panel, MSG_X, y, libtcod.BKGND_NONE, libtcod.LEFT, line)
        y += 1
 
    #show the player's stats
    render_bar(1, 1, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp,
        libtcod.light_red, libtcod.darker_red)
 
    #display names of objects under the mouse
    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())
 
    #blit the contents of "panel" to the root console
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
 def draw(self):
         #set the color and then draw the character that represents this object at its position
         libtcod.console_set_default_foreground(con, self.color)
         libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_NONE)
Пример #33
0
def draw_entity(con, entity, fov_map, game_map):
    if libtcod.map_is_in_fov(fov_map, entity.x, entity.y) or (
            entity.stairs and game_map.tiles[entity.x][entity.y].explored):
        libtcod.console_set_default_foreground(con, entity.color)
        libtcod.console_put_char(con, entity.x, entity.y, entity.char,
                                 libtcod.BKGND_NONE)
Пример #34
0
    def render(self, console):
        if not self.render_next:
            return

        self.target_tiles = []

        if self.mode == MapMode.TARGETING:
            if self.target_mode == AbilityTargeting.LOS:
                line = line_where(self.player.entity.x, self.player.entity.y,
                                  self.target_x, self.target_y, False)
                for _ in range(len(line[0])):
                    self.target_tiles.append(
                        self.game_map.field[line[0][_]][line[1][_]])

        dx = -(self.player.entity.x - int(field_console_width / 2))
        dy = -(self.player.entity.y - int(field_console_height / 2))

        if self.fov_recompute:
            recompute_fov(self.game_map.fov_map, self.player.entity.x,
                          self.player.entity.y, 10)

            for x in range(self.game_map.width):
                for y in range(self.game_map.height):
                    if x < self.player.entity.x - int(field_console_width / 2) \
                            or x > self.player.entity.x + int(field_console_width / 2) \
                            or y < self.player.entity.y - int(field_console_height / 2) \
                            or y > self.player.entity.y + int(field_console_height / 2):
                        continue
                    visible = tcod.map_is_in_fov(self.game_map.fov_map, x, y)

                    if visible:
                        tcod.console_set_char_background(
                            self.field_console, x + dx, y + dy,
                            self.game_map.field[x][y].background_color,
                            tcod.BKGND_SET)
                        if self.mode == MapMode.TARGETING:
                            if abs(x - self.player.entity.x) > self.target_distance \
                                    or abs(y - self.player.entity.y) > self.target_distance:
                                tcod.console_set_char_background(
                                    self.field_console, x + dx, y + dy,
                                    (60, 60, 60), tcod.BKGND_DARKEN)
                            if self.game_map.field[x][y] in self.target_tiles:
                                tcod.console_set_char_background(
                                    self.field_console, x + dx, y + dy,
                                    (60, 40, 40), tcod.BKGND_ADD)
                            if x == self.target_x and y == self.target_y:
                                tcod.console_set_char_background(
                                    self.field_console, x + dx, y + dy,
                                    (60, 40, 20), tcod.BKGND_ADD)
                        self.game_map.field[x][y].explored = True
                    elif self.game_map.field[x][y].explored:
                        tcod.console_set_char_background(
                            self.field_console, x + dx, y + dy,
                            self.game_map.field[x][y].background_color_dark,
                            tcod.BKGND_SET)
                    else:
                        tcod.console_set_char_background(
                            self.field_console, x + dx, y + dy, tcod.black,
                            tcod.BKGND_SET)
                    if (visible or self.game_map.field[x][y].explored
                        ) and self.game_map.field[x][y].stairs:
                        tcod.console_put_char(self.field_console, x + dx,
                                              y + dy, '>', tcod.BKGND_NONE)

        for x in range(field_console_width):
            for y in range(field_console_height):
                if x < (int(field_console_width / 2) - self.player.entity.x) \
                        or x > (self.game_map.width - 1 - self.player.entity.x + int(field_console_width / 2)) \
                        or y < (int(field_console_height / 2) - self.player.entity.y) \
                        or y > (self.game_map.height - 1 - self.player.entity.y + int(field_console_height / 2)):
                    tcod.console_set_char_background(self.field_console, x, y,
                                                     tcod.black,
                                                     tcod.BKGND_SET)

        for entity in self.game_map.entities:
            if entity.x < self.player.entity.x - int(field_console_width / 2) \
                    or entity.x > self.player.entity.x + int(field_console_width / 2) \
                    or entity.y < self.player.entity.y - int(field_console_height / 2) \
                    or entity.y > self.player.entity.y + int(field_console_height / 2):
                continue
            if not tcod.map_is_in_fov(self.game_map.fov_map, entity.x,
                                      entity.y):
                continue
            # Don't render an item entity if there's already one on this tile
            if isinstance(entity, ItemEntity) and self.game_map.get_monster_at(
                    entity.x, entity.y) is not None:
                continue
            # Don't render a dead entity if there's already one on this tile
            if isinstance(entity, MonsterEntity) \
                    and entity.dead \
                    and self.game_map.get_monster_at(entity.x, entity.y) is not None:
                continue
            tcod.console_set_default_foreground(self.field_console,
                                                entity.get_color())
            tcod.console_put_char(self.field_console,
                                  entity.x + dx, entity.y + dy,
                                  entity.get_char(), tcod.BKGND_NONE)

        tcod.console_blit(self.field_console, 0, 0, field_console_width,
                          field_console_height, 0, 0, 0)
        self.render_stats()
        self.render_log()
Пример #35
0
 def default_foreground_color(self, color):
     tcod.console_set_default_foreground(self._c, color)
Пример #36
0
def render_all(game_state, con, panel, mouse, entities, player, game_map,
               fov_map, light_map, camera, message_log, fov_recompute,
               screen_width, screen_height, bar_width, panel_height, panel_y,
               colors):
    # fov 재계산 시만
    if fov_recompute:
        #tcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)
        con.clear()
        for y in range(game_map.height):
            for x in range(game_map.width):
                # 지도 위치
                Mapx = x + camera.x
                Mapy = y + camera.y

                #print(F"{camera.x},{camera.y}")

                # wall 불리언에 tile의 block_sight이 True인지 여부를 대입
                visible = fov_map.fov[y, x]
                wall = game_map.tiles[y, x].block_sight

                if light_map[y, x] == 999:
                    brightness = 0
                else:
                    brightness = light_map[y, x]

                if visible:
                    game_map.tiles[y, x].explored = True
                    if wall:
                        draw_background(con, Mapx, Mapy, 'light_wall',
                                        brightness)
                    else:
                        draw_background(con, Mapx, Mapy, 'light_ground',
                                        brightness)
                elif game_map.tiles[y, x].explored:
                    if wall:
                        draw_background(con, Mapx, Mapy, 'dark_wall')
                    else:
                        draw_background(con, Mapx, Mapy, 'dark_ground')
                else:
                    draw_background(con, Mapx, Mapy, 'pitch_black')

    # 목록에 있는 모든 객체를 표시함.
    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, camera)

    tcod.console_blit(con, 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 = 2
    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_set_default_foreground(panel, tcod.light_gray)
    tcod.console_print_ex(
        panel, 1, 0, tcod.BKGND_NONE, tcod.LEFT,
        get_names_under_mouse(mouse, camera, 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 = 'Use which? (Esc to exit)\n'
        else:
            inventory_title = 'Drop which? , or Esc to cancel.\n'
        inventory_menu(con, inventory_title, player._Inventory,
                       screen_width - 2, screen_width, screen_height)
Пример #37
0
def main():
    # Setting the screen size
    screen_width = 80
    screen_height = 50

    # Variables to keep track of player position
    player_x = int(screen_width/2)
    player_y = int(screen_height/2)

    # Telling libtcod which font to use. We read the font details from the arial10x10.png file that we saved down.
    # The other two parts are telling libtcod which type of file we're reading.
    libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    # This line actually creates the screen, using the screen heigh and width that we specified.
    # The boolean at the end tells it whether to go full screen or not.
    libtcod.console_init_root(screen_width, screen_height, 'Adversarial Attacker', False)

    # Define console
    con = libtcod.console_new(screen_width, screen_height)

    # Variables to hold our keyboard and mouse inputs.
    key = libtcod.Key()
    mouse = libtcod.Mouse()

    # This begins what's called our 'game loop'. This won't end until we close the game.
    while not libtcod.console_is_window_closed():

        # This line captures new events (inputs from the user)
        # This updates the key variable with the user input but doesn't actually do anything with it yet.
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)

        # Provides the font color for our foreground, which is our '@' symbol.
        # The first arguement is the console we're drawing to.
        libtcod.console_set_default_foreground(con, libtcod.white)

        # The first argument is the console we're printing to again.
        # The second and third arguments are x and y coordinates for where to draw.
        # The third argument is what to draw.
        # The fourth argument sets the background to none.
        libtcod.console_put_char(con, player_x, player_y, "@", libtcod.BKGND_NONE)
        
        # This part actually draws our symbol.
        libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

        # This line presents everything on the screen.
        libtcod.console_flush()

        # Removes the trailing '@' symbol when we move (so that we don't create a snake).
        libtcod.console_put_char(con, player_x, player_y, ' ', libtcod.BKGND_NONE)

        # Use the handle_keys function that we created to translate our key press into an action.
        action = handle_keys(key)

        # Grab our actions (if they exist)
        move = action.get('move')
        exit = action.get('exit')
        fullscreen = action.get('fullscreen')

        # Carry out our movement action if it exists.
        if move:
            # Set dx and dy values to our move coordinates.
            dx, dy = move
            # Update player (x,y) position using (dx,dy).
            player_x += dx
            player_y += dy

        # Exit the game if that was the action taken by the user.
        if exit:
            return True

        # Go fullscreen if that was the action taken by the user.
        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) 
Пример #38
0
def draw_entity(god, con, entity, fov_map):
    if entity_in_fov(god, entity, fov_map):
        tcod.console_set_default_foreground(con, entity.color)
        tcod.console_put_char(con, entity.x, entity.y, entity.char, tcod.BKGND_NONE)
Пример #39
0
 def draw(self):
     if tcod.map_is_in_fov(fovMap, self.x, self.y):
         tcod.console_set_default_foreground(con, self.color)
         tcod.console_put_char(con, self.x, self.y, self.char, tcod.BKGND_NONE)
Пример #40
0
 def explored_draw(self, topx, topy) -> None:
     tcod.console_set_default_foreground(0, self.explored_color)
     #find the offset coordinates and draw to that point on the screen
     tcod.console_put_char(0, self.x - topx, self.y - topy, self.char,
                           tcod.BKGND_NONE)
Пример #41
0
def render_all():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute

    if fov_recompute:
        #recompute FOV if needed (the player moved or something)
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS,
                                FOV_LIGHT_WALLS, FOV_ALGO)

        #go through all tiles, and set their background color according to the FOV
        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = map[x][y].block_sight
                if not visible:
                    #if it's not visible right now, the player can only see it if it's explored
                    if map[x][y].explored:
                        if wall:
                            libtcod.console_set_char_background(
                                con, x, y, color_dark_wall, libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_char_background(
                                con, x, y, color_dark_ground,
                                libtcod.BKGND_SET)
                else:
                    #it's visible
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, color_light_wall, libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, color_light_ground, libtcod.BKGND_SET)
                    #since it's visible, explore it
                    map[x][y].explored = True

    #draw all objects in the list, except the player. we want it to
    #always appear over all other objects! so it's drawn later.
    for object in objects:
        if object != player:
            object.draw()
    player.draw()

    #blit the contents of "con" to the root console
    libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0)

    #prepare to render the GUI panel
    libtcod.console_set_default_background(panel, libtcod.black)
    libtcod.console_clear(panel)

    #print the game messages, one line at a time
    y = 1
    for (line, color) in game_msgs:
        libtcod.console_set_default_foreground(panel, color)
        libtcod.console_print_ex(panel, MSG_X, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, line)
        y += 1

    #show the player's stats
    render_bar(1, 1, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp,
               libtcod.light_red, libtcod.darker_red)

    #display names of objects under the mouse
    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())

    #blit the contents of "panel" to the root console
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                         PANEL_Y)
Пример #42
0
def render_inv(root_console, inv_panel, player, map_width, sch_height):
    """
    Render the right panel (features, weapons, inventory) except time
    """
    tcod.console_clear(inv_panel)
    default_fore = const.base0
    tcod.console_set_default_foreground(inv_panel, default_fore)
    w = inv_panel.width

    # Features
    y = 0
    tcod.console_set_default_foreground(inv_panel, default_fore)
    inv_panel.print_frame(0, y, w, 5 * 3 + 1, string="Features")
    for fslot in const.FeatureSlot:
        y += 1
        feature = player.fequiped.get(fslot)
        tcod.console_set_char_background(inv_panel, 1, y,
                                         fslot.value.get("color"),
                                         tcod.BKGND_SET)
        if feature:
            render_feature(inv_panel, feature, default_fore, y, player)
            y += 2
        else:
            tcod.console_set_default_foreground(inv_panel, const.base02)
            tcod.console_print_ex(inv_panel, 3, y, tcod.BKGND_NONE, tcod.LEFT,
                                  "(none)")
            y += 1
            tcod.console_print_ex(inv_panel, 3, y, tcod.BKGND_NONE, tcod.LEFT,
                                  fslot.value.get("name"))
            y += 1

    y += 1
    tcod.console_set_default_foreground(inv_panel, default_fore)

    inv_panel.print_frame(0, y, w, 3, string="Resistance")
    y += 1
    x = 2
    at_least_one = False
    for fslot in const.FeatureSlot:
        r = player.resistances.get(fslot)
        if r > 0:
            at_least_one = True
            tcod.console_set_char_background(inv_panel, x, y,
                                             fslot.value.get("color"),
                                             tcod.BKGND_SET)
            x += 1
            if fslot in player.synergy:
                tcod.console_print_ex(inv_panel, x, y, tcod.BKGND_NONE,
                                      tcod.LEFT, ":" + str(r) + "*")
            else:
                tcod.console_print_ex(inv_panel, x, y, tcod.BKGND_NONE,
                                      tcod.LEFT, ":" + str(r))
            x += 4
        else:
            x += 5
    if not at_least_one:
        tcod.console_set_default_foreground(inv_panel, const.base02)
        tcod.console_print_ex(inv_panel, int(w / 2), y, tcod.BKGND_NONE,
                              tcod.CENTER, "(none)")

    tcod.console_set_default_foreground(inv_panel, default_fore)
    y += 2
    inv_panel.print_frame(0, y, w, 3 * 3 + 1, string="Weapons")

    for wslot in const.WeaponSlot:
        y += 1
        weapon = player.wequiped.get(wslot)
        if weapon:
            render_weapon(inv_panel, weapon, default_fore, y,
                          weapon == player.active_weapon)
            y += 1
        else:
            tcod.console_set_default_foreground(inv_panel, const.base02)
            tcod.console_print_ex(inv_panel, 1, y, tcod.BKGND_NONE, tcod.LEFT,
                                  wslot.value.get("key") + " (none)")
            y += 1
            tcod.console_print_ex(inv_panel, 3, y, tcod.BKGND_NONE, tcod.LEFT,
                                  wslot.value.get("name"))
            string = str(round(
                wslot.value.get("success_rate_base") * 100)) + "% " + str(
                    wslot.value.get("duration_base")) + "s"
            if wslot.value.get("unstable"):
                string = "Stab- " + string
            tcod.console_print_ex(inv_panel, w - 1, y, tcod.BKGND_NONE,
                                  tcod.RIGHT, string)
        y += 1

    y += 1

    tcod.console_set_default_foreground(inv_panel, default_fore)
    inv_panel.print_frame(0, y, w, 5 * 3 + 1, string="Inventory")

    for k in player.inventory:
        y += 1
        item = player.inventory.get(k)
        if item:
            if isinstance(item, ent.Weapon):
                render_weapon(inv_panel, item, default_fore, y, False)
                tcod.console_put_char(inv_panel, 1, y, k, tcod.BKGND_NONE)
            else:
                render_feature(inv_panel, item, default_fore, y, player)
            tcod.console_set_default_foreground(inv_panel, default_fore)
            tcod.console_put_char(inv_panel, 1, y, k, tcod.BKGND_NONE)
        else:
            tcod.console_set_default_foreground(inv_panel, const.base02)
            tcod.console_print_ex(inv_panel, 1, y, tcod.BKGND_NONE, tcod.LEFT,
                                  k + " (none)")
        y += 2

    inv_panel.blit(dest=root_console, dest_x=map_width, dest_y=sch_height)
Пример #43
0
def help_screen(help_screen_width, help_screen_height, screen_width,
                screen_height):
    window = libtcod.console_new(help_screen_width, help_screen_height)

    libtcod.console_set_default_foreground(window, libtcod.white)

    libtcod.console_print_rect_ex(window, 0, 1, help_screen_width,
                                  help_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'List of Game Commands')
    libtcod.console_print_rect_ex(window, 0, 3, help_screen_width,
                                  help_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Pick up: comma')
    libtcod.console_print_rect_ex(window, 0, 5, help_screen_width,
                                  help_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Move: arrow keys, num pad')
    libtcod.console_print_rect_ex(window, 0, 7, help_screen_width,
                                  help_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT,
                                  'Wait: full stop / 5 on num pad')
    libtcod.console_print_rect_ex(window, 0, 9, help_screen_width,
                                  help_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Down stairs: space')
    libtcod.console_print_rect_ex(window, 0, 11, help_screen_width,
                                  help_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Help menu: \'h\'')
    libtcod.console_print_rect_ex(window, 0, 13, help_screen_width,
                                  help_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Inventory menu: \'i\'')
    libtcod.console_print_rect_ex(window, 0, 15, help_screen_width,
                                  help_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Drop menu: \'d\'')
    libtcod.console_print_rect_ex(window, 0, 17, help_screen_width,
                                  help_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Character screen: \'c\'')
    libtcod.console_print_rect_ex(window, 0, 19, help_screen_width,
                                  help_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Cancel/exit anything: esc')
    libtcod.console_print_rect_ex(window, 0, 21, help_screen_width,
                                  help_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Full screen: Alt-Enter')
    libtcod.console_print_rect_ex(
        window, 0, 23, help_screen_width, help_screen_height,
        libtcod.BKGND_NONE, libtcod.LEFT,
        'Using menus: a-z(signified beside the option)')
    libtcod.console_print_rect_ex(window, 0, 25, help_screen_width,
                                  help_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT,
                                  'What\'s that?: hover with mouse')
    libtcod.console_print_rect_ex(
        window, 0, 27, help_screen_width, help_screen_height,
        libtcod.BKGND_NONE, libtcod.LEFT,
        'If an item is a piece of armour or weapon(excluding bows): select it in inventory menu to (d)equip'
    )
    libtcod.console_print_rect_ex(window, 0, 31, help_screen_width,
                                  help_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT,
                                  'Any other item is instant use')
    libtcod.console_print_rect_ex(
        window, 0, 33, help_screen_width, help_screen_height,
        libtcod.BKGND_NONE, libtcod.LEFT,
        'Most items are fairly self-explanatory(antidotes), but scrolls can make monsters move randomly(confusion), hit the nearest monster(lightning), deal AOE damage(fireball) or freeze a monster(freeze)'
    )
    libtcod.console_print_rect_ex(
        window, 0, 40, help_screen_width, help_screen_height,
        libtcod.BKGND_NONE, libtcod.LEFT,
        'If in doubt: read the message bar/ask me!!')
    libtcod.console_print_rect_ex(window, 0, 42, help_screen_width,
                                  help_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT,
                                  'Game automatically saves with esc')

    x = screen_width // 2 - help_screen_width // 2
    y = screen_height // 2 - help_screen_width // 2
    libtcod.console_blit(window, 0, 0, help_screen_width, help_screen_height,
                         0, x, y, 1.0, 0.7)
Пример #44
0
def draw_entity(con, entity, fov_map):
    if libtcod.map_is_in_fov(fov_map, entity.x, entity.y):
        libtcod.console_set_default_foreground(con, entity.color)
        libtcod.console_put_char(con, entity.x, entity.y, entity.char,
                                 libtcod.BKGND_NONE)
Пример #45
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, colors, game_state, graphics):
    """
    Affiche les pièces, les entites, les menus, et tous les éléments du jeu

    Parametres:
    ----------
    con : tcod.console

    panel : tcod.console

    entities : list

    player : Entity

    game_map : GameMap

    fov_map : tcod.map

    fov_recompute : bool

    message_log : MessageLog

    screen_width : int

    screen_height : int

    bar_width : int

    panel_heidght : int

    panel_y : int

    mouse : tcod.mouse

    colors : tcod.colors
        Désormais non utilisé

    game_state : int

    graphics : dict


    Renvoi:
    -------
    Aucun

    """
    if fov_recompute:
        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_put_char_ex(con, x, y,
                                                    graphics.get('wall'),
                                                    libtcod.white,
                                                    libtcod.black)
                    else:
                        libtcod.console_put_char_ex(con, x, y,
                                                    graphics.get('floor'),
                                                    libtcod.white,
                                                    libtcod.black)
                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    if wall:
                        libtcod.console_put_char_ex(con, x, y,
                                                    graphics.get('wall'),
                                                    libtcod.light_grey,
                                                    libtcod.black)
                    else:
                        libtcod.console_put_char_ex(con, x, y,
                                                    graphics.get('floor'),
                                                    libtcod.light_grey,
                                                    libtcod.black)
    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)
        if entity.ai:
            if entity.ai.ai_name == 'Boss':
                if entity.ai.aoeing:
                    if entity.ai.turn % 10 == 0:
                        color = libtcod.lightest_red
                    elif entity.ai.turn % 10 == 1:
                        color = libtcod.lighter_red
                    elif entity.ai.turn % 10 == 2:
                        color = libtcod.light_red
                    elif entity.ai.turn % 10 == 3:
                        color = libtcod.red
                    radius = entity.ai.radius
                    for x in range(entity.x - radius, entity.x + radius + 1):
                        for y in range(entity.y - radius,
                                       entity.y + radius + 1):
                            if ((x - entity.x)**2 +
                                (y - entity.y)**2)**0.5 <= radius:
                                libtcod.console_set_char_foreground(
                                    con, x, y, color)

    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)

    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_print_ex(
        panel, 1, 2, libtcod.BKGND_NONE, libtcod.LEFT,
        'Salle : {0} - LVL : {1}'.format(game_map.dungeon_level,
                                         player.level.current_level))
    boss_bar = False
    for entity in entities:
        if entity.name == 'Boss':
            boss_bar = True
            boss = entity.fighter
    if boss_bar:
        render_bar(panel, 1, 3, bar_width, 'Boss HP', boss.hp, boss.max_hp,
                   libtcod.orange, libtcod.darker_orange)
    else:
        render_bar(panel, 1, 3, bar_width, 'XP', player.level.current_xp,
                   player.level.experience_to_next_level, libtcod.light_purple,
                   libtcod.darker_purple)
    libtcod.console_print_ex(
        panel, 1, 4, libtcod.BKGND_NONE, libtcod.LEFT,
        'ATQ : {0} - DEF : {1}'.format(player.fighter.power,
                                       player.fighter.defense))

    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 = 'Echap pour quitter, A/B/C... pour utiliser.\n'
        else:
            inventory_title = 'Echap pour quitter, A/B/C... pour lacher\n'
        inventory_menu(con, inventory_title, player, 50, screen_width,
                       screen_height)
    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up, choisis une amelioration :', player, 40,
                      screen_width, screen_height)
    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)
Пример #46
0
    def _render_player(self, player):
        x, y = player.coords

        libtcod.console_set_default_foreground(self.console, settings.PLAYER_COLOR)
        libtcod.console_put_char(self.console, x - self.start_x, y - self.start_y, '@')
Пример #47
0
 def render(self):
     tcod.console_set_default_foreground(0, self.color)
     tcod.console_put_char(0, self.col, self.row,
                           self.symbol, tcod.BKGND_NONE)
Пример #48
0
def render_all():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute

    if fov_recompute:
        # recompute FOV if needed (the player moved or something)
        fov_recompute = False
        tcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO)

        # go through all tiles, and set their background color according to the FOV
        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = tcod.map_is_in_fov(fov_map, x, y)
                wall = map[x][y].block_sight
                if EXPLORE_MODE:
                    if not visible:
                        # it's out of the player's FOV
                        if map[x][y].explored:
                            if wall:
                                tcod.console_set_char_background(con, x, y, color_dark_wall, tcod.BKGND_SET)
                            else:
                                tcod.console_set_char_background(con, x, y, color_dark_ground, tcod.BKGND_SET)
                    else:
                        # it's visible
                        if wall:
                            tcod.console_set_char_background(con, x, y, color_light_wall, tcod.BKGND_SET)
                        else:
                            tcod.console_set_char_background(con, x, y, color_light_ground, tcod.BKGND_SET)

                        map[x][y].explored = True

                else:
                    if not visible:
                        # it's out of the player's FOV
                        if wall:
                            tcod.console_set_char_background(con, x, y, color_dark_wall, tcod.BKGND_SET)
                        else:
                            tcod.console_set_char_background(con, x, y, color_dark_ground, tcod.BKGND_SET)
                    else:
                        # it's visible
                        if wall:
                            tcod.console_set_char_background(con, x, y, color_light_wall, tcod.BKGND_SET)
                        else:
                            tcod.console_set_char_background(con, x, y, color_light_ground, tcod.BKGND_SET)

    # draw all objects in the list
    for object in objects:
        if object != player:
            object.draw()

    player.draw()

    # blit the contents of "con" to the root console
    tcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)

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

    message_y = 1

    for (line, color) in game_msgs:
        tcod.console_set_default_foreground(panel, color)
        tcod.console_print_ex(panel, MSG_X, message_y, tcod.BKGND_NONE, tcod.LEFT, line)
        message_y += 1

    tcod.console_set_default_foreground(panel, tcod.light_gray)
    name = get_names_under_mouse()
    print(name)
    tcod.console_print_ex(panel, 1, 0, tcod.BKGND_NONE, tcod.LEFT, name)

    render_bar(1, 1, BAR_WIDTH, "HP", player.fighter.hp, player.fighter.max_hp, tcod.light_red, tcod.darker_red)
    tcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
Пример #49
0
 def _render_lines(self):
     """
         Renders the lines which separate sections of the screen.
     """
     libtcod.console_set_default_foreground(self.console, settings.LINE_COLOR)
     libtcod.console_hline(self.console, 0, BattleRenderer.top_section_height, settings.SCREEN_WIDTH)
Пример #50
0
def draw_entity(con, entity):
    libtcod.console_set_default_foreground(con, entity.color)
    libtcod.console_put_char(con, entity.x, entity.y, entity.char,
                             libtcod.BKGND_NONE)
Пример #51
0
 def draw(self):
      if tcod.map_is_in_fov(fov_map, self.axis_X, self.axis_Y):
          tcod.console_set_default_foreground(char_con, self.color)
          tcod.console_put_char(char_con, self.axis_X, self.axis_Y, self.character, tcod.BKGND_NONE)
Пример #52
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, colors, game_state):
    # Draw all the tiles in the game map
    if fov_recompute:
        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)
    libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
                             f'dungeon level: {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, 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)
Пример #53
0
 def drawChar(self, drawInfo):
     if drawInfo[1]:
         libtcod.console_set_default_foreground(drawInfo[0], drawInfo[1])
     libtcod.console_put_char(drawInfo[0], drawInfo[2], drawInfo[3],
                              drawInfo[4], libtcod.BKGND_NONE)
     libtcod.console_set_default_foreground(drawInfo[0], libtcod.white)