Example #1
0
    def __setitem__(self, index, cell):
        if isinstance(index, slice):
            raise TypeError('Console objects do not support slices. Yet.')
        x, y = index
        if x > self.width or x < 0 or y > self.height or y < 0:
            raise IndexError(
                'Attempt to access cell ({0}, {1}), which is out of range. Console size is ({2}, {3}).'.format(x, y,
                                                                                                               self.width,
                                                                                                               self.height))

        if isinstance(cell, tuple) and len(cell) >= 3:
            symbol, foreground, background = cell
            if isinstance(foreground, str):
                foreground = color.string_to_colornum(foreground)
            if isinstance(background, str):
                background = color.string_to_colornum(background)
        elif cell is not tuple:
            symbol = cell
            foreground = self.get_char_foreground(x, y)
            background = self.get_char_background(x, y)
        else:
            symbol = cell[0]
            foreground = cell[1]
            background = self.get_char_background(x, y)

        if background is None:
            background = self.get_char_background(x, y)

        if foreground is None:
            foreground = self.get_char_foreground(x, y)

        # tcod.console_set_char_background(self._c, x, y, background)
        # tcod.console_set_char_foreground(self._c, x, y, foreground)
        # tcod.console_put_char(self._c, x, y, symbol)
        tcod.console_put_char_ex(self._c, x, y, symbol, foreground, background)
Example #2
0
 def draw(self, con, x, y):
     tcod.console_put_char_ex(con,
                              x,
                              y,
                              self.symbol,
                              fore=self.color,
                              back=con.default_bg)
Example #3
0
def test_array_read_write():
    console = tcod.console.Console(width=12, height=10)
    FG = (255, 254, 253)
    BG = (1, 2, 3)
    CH = ord('&')
    tcod.console_put_char_ex(console, 0, 0, CH, FG, BG)
    assert console.ch[0, 0] == CH
    assert tuple(console.fg[0, 0]) == FG
    assert tuple(console.bg[0, 0]) == BG

    tcod.console_put_char_ex(console, 1, 2, CH, FG, BG)
    assert console.ch[2, 1] == CH
    assert tuple(console.fg[2, 1]) == FG
    assert tuple(console.bg[2, 1]) == BG

    console.clear()
    assert console.ch[1, 1] == ord(' ')
    assert tuple(console.fg[1, 1]) == (255, 255, 255)
    assert tuple(console.bg[1, 1]) == (0, 0, 0)

    ch_slice = console.ch[1, :]
    ch_slice[2] = CH
    console.fg[1, ::2] = FG
    console.bg[...] = BG

    assert tcod.console_get_char(console, 2, 1) == CH
    assert tuple(tcod.console_get_char_foreground(console, 2, 1)) == FG
    assert tuple(tcod.console_get_char_background(console, 2, 1)) == BG
Example #4
0
 def draw_entity(self, entry, fov_map):
     # put entity character on screen
     if fov_map.fov[entry.y, entry.x] or (
             entry.stairs
             and self.game_map.tiles[entry.x][entry.y].explored):
         tcod.console_put_char_ex(self.map_buffer, entry.x, entry.y,
                                  entry.char, entry.color, tcod.black)
Example #5
0
 def draw(self, target_console):
     """Updates and blits the windows's console buffer to another console."""
     tcod.console_print_frame(self.console, 0, 0, self.w, self.h, True, tcod.BKGND_DEFAULT)
     for index in range (len(self.contents)):
         tcod.console_print(self.console, 3, index+2, self.contents[index])
     tcod.console_put_char_ex(self.console, 2, self.selection+2, '>', tcod.white, tcod.black)
     tcod.console_blit(self.console, 0, 0, self.w, self.h, target_console, self.x, self.y, 1.0, 0.9)
