Exemplo n.º 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
 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)
Exemplo n.º 3
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)
Exemplo n.º 4
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, '=')
Exemplo n.º 5
0
def test_alpha_blend(console):
    for i in range(256):
        libtcodpy.console_put_char(console, 0, 0, 'x',
                                   libtcodpy.BKGND_ALPHA(i))
        libtcodpy.console_put_char(console, 0, 0, 'x',
                                   libtcodpy.BKGND_ADDALPHA(i))
Exemplo n.º 6
0
def clear_entity(con, entity):
    tcod.console_put_char(con, entity.x, entity.y, ' ', tcod.BKGND_NONE)
Exemplo n.º 7
0
def clear_entity(con, entity):
    # erase the character that represents this object
    tcod.console_put_char(con, entity.x, entity.y, ' ', tcod.BKGND_NONE)
def clear_gameobject(con, object):
    # Set the color
    tcod.console_set_default_foreground(con, object.color)
    # Draw the object rep on to the console
    tcod.console_put_char(con, object.x, object.y, " ", tcod.BKGND_NONE)
Exemplo n.º 9
0
def clear_entity(console, entity):
    libtcod.console_set_default_background(console, libtcod.black)
    libtcod.console_put_char(console, entity.x, entity.y, ' ',
                             libtcod.BKGND_SET)
Exemplo n.º 10
0
 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)
Exemplo n.º 11
0
 def clear(self):        # Erase Character
     tcod.console_put_char(con, self.x, self.y, ' ', tcod.BKGND_NONE)
Exemplo n.º 12
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, '@')
Exemplo n.º 13
0
def clear_entity(con, entity):
    # Erase character representing the entity
    libtcod.console_put_char(con, entity.x, entity.y, ' ', libtcod.BKGND_NONE)
Exemplo n.º 14
0
 def draw(self):         # Draw Character
     if tcod.map_is_in_fov(FOV_map, 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)
Exemplo n.º 15
0
def clear_entity(con, entity):
	#rease teh char that represents this object
	libtcod.console_put_char(con, entity.x, entity.y, ' ', libtcod.BKGND_NONE)
Exemplo n.º 16
0
 def put_cell(self, x, y, sym, flag=tcod.BKGND_NONE):
     tcod.console_put_char(self._c, x, y, sym, flag)
Exemplo n.º 17
0
 def draw(self):
     # only show if it's visible to the player
     if libtcod.map_is_in_fov(fov_map, int(self.x), int(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, int(self.x), int(self.y), self.char, libtcod.BKGND_NONE)
Exemplo n.º 18
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 = libtcodpy.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    if wall:
                        libtcodpy.console_put_char(con, x, y, '#',
                                                   libtcodpy.BKGND_SET)
                        libtcodpy.console_set_char_foreground(
                            con, x, y, colors.get('light_wall'))
                    else:
                        libtcodpy.console_put_char(con, x, y, '.',
                                                   libtcodpy.BKGND_SET)
                        libtcodpy.console_set_char_foreground(
                            con, x, y, colors.get('light_ground'))

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

    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)

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

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

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

    # Draw health bar
    render_bar(panel, 1, 2, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, libtcodpy.Color(245, 56, 2),
               libtcodpy.Color(138, 20, 0))
    libtcodpy.console_print_ex(
        panel, 1, 4, libtcodpy.BKGND_NONE, libtcodpy.LEFT,
        'Dungeon Level: {0}'.format(game_map.dungeon_level))

    # Draw names
    libtcodpy.console_set_default_foreground(panel,
                                             libtcodpy.Color(231, 93, 16))
    libtcodpy.console_print_ex(panel, 1, 0, libtcodpy.BKGND_NONE,
                               libtcodpy.LEFT,
                               get_names_under_mouse(mouse, entities, fov_map))

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

    # Draw Inventory
    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Inventory'
            color = libtcodpy.Color(66, 190, 255)
        else:
            inventory_title = 'Inventory'
            color = libtcodpy.Color(169, 0, 32)

        inventory_menu(con, inventory_title, player, 50, screen_width,
                       screen_height, color)

    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, 15, screen_width, screen_height)
    character_equipment_screen(player, 30, 10, screen_width)
    help_screen(30, 15, screen_width)

    # Draw Inventory on Side
    if game_state not in (GameStates.SHOW_INVENTORY,
                          GameStates.DROP_INVENTORY):
        inventory_menu(con, 'Inventory', player, 50, screen_width,
                       screen_height, libtcodpy.Color(121, 121, 121))
Exemplo n.º 19
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)
Exemplo n.º 20
0
def test_alpha_blend(console):
    for i in range(256):
        libtcodpy.console_put_char(console, 0, 0, 'x',
                                   libtcodpy.BKGND_ALPHA(i))
        libtcodpy.console_put_char(console, 0, 0, 'x',
                                   libtcodpy.BKGND_ADDALPHA(i))
Exemplo n.º 21
0
def clear_entity(con, entity, camera_x, camera_y):
    # erase the character that represents this object
    libtcod.console_put_char(con, entity.x - camera_x, entity.y - camera_y, ' ', libtcod.BKGND_NONE)
Exemplo n.º 22
0
def draw_entity(console, entity):
    libtcod.console_set_default_background(console, entity.bg_color)
    libtcod.console_set_default_foreground(console, entity.fg_color)
    libtcod.console_put_char(console, entity.x, entity.y, entity.char,
                             libtcod.BKGND_SET)
Exemplo n.º 23
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, camera, cursor):
   
    # Draw all the tiles in the game map
    if fov_recompute:
        for y in range(camera.y, camera.y2):
            for x in range(camera.x, camera.x2):
                tile_type = game_map.tiles[x][y].tile_type
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                # Decide on color names.
                light_color_name = 'light_' + tile_type
                dark_color_name = 'dark_' + tile_type
                # Convert the map coords to console coords
                console_x = x - camera.x
                console_y = y - camera.y

                # If the player can see it, make it explored and use the light color.
                if visible:
                    game_map.tiles[x][y].explored = True

                    if tile_type == 'nothing':
                        libtcod.console_put_char_ex(con, console_x, console_y, '?', libtcod.blue, libtcod.dark_blue)
                    else:
                        libtcod.console_set_char_background(con, console_x, console_y, colors.get(light_color_name), libtcod.BKGND_SET)
                
                # If I can't see it, but it was explored already, use the dark color.
                elif game_map.tiles[x][y].explored:
                    
                    if tile_type == 'nothing':
                        libtcod.console_put_char_ex(con, console_x, console_y, '?', libtcod.dark_blue, libtcod.black)
                    else:
                        libtcod.console_set_char_background(con, console_x, console_y, colors.get(dark_color_name), libtcod.BKGND_SET)
                
                # I can neither see it, nor has it been explored. Color it black.
                elif not visible and not game_map.tiles[x][y].explored:
                    if tile_type == 'nothing':
                        libtcod.console_put_char_ex(con, console_x, console_y, '?', libtcod.red, libtcod.dark_red)
                    else:
                        libtcod.console_put_char(con, console_x, console_y, ' ', libtcod.BKGND_NONE)
                        libtcod.console_set_char_background(con, console_x, console_y, libtcod.black, 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:
        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 - camera.x, entity.y - camera.y, entity.char, libtcod.BKGND_NONE) # TODO: Can the entity know it's screen position?

    # Draw the cursor, if there is one
    if game_state in (GameStates.LOOK, GameStates.TARGETING):
        libtcod.console_set_default_foreground(con, cursor.color)
        libtcod.console_put_char(con, cursor.x - camera.x, cursor.y - camera.y, cursor.char, libtcod.BKGND_NONE)

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

    # Prepare the panel console
    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

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

    # Print what is 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(entities, fov_map, camera.x, camera.y, mouse=mouse))

    # Print what is under the cursor
    if game_state in (GameStates.LOOK, GameStates.TARGETING):
        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(entities, fov_map, camera.x, camera.y, cursor=cursor))

    # Finish panel console.
    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y)

    # Show the Inventory menu
    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)
    
    # Show the Level Up menu
    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up! Choose a stat to raise:', player, 40, screen_width, screen_height)

    # Show the Character screen
    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)

    # Show the Materia Extraction menu
    elif game_state == GameStates.MATERIA_SCREEN:
        materia_extraction_menu(con, 'Materia Extraction menu', player.inventory, 50, screen_width, screen_height)