def render(player, con, fov_map, check_explored):
    tcod.map_compute_fov(fov_map, player.xPos, player.yPos, TORCH_RADIUS,
                         FOV_LIGHT_WALLS, FOV_ALGO)

    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            visible = tcod.map_is_in_fov(fov_map, x, y)
            compute_fov = False
            wall = map[x][y].wall
            if not visible and (map[x][y].explored or not check_explored):
                if check_explored:
                    color = tcod.grey
                else:
                    color = tcod.light_grey

                if wall:
                    tcod.console_put_char_ex(con, x, y, '#', color, tcod.black)
                else:
                    tcod.console_put_char_ex(con, x, y, '.', color, tcod.black)

            if visible:
                map[x][y].explored = True
                if wall:
                    tcod.console_put_char_ex(con, x, y, '#', tcod.light_yellow,
                                             tcod.black)
                else:
                    tcod.console_put_char_ex(con, x, y, '.', tcod.light_yellow,
                                             tcod.black)

    tcod.console_put_char_ex(con, MAP_WIDTH - 2, MAP_HEIGHT - 2, 'X',
                             tcod.fuchsia, tcod.black)
    player.draw(con)
Example #7
0
    def __setitem__(self, index, cell):
        if isinstance(index, slice):
            raise TypeError('Console objects do not support slices. Yet.')
        x, y = index
        if x > self.width or x < 0 or y > self.height or y < 0:
            raise IndexError(
                'Attempt to access cell ({0}, {1}), which is out of range. Console size is ({2}, {3}).'
                .format(x, y, self.width, self.height))

        if isinstance(cell, tuple) and len(cell) >= 3:
            symbol, foreground, background = cell
            if isinstance(foreground, str):
                foreground = color.string_to_colornum(foreground)
            if isinstance(background, str):
                background = color.string_to_colornum(background)
        elif cell is not tuple:
            symbol = cell
            foreground = self.get_char_foreground(x, y)
            background = self.get_char_background(x, y)
        else:
            symbol = cell[0]
            foreground = cell[1]
            background = self.get_char_background(x, y)

        if background is None:
            background = self.get_char_background(x, y)

        if foreground is None:
            foreground = self.get_char_foreground(x, y)

        # tcod.console_set_char_background(self._c, x, y, background)
        # tcod.console_set_char_foreground(self._c, x, y, foreground)
        # tcod.console_put_char(self._c, x, y, symbol)
        tcod.console_put_char_ex(self._c, x, y, symbol, foreground, background)
Example #8
0
 def render(self, con, x: int, y: int):
     libtcod.console_put_char_ex(con,
                                 x,
                                 y,
                                 self.char,
                                 fore=self.fg,
                                 back=self.bg)
Example #9
0
    def render(self, con, x: int, y: int, alignment: int = None):
        if alignment is None:
            alignment = self.alignment

        if self.fill_char != 0:
            box = np.full((self.width, self.height), self.fill_char)
            for dx, col in enumerate(box):
                for dy, char in enumerate(col):
                    if type(char) == 'int':
                        char = chr(char)
                    if char != ScreenObject.NONE_CHAR:
                        libtcod.console_put_char_ex(con,
                                                    x + dx,
                                                    y + dy,
                                                    char,
                                                    fore=self.fg,
                                                    back=self.bg)

        libtcod.console_set_default_foreground(con, self.fg)
        libtcod.console_set_default_background(con, self.bg)
        libtcod.console_print_rect_ex(con,
                                      x,
                                      y,
                                      self.width,
                                      self.height,
                                      flag=libtcod.BKGND_SET,
                                      alignment=alignment,
                                      fmt=self.text)
Example #10
0
def draw_entity(con, entity, fov_map, game_map):
    """
    Affiche une entité visible

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

    entity : Entity

    fov_map : tcod.map

    game_map : GameMap


    Renvoi:
    -------
    Aucun

    """
    if libtcod.map_is_in_fov(fov_map, entity.x, entity.y) or (
            entity.stairs and game_map.tiles[entity.x][entity.y].explored):
        if entity.visible:
            libtcod.console_set_default_foreground(con, entity.color)
            libtcod.console_put_char_ex(con, entity.x, entity.y, entity.char,
                                        libtcod.white, libtcod.black)
    elif game_map.tiles[entity.x][entity.y].explored:
        libtcod.console_put_char_ex(con, entity.x, entity.y, 257,
                                    libtcod.light_grey, libtcod.black)
Example #11
0
def ClearConsole():
    for x in range(SCREEN_WIDTH):
        for y in range(SCREEN_HEIGHT):
            tcod.console_put_char_ex(0, x, y, " ", tcod.black, tcod.black)

    tcod.console_flush()

    return
Example #12
0
 def render(self, con):
     for x, y in self.positions:
         if self.char != ScreenObject.NONE_CHAR:
             libtcod.console_put_char_ex(con,
                                         x,
                                         y,
                                         self.char,
                                         fore=self.fg,
                                         back=self.bg)
Example #13
0
def render_bar(x, y, total_width, name, value, maximum, bar_colour, bg_colour):
    bar_width = int(value / maximum * total_width)
    txt = "{}: {}/{}".format(name, value, maximum)
    for i, (char, col) in enumerate(
            zip(
                txt.center(total_width),
                list(repeat(bar_colour, bar_width)) +
                list(repeat(bg_colour, total_width - bar_width)))):
        tcod.console_put_char_ex(panel, x + i, y, char, tcod.color.white, col)
Example #14
0
def test_console_rexpaint_save_load(console, tmpdir, ch, fg, bg):
    libtcodpy.console_print(console, 0, 0, 'test')
    libtcodpy.console_put_char_ex(console, 1, 1, ch, fg, bg)
    xp_file = tmpdir.join('test.xp').strpath
    assert libtcodpy.console_save_xp(console, xp_file, 1)
    xp_console = libtcodpy.console_from_xp(xp_file)
    assert xp_console
    assertConsolesEqual(console, xp_console)
    assert libtcodpy.console_load_xp(None, xp_file)
    assertConsolesEqual(console, xp_console)
Example #15
0
def test_console_rexpaint_save_load(console, tmpdir, ch, fg, bg):
    libtcodpy.console_print(console, 0, 0, 'test')
    libtcodpy.console_put_char_ex(console, 1, 1, ch, fg, bg)
    xp_file = tmpdir.join('test.xp').strpath
    assert libtcodpy.console_save_xp(console, xp_file, 1)
    xp_console = libtcodpy.console_from_xp(xp_file)
    assert xp_console
    assertConsolesEqual(console, xp_console)
    assert libtcodpy.console_load_xp(None, xp_file)
    assertConsolesEqual(console, xp_console)
Example #16
0
def clear_entity(con, entity, fov_map, game_map):
	visible = libtcod.map_is_in_fov(fov_map, entity.x, entity.y)
	if visible:
		libtcod.console_put_char_ex(con, entity.x, entity.y, '.', libtcod.white, libtcod.black)
	
	if not visible and game_map.tiles[entity.x][entity.y].explored:
		libtcod.console_put_char_ex(con, entity.x, entity.y, '.', libtcod.dark_grey, libtcod.black)
	
	else:
		libtcod.console_put_char(con, entity.x, entity.y, ' ', libtcod.BKGND_NONE)
		