Exemplo n.º 24
0
 def draw_entity(self, con, entity, fov):
     """Draws a single entity."""
     if tcod.map_is_in_fov(fov.map, entity.x, entity.y):
         tcod.console_put_char(con, entity.x, entity.y,
                               entity.tile, tcod.BKGND_NONE)
Exemplo n.º 25
0
def draw_entity(con, entity):
    con.default_fg = (entity.colour)
    libtcod.console_put_char(con, entity.x, entity.y, entity.char,
                             libtcod.BKGND_NONE)
Exemplo n.º 26
0
 def clear(self):
     #erase the character that represents this object
     libtcod.console_put_char(con, self.x, self.y, ' ', libtcod.BKGND_NONE)
Exemplo n.º 27
0
 def clear(self):
     tcod.console_put_char(con, self.x, self.y, ' ', tcod.BKGND_NONE)
Exemplo n.º 28
0
def draw_entity(con, entity, fov_map):
    if tcod.map_is_in_fov(fov_map, entity.x, entity.y):
        tcod.console_set_default_foreground(con, entity.color)
        tcod.console_put_char(con, entity.x, entity.y, entity.char, tcod.BKGND_NONE)
Exemplo n.º 29
0
def clear_entity(con, entity):
    # erase char for this Entity
    libtcod.console_put_char(con, entity.x, entity.y, ' ', libtcod.BKGND_NONE)
Exemplo n.º 30
0
def test_console_put_char(console, ch):
    libtcodpy.console_put_char(console, 0, 0, ch, libtcodpy.BKGND_SET)
    assert_char(console, 0, 0, ch=ch)
Exemplo n.º 31
0
 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)
Exemplo n.º 32
0
def draw_entity(con, entity, fov_map, game_map):
    if tcod.map_is_in_fov(fov_map, entity.x, entity.y) or (
            entity.stairs and game_map.tiles[entity.x][entity.y].explored):
        tcod.console_set_default_foreground(con, entity.color)
        tcod.console_put_char(con, entity.x, entity.y, entity.char,
                              tcod.BKGND_NONE)
        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
Exemplo n.º 34
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)
Exemplo n.º 35
0
def clear_entity(con, entity, fov_map):
    # Erase the character that represents this object
    if libtcodpy.map_is_in_fov(fov_map, entity.x, entity.y):
        libtcodpy.console_put_char(con, entity.x, entity.y, '.',
                                   libtcodpy.BKGND_NONE)
 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)
Exemplo n.º 37
0
def draw_entity(con, entity, fov_map, game_map):
    if libtcod.map_is_in_fov(fov_map, entity.location.x, entity.location.y):
        libtcod.console_set_default_foreground(con, entity.render.color)
        libtcod.console_put_char(con, entity.location.x, entity.location.y,
                                 entity.render.char, libtcod.BKGND_NONE)
Exemplo n.º 38
0
 def clear(self):
     #erase the character that represents this object
     libtcod.console_put_char(con, self.x, self.y, ' ', libtcod.BKGND_NONE)
Exemplo n.º 39
0
def clear_entity(con, entity):
    # erase the character that represents this object
    if entity.location is not None:
        libtcod.console_put_char(con, entity.location.x, entity.location.y,
                                 ' ', libtcod.BKGND_NONE)
Exemplo n.º 40
0
def test_console_put_char(console, ch):
    libtcodpy.console_put_char(console, 0, 0, ch, libtcodpy.BKGND_SET)
    assert_char(console, 0, 0, ch=ch)
Exemplo n.º 41
0
def erase_cell(con, x, y):
    """
    Some temporary cell fg and bg should stick around until the end of a phase.
    Those need to be manually erased.
    """
    libtcod.console_put_char(con, x, y, ' ', libtcod.BKGND_NONE)
Exemplo n.º 42
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, '<')
Exemplo n.º 43
0
 def _draw(self, x, y, char, color):
     libtcod.console_set_default_foreground(self.consoles_inventory.console, color)
     libtcod.console_put_char(self.consoles_inventory.console, x, y, char, libtcod.BKGND_NONE)