Example #17
0
def render_enemy_panel(game, con, panel_x, panel_y, width, height, color):
    setup_console(con, caption='Enemies', borders=True, bordercolor=color)

    # check for monsters in FOV
    spotted = [
        ent for ent in game.npc_ents
        if ent.is_visible(game.fov_map) and ent.f.hp > 0
    ]
    #spotted = [ent for ent in game.entities if ent.ai and ent.f.hp > 0 and ent.is_visible(game.fov_map)]

    if len(spotted):
        spotted.sort(key=game.player.distance_to_ent
                     )  # sort the spotted array by distance to player

        # initial offsets from panel borders
        y = 2

        for ent in spotted:  # Go through the object names and wrap them according to the panel's width
            if y >= con.height - 2:  # If the limit's of the con are reached, cut the con off
                tcod.console_set_default_foreground(con, colors.white)
                x = center_x_for_text(width, '~ ~ ~ MORE ~ ~ ~')
                print_line(con, x, y, '~ ~ ~ MORE ~ ~ ~')
                break

            char = '*' if ent.pos == game.cursor.pos and game.state in [
                GameState.CURSOR_ACTIVE, GameState.CURSOR_TARGETING
            ] else f'{ent.char}'

            # Draw creature name and stats #
            tcod.console_set_default_foreground(con, colors.gray)
            tcod.console_set_color_control(tcod.COLCTRL_1, ent.color,
                                           tcod.black)
            tcod.console_put_char_ex(con, 1, y, char, ent.color, tcod.black)
            print_line(con, 3, y, ent.full_name, color=ent.color)
            y += 1
            x = 1
            tcod.console_put_char_ex(con, x, y, chr(192), tcod.gray,
                                     tcod.black)
            tcod.console_set_color_control(tcod.COLCTRL_2, ent.f.hp_color,
                                           tcod.black)
            tcod.console_set_color_control(tcod.COLCTRL_3, ent.f.stamina_color,
                                           tcod.black)
            status_line = f'%c{ent.f.hp_string.title()}%c|%c{ent.f.stamina_string.title()}%c'\
                          % (tcod.COLCTRL_2, tcod.COLCTRL_STOP, tcod.COLCTRL_3, tcod.COLCTRL_STOP)
            for status, active in ent.f.effects.items(
            ):  # Todo does not consider number of status effects > width of panel
                if active:
                    status_line += f' %white%{status.name[0]}%%'

            print_line(con, x + 1, y, f'{status_line}')

            y += 1

    con.blit(game.root, panel_x, panel_y, 0, 0, width, height)
Example #18
0
def blind_draw_map(level):
    for tile in chain(*level.map_grid.tiles):
        if not in_fov(tile.location, level):
            tile.explored = False
        elif same_location(level.player.location, tile.location):
            tile.explored = True
        if tile.explored:
            tcod.console_put_char_ex(con, tile.location.x, tile.location.y,
                                     tile_char(level, tile.location),
                                     tcod.color.black,
                                     tile_colour(level, "DARK", tile.location))
Example #19
0
    def _discover_place(self, x,y,char=None):
        world=rog.world()
##        ent = self.thingat(x,y)
        if char:
            libtcod.console_put_char_ex(
                self.con_memories, x,y, char, COL['dkgray'],COL['black']
                )
        else:
            libtcod.console_put_char_ex(self.con_memories, x,y,
                                        self.get_char(x,y),
                                        COL['dkgray'], COL['black'])
Example #20
0
def draw_map(level):
    for tile in chain(*level.map_grid.tiles):
        if in_fov(tile.location, level):
            fov = "LIT"
            tile.explored = True
        else:
            fov = "DARK"
        if tile.explored:
            tcod.console_put_char_ex(con, tile.location.x, tile.location.y,
                                     tile_char(level, tile.location),
                                     tcod.color.black,
                                     tile_colour(level, fov, tile.location))
Example #21
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 = 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, '#', colors.lgray(), colors.black())
                    else:
                        libtcod.console_put_char_ex(con, x, y, '+', colors.dgray(), colors.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, '#', colors.dgray(), colors.black())
                    else:
                        libtcod.console_put_char_ex(con, x, y, '+', colors.black(), colors.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)

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

    libtcod.console_set_default_background(panel, colors.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,
               colors.red(), colors.dred(), colors.white())
    libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
                             'Dungeon level: {0}'.format(game_map.dungeon_level))

    libtcod.console_set_default_foreground(panel, colors.lgray())
    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, 18, screen_width, screen_height)
def draw_entity(game, con, entity, fov_map, debug=False):
    if entity.render_order != RenderOrder.NONE:
        x, y = pos_on_screen(*entity.pos, game.player)

        if debug or entity.is_visible(fov_map) or (entity.render_order == RenderOrder.ALWAYS and game.map.tiles[entity.pos].explored > 0):
            if entity.is_visible(fov_map) and entity is not game.cursor and not debug:
                color = darken_color_by_fov_distance(game.player, entity.color, entity.x, entity.y, min=0.3)
            elif entity.render_order == RenderOrder.ALWAYS and not debug and not game.state == GameState.SHOW_MAP:
                color = colors.darkest_gray
            else:
                color = entity.color

            bg_color = colors.black if entity.color_bg is None else entity.color_bg
            tcod.console_put_char_ex(con, x, y, entity.char, color, bg_color)
Example #23
0
def BiomeMap(Chars, Colors):

    for x in range(WORLD_WIDTH):
        for y in range(WORLD_HEIGHT):
            tcod.console_put_char_ex(
                0,
                x,
                y + int(SCREEN_HEIGHT / 2) - int(WORLD_HEIGHT / 2),
                Chars[x][y],
                Colors[x][y],
                tcod.black,
            )

    tcod.console_flush()
    return
Example #24
0
def load_layer_to_console(console, xp_file_layer):
    if not xp_file_layer['width'] or not xp_file_layer['height']:
        raise AttributeError(
            'Attempted to call load_layer_to_console on data that didn\'t have a width or height key, check your data'
        )

    for x in range(xp_file_layer['width']):
        for y in range(xp_file_layer['height']):
            cell_data = xp_file_layer['cells'][x][y]
            fore_color = tcod.Color(cell_data['fore_r'], cell_data['fore_g'],
                                    cell_data['fore_b'])
            back_color = tcod.Color(cell_data['back_r'], cell_data['back_g'],
                                    cell_data['back_b'])
            tcod.console_put_char_ex(console, x, y, cell_data['keycode'],
                                     fore_color, back_color)
Example #25
0
def PrecipGradMap(
    World,
):  # ------------------------------------------------------------ Print Map (Precipitation Gradient) white -> low blue -> high --------------------------------
    for x in range(WORLD_WIDTH):
        for y in range(WORLD_HEIGHT):
            tempv = World[x][y].precip
            tempcolor = tcod.color_lerp(tcod.white, tcod.light_blue, tempv)
            tcod.console_put_char_ex(
                0,
                x,
                y + SCREEN_HEIGHT / 2 - WORLD_HEIGHT / 2,
                "\333",
                tempcolor,
                tcod.black,
            )
    tcod.console_flush()
    return
Example #26
0
def TempGradMap(
    World,
):  # ------------------------------------------------------------ Print Map (Surface Temperature Gradient) white -> cold red -> warm --------------------------------
    for x in range(WORLD_WIDTH):
        for y in range(WORLD_HEIGHT):
            tempv = World[x][y].temp
            tempcolor = tcod.color_lerp(tcod.white, tcod.red, tempv)
            tcod.console_put_char_ex(
                0,
                x,
                y + SCREEN_HEIGHT / 2 - WORLD_HEIGHT / 2,
                "\333",
                tempcolor,
                tcod.black,
            )
    tcod.console_flush()
    return
Example #27
0
def testpage_screen(character_screen_width, character_screen_height, screen_width, screen_height):
    window = libtcod.console_new(character_screen_width, character_screen_height)

    libtcod.console_set_default_foreground(window, libtcod.white)

    libtcod.console_print_rect_ex(window, 0, 1, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Test Page')

    n = 0
    for r in range(0,10):
        for c in range(0, 32):
            n = n + 1
            libtcod.console_put_char_ex(window, c, 3 + r, n, libtcod.white, libtcod.red)


    x = screen_width // 2 - character_screen_width // 2
    y = screen_height // 2 - character_screen_height // 2
    libtcod.console_blit(window, 0, 0, screen_width, screen_height, 0, x, y, 1.0, 0.7)
Example #28
0
def render_status_panel(game, con, panel_x, panel_y, width, height):
    setup_console(con, fgcolor=colors.light_gray)
    draw_console_borders(con, color=colors.dark_gray)

    bar_width = round(width // 3)
    draw_bar(con, 1, 1, bar_width, f'{game.player.f.hp_string}',
             int(game.player.f.hp), game.player.f.max_hp,
             game.player.f.hp_color, tcod.darkest_red)
    draw_bar(con, width - bar_width - 1, 1,
             bar_width, f'{game.player.f.stamina_string}',
             int(game.player.f.stamina), game.player.f.max_stamina,
             game.player.f.stamina_color, colors.darkest_blue)

    draw_quickslots(con, round(r_cons.STATUS_BAR_WIDTH // 2) - 1, 0, game)

    tcod.console_put_char_ex(con, 0, 0, 195, colors.dark_gray, colors.black)
    #tcod.console_put_char_ex(con, width-1, 0, 180, colors.dark_gray, colors.black)
    con.blit(game.map_panel, panel_x, panel_y, 0, 0, width, height)
def draw_tile(game, con, fov_map, tile_x, tile_y, screen_x, screen_y, debug=False):
    tile = game.map.tiles[(tile_x, tile_y)]
    visible = fov_map.fov[tile_y, tile_x] or debug

    if visible:
        if debug or game.state == GameState.SHOW_MAP:
            color = tile.fg_color
        else:
            color = darken_color_by_fov_distance(game.player, tile.fg_color, tile_x, tile_y, min = 0.3)
        tcod.console_put_char_ex(con, screen_x, screen_y, tile.char, color, colors.black)
        tile.explored = 50

    elif tile.explored > 0: #and not game.player.in_combat(game):
        # "forgetting" tiles disabled for now
        # if  game.state == GameState.PLAYERS_TURN:   # Only active player movement lowers tile exploration state
        #     tile.explored -= randint(0, 1)
        #if game.state == GameStates.PLAYER_RESTING: # Automap is only displayed outside of combat when actively pausing #
        color = tile.dark_color if not game.state == GameState.SHOW_MAP else tile.fg_color
        tcod.console_put_char_ex(con, screen_x, screen_y, tile.char, color, colors.black)
Example #30
0
def look_mode():
    global MESSAGES
    from game import decode_key

    x, y = GAME.player.x, GAME.player.y
    _messages = MESSAGES
    MESSAGES = []
    message('Look mode - use movement keys, ESC/q to exit.', T.green)
    new_ui_turn()
    _draw_messages()
    redraw = True
    while True:
        if redraw:
            T.console_blit(CON_MAP, 0, 0, MAP_W, MAP_H,
                           None, 1, 1)
            c = T.console_get_char(CON_MAP, x, y)
            color = T.console_get_char_foreground(CON_MAP, x, y)

            T.console_put_char_ex(None, x+1, y+1, c,
                                  T.black, color)

            describe_tile(x, y)

            _draw_messages()
            T.console_flush()

            # now clear the message buffer of last messages
            while MESSAGES and MESSAGES[-1][0]:
                MESSAGES.pop()

            redraw = False
        cmd = decode_key(readkey())
        if cmd == 'quit':
            break
        elif isinstance(cmd, tuple):
            name, args = cmd
            if name == 'walk':
                dx, dy = args
                if in_map(x+dx, y+dy):
                    x, y = x+dx, y+dy
                    redraw = True

    MESSAGES = _messages
Example #31
0
def ProsperityGradMap(
    World,
):  # ------------------------------------------------------------ Print Map (Prosperity Gradient) white -> low green -> high --------------------------------
    for x in range(WORLD_WIDTH):
        for y in range(WORLD_HEIGHT):
            prosperitynv = World[x][y].prosperity
            prosperitycolor = tcod.color_lerp(
                tcod.white, tcod.darker_green, prosperitynv
            )
            tcod.console_put_char_ex(
                0,
                x,
                y + int(SCREEN_HEIGHT / 2) - int(WORLD_HEIGHT / 2),
                "\333",
                prosperitycolor,
                tcod.black,
            )
    tcod.console_flush()
    return
Example #32
0
def DrainageGradMap(
    World,
):  # ------------------------------------------------------------ Print Map (Drainage Gradient) brown -> low white -> high --------------------------------
    for x in range(WORLD_WIDTH):
        for y in range(WORLD_HEIGHT):
            drainv = World[x][y].drainage
            draincolor = tcod.color_lerp(
                tcod.darkest_orange, tcod.white, drainv
            )
            tcod.console_put_char_ex(
                0,
                x,
                y + SCREEN_HEIGHT / 2 - WORLD_HEIGHT / 2,
                "\333",
                draincolor,
                tcod.black,
            )
    tcod.console_flush()
    return
Example #33
0
def draw_top(game, console):
    console.clear()

    center_y = SCREEN_HEIGHT / 2.0 + 0.5
    center_x = SCREEN_WIDTH / 2.0 + 0.5

    for name, body in game.orbits.items():
        planet_x, planet_y, planet_z = body.position(game.time / DAYS_PER_YEAR)
        planet_x = planet_x * 4.0
        planet_y = planet_y * 4.0
        planet_z = planet_z * 4.0
        tcod.console_put_char_ex(console, int(center_x + planet_x), int(center_y - planet_y), game.planet_symbols[name], game.planet_colors[name], tcod.black)

    # Draw Sun
    # TODO: refactor this so the sun isn't special
    tcod.console_put_char_ex(console, int(center_x), int(center_y), chr(42), tcod.yellow, tcod.black)

    info = 'Day: {t:.2f} @ {ts:.2f} d/s'.format(t = game.time, ts = game.time_scale)
    console.print(0, SCREEN_HEIGHT-1, info, fg=tcod.constants.white, bg=tcod.constants.black)
Example #34
0
def _draw_map():
    con = CON_MAP
    player = GAME.player
    for x in range(MAP_W):
        for y in range(MAP_H):
            tile = GAME.map.tiles[x][y]
            if GAME.map.is_visible(x, y):
                c, color = tile.visible_glyph
                d = distance(x, y, player.x, player.y)
                if d > player.light_range + 1:
                    color *= 0.6
                if 'h' in player.effects:
                    color = insanize_color(color, player.sanity)
                elif 'd' in player.effects:
                    color = dim_color(color, player.sanity)
            else:
                c, _ = tile.known_glyph
                color = T.dark_grey*((player.sanity/100.0)*0.6+0.4)
            T.console_put_char_ex(con, x, y, ord(c),
                                  color, T.black)
    T.console_blit(con, 0, 0, MAP_W, MAP_H,
                   None, 1, 1)
Example #35
0
def _draw_items(title, items):
    con = CON_INV
    T.console_clear(con)
    con.default_fg = T.white
    con.print_(1, 0, title)
    con.default_fg = T.light_grey
    for i, item in enumerate(items):
        T.console_put_char_ex(con, 2, i+2, (i+ord('a')),
                              T.light_grey, T.black)
        c, color = item.glyph
        T.console_put_char_ex(con, 4, i+2, ord(c), color, T.black)
        s = item.descr
        if GAME.player.has_equipped(item):
            T.console_put_char_ex(con, 0, i+2, ord('*'),
                                  T.light_grey, T.black)
            con.default_fg = T.white
        else:
            con.default_fg = T.grey
        con.print_(6, i+2, s)
    T.console_blit(con, 0, 0, INV_W, INV_H,
                   None, 1, 1)
Example #36
0
def console_put_char_ex(console, ch, fg, bg):
    libtcodpy.console_put_char_ex(console, 0, 0, ch, fg, bg)
    assert_char(console, 0, 0, ch=ch, fg=fg, bg=bg)