Example #1
0
def character_screen(player, 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, 'Character Information')
    libtcod.console_print_rect_ex(
        window, 0, 6, character_screen_width, character_screen_height,
        libtcod.BKGND_NONE, libtcod.LEFT,
        'Maximum HP: {0}'.format(player.fighter.max_hp))
    libtcod.console_print_rect_ex(window, 0, 7, character_screen_width,
                                  character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT,
                                  'Attack: {0}'.format(player.fighter.power))
    libtcod.console_print_rect_ex(
        window, 0, 8, character_screen_width, character_screen_height,
        libtcod.BKGND_NONE, libtcod.LEFT,
        'Defense: {0}'.format(player.fighter.defense))

    x = screen_width // 2 - character_screen_width // 2
    y = screen_height // 2 - character_screen_height // 2
    libtcod.console_blit(window, 0, 0, character_screen_width,
                         character_screen_height, 0, x, y, 1.0, 0.7)
Example #2
0
def main_menu_help_menu(con, help_menu_width, help_menu_height, screen_width, screen_height):
	help_menu_width = 38
	help_menu_height = 14
	window = libtcod.console_new(help_menu_width, help_menu_height)
	menu_title = help_menu_width // 2 - 4

	libtcod.console_set_default_foreground(window, libtcod.white)

	libtcod.console_print_rect_ex(window, menu_title, 1, help_menu_width, help_menu_height, libtcod.BKGND_NONE, libtcod.LEFT, "HELP MENU")
	libtcod.console_print_rect_ex(window, 0, 3, help_menu_width, help_menu_height, libtcod.BKGND_NONE, libtcod.LEFT, "> WASD: Cardinal movement")
	libtcod.console_print_rect_ex(window, 0, 4, help_menu_width, help_menu_height, libtcod.BKGND_NONE, libtcod.LEFT, "> QEZX: Diagonal movement")
	libtcod.console_print_rect_ex(window, 0, 5, help_menu_width, help_menu_height, libtcod.BKGND_NONE, libtcod.LEFT, "> ENTER: Descend stairs")
	libtcod.console_print_rect_ex(window, 0, 6, help_menu_width, help_menu_height, libtcod.BKGND_NONE, libtcod.LEFT, "> ESC: Exit and save the game")
	libtcod.console_print_rect_ex(window, 0, 7, help_menu_width, help_menu_height, libtcod.BKGND_NONE, libtcod.LEFT, "> MOUSE over objects for descriptions")
	libtcod.console_print_rect_ex(window, 0, 8, help_menu_width, help_menu_height, libtcod.BKGND_NONE, libtcod.LEFT, "> G: Pick up objects")
	libtcod.console_print_rect_ex(window, 0, 9, help_menu_width, help_menu_height, libtcod.BKGND_NONE, libtcod.LEFT, "> M: Attack with magic wand")
	libtcod.console_print_rect_ex(window, 0, 10, help_menu_width, help_menu_height, libtcod.BKGND_NONE, libtcod.LEFT, "> I: Open the INVENTORY")
	libtcod.console_print_rect_ex(window, 0, 11, help_menu_width, help_menu_height, libtcod.BKGND_NONE, libtcod.LEFT, "> C: Open the CHARACTER SCREEN")
	libtcod.console_print_rect_ex(window, 0, 12, help_menu_width, help_menu_height, libtcod.BKGND_NONE, libtcod.LEFT, "> U: Drop items")
	libtcod.console_print_rect_ex(window, 0, 13, help_menu_width, help_menu_height, libtcod.BKGND_NONE, libtcod.LEFT, "> P: Wait (Skip a turn)")
	libtcod.console_print_rect_ex(window, 0, 14, help_menu_width, help_menu_height, libtcod.BKGND_NONE, libtcod.LEFT, "> H: Open the HELP MENU")

	x = screen_width // 2 - help_menu_width // 2
	y = screen_height // 2 - help_menu_height // 2
	libtcod.console_blit(window, 0, 0, help_menu_width, help_menu_height, 0, x, y, 1.0, 1.0)
Example #3
0
def menu(con,
         header,
         options,
         width,
         screen_width,
         screen_height,
         render_func=render_option):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options')

    header_height = libtcod.console_get_height_rect(con, 0, 0, width,
                                                    screen_height, header)
    height = len(options) + header_height

    window = libtcod.console_new(width, height)

    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window, 0, 0, width, height,
                                  libtcod.BKGND_NONE, libtcod.LEFT, header)

    y = header_height
    index = 1
    for option in options:
        render_func(option, index, window, y)
        index += 1
        y += 1

    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
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):
    draw_map(con, game_map, fov_map, fov_recompute, colors)

    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)

    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.combat.hp,
               player.combat.max_hp, libtcod.light_red, libtcod.darker_red)

    libtcod.console_set_default_foreground(panel, libtcod.light_grey)
    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)
Example #5
0
def menu(con, header, options, width, screenWidth, screenHeight):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options')

    headerHeight = tcod.console_get_height_rect(con, 0, 0, width, screenHeight,
                                                header)
    height = len(options) + headerHeight

    window = tcod.console_new(width, height)

    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_rect_ex(window, 0, 0, width, height, tcod.BKGND_NONE,
                               tcod.LEFT, header)

    y = headerHeight
    letterIndex = ord('a')
    for optionText in options:
        text = '(' + chr(letterIndex) + ')' + optionText
        tcod.console_print_ex(window, 0, y, tcod.BKGND_NONE, tcod.LEFT, text)
        y += 1
        letterIndex += 1

    x = int(screenWidth / 2 - width / 2)
    y = int(screenHeight / 2 - height / 2)

    tcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Example #6
0
    def _render_all(self, app, mouse):
        game = app.game
        if game.fov_recompute:
            self._render_map(game)

        # fix pour eviter artefact lors de changement de niveau...TODO: autre solution.
        if game.reset_game_windows:
            self.reset_render_windows()
            game.reset_game_windows = False

        libtcod.console_set_default_background(self.menu_window, libtcod.black)
        libtcod.console_clear(self.menu_window)

        self._render_entities(game)

        libtcod.console_blit(self.game_window, 0, 0, self.screen_width,
                             self.screen_height, 0, 0, 0)

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

        # print message
        self._render_messages(game)
        self._render_under_mouse(game, mouse)
        self._render_interface(game)
        self._render_dungeon_level(game)
        libtcod.console_blit(self.panel, 0, 0, self.screen_width,
                             self.panel_height, 0, 0, self.panel_y)

        if game.current_menu:
            self._render_main_menu(app)

        game.fov_recompute = False
        libtcod.console_flush()
        self._clear_all(game.dungeon.current_map.get_entities())
Example #7
0
 def draw_game(self):
     for y in range(self.game.world.map.height):
         for x in range(self.game.world.map.width):
             self.draw_cell(x, y)
     tcod.console_blit(self.console, 0, 0, self.SCREEN_WIDTH,
                       self.SCREEN_HEIGHT, self.console, 0, 0)
     tcod.console_flush()
Example #8
0
    def draw_splash_screen(self):
        # title_height = self.console.print_box(
        #     0, 0, self.SCREEN_WIDTH, self.SCREEN_HEIGHT,
        #     self.game.SPLASH_SCREEN.get_centered_title_art(self.SCREEN_WIDTH),
        #     fg=tuple(self.game.SPLASH_SCREEN.title_art_color)
        # )
        self.console.clear()

        self.draw_title()
        top_offset = self.LOGO_HEIGHT + 4
        # bottom_offset = self.draw_credits() + 1
        # remaining = self.SCREEN_HEIGHT - top_offset - bottom_offset - 1

        # Have to do it this way because libtcod has a weird interaction with
        # CP437 characters
        key_hint1 = f"Choose an option with {chr(18)}"
        key_hint2 = ", confirm with the Spacebar or Enter"
        xstart = (self.SCREEN_WIDTH - (len(key_hint1) + len(key_hint2))) // 2
        self.console.print(xstart, top_offset, key_hint1, fg=(112, 120, 128))
        self.console.print(xstart + len(key_hint1),
                           top_offset,
                           key_hint2,
                           fg=(112, 120, 128))
        self.draw_main_menu_options(top_offset + 1)
        self.draw_credits()
        if not self._end_credits:
            self._end_credits = tcod.console_credits_render(
                self.SCREEN_WIDTH - 15, self.SCREEN_HEIGHT - 3, True)
        tcod.console_blit(self.console, 0, 0, self.SCREEN_WIDTH,
                          self.SCREEN_HEIGHT, self.console, 0, 0)
        tcod.console_flush()
Example #9
0
def edges_to_ascii(edges, w, h, debug):
    # map final size
    ascii_map = np.empty((h, w), dtype='str')
    ascii_map[:] = ' '

    # block size
    br = floor(edges.shape[0] / h)
    bc = floor(edges.shape[1] / w)

    pixel_threshold = (br + bc) / 1

    for y in range(h):
        for x in range(w):
            if np.count_nonzero(edges[x * br:(x * br) + br,
                                      y * bc:(y * bc) + bc]) > pixel_threshold:
                ascii_map[y, x] = '#'

    if debug:
        libtcod.console_set_custom_font('Anikki_square_8x8.png',
                                        libtcod.FONT_LAYOUT_ASCII_INROW)
        libtcod.console_init_root(w, h, 'Test', False)
        con = libtcod.console_new(w, h)
        libtcod.console_set_default_foreground(con, libtcod.white)

        for y in range(h):
            for x in range(w):
                libtcod.console_put_char(con, x, y, str(ascii_map[x, y]))

        libtcod.console_blit(con, 0, 0, w, h, 0, 0, 0)
        libtcod.console_flush()

        while not libtcod.console_is_window_closed():
            pass

    return ascii_map
Example #10
0
def character_screen(player, 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)
    character_sheet = [
        'Character Information',
        'Level: {0}'.format(player.level.current_level),
        'Experience: {0}'.format(player.level.current_xp),
        'Experience to Level: {0}'.format(
            player.level.experience_to_next_level),
        'Maximum HP: {0}'.format(player.fighter.max_hp),
        'Damage: {0}'.format(player.fighter.power),
        'Accuracy: {0}'.format(player.fighter.hit),
        'Defense: {0}'.format(player.fighter.defense),
    ]
    if player.status_effects.active_statuses:
        character_sheet.append("Active Status Effects:")
        character_sheet.extend(
            "{} ({} turns left)".format(name, status.duration)
            for name, status in player.status_effects.active_statuses.items())

    for i, s in enumerate(character_sheet):
        libtcod.console_print_rect_ex(window, 0, i, character_screen_width,
                                      character_screen_height,
                                      libtcod.BKGND_NONE, libtcod.LEFT, s)

    x = screen_width // 2 - character_screen_width // 2
    y = screen_height // 2 - character_screen_height // 2
    libtcod.console_blit(window, 0, 0, character_screen_width,
                         character_screen_height, 0, x, y, 1.0, 0.7)
Example #11
0
def menu(con, header, options, width, screen_width, screen_height):
    if len(options) > 26:
        raise ValueError("Cannot have a menu with more than 26 options.")

    # ヘッダーの高さと行の計算
    header_height = libtcod.console_get_height_rect(con, 0, 0, width,
                                                    screen_height, header)
    height = len(options) + header_height

    # メニューのコンソールを作る
    window = libtcod.console.Console(width, height)

    # 自動折り返しでヘッダをprintする
    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する
    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する
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Example #12
0
def character_screen(player, 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, 'Character Information')
    libtcod.console_print_rect_ex(window, 0, 3, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Level: {0}'.format(player.level.current_level))
    libtcod.console_print_rect_ex(window, 0, 4, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Experience: {0}'.format(player.level.current_xp))
    libtcod.console_print_rect_ex(window, 0, 5, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Experience to Level: {0}'.format(player.level.experience_to_next_level))
    libtcod.console_print_rect_ex(window, 0, 7, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Maximum HP: {0}'.format(player.fighter.max_hp))
    libtcod.console_print_rect_ex(window, 0, 8, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Attack: {0}'.format(player.fighter.main_hand_damage_msg))
    libtcod.console_print_rect_ex(window, 0, 9, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Defense: {0}'.format(player.fighter.defense))
    libtcod.console_print_rect_ex(window, 0, 11, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'STR: {0} ({1})'.format(player.fighter.strength, player.fighter.str_mod))
    libtcod.console_print_rect_ex(window, 0, 12, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'AGI: {0} ({1})'.format(player.fighter.agility, player.fighter.agi_mod))
    libtcod.console_print_rect_ex(window, 0, 13, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'INT: {0} ({1})'.format(player.fighter.intelligence, player.fighter.int_mod))
    libtcod.console_print_rect_ex(window, 0, 14, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'PER: {0} ({1})'.format(player.fighter.perception, player.fighter.per_mod))
    libtcod.console_print_rect_ex(window, 0, 15, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'END: {0} ({1})'.format(player.fighter.endurance, player.fighter.end_mod))
    libtcod.console_print_rect_ex(window, 0, 16, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'CHA: {0} ({1})'.format(player.fighter.charisma, player.fighter.cha_mod))
    x = screen_width // 2 - character_screen_width // 2
    y = screen_height // 2 - character_screen_height // 2
    libtcod.console_blit(window, 0, 0, character_screen_width, character_screen_height, 0, x, y, 1.0, 0.7)
Example #13
0
def menu(con, header, options, width, screen_width, screen_height):
    if len(options) > 12: raise ValueError('Cannot have a menu with more than 12 options')

    # calc total menu height for the header 
    header_height = libtcod.console_get_height_rect(con, 0, 0, width, screen_height, header)
    height = len(options) + header_height

    # create off-screen console that represents the menu's window
    window = libtcod.console.Console(width, height)

    # print header (with auto-wrap)
    libtcod.console_set_default_foreground(window, libtcod.white)
    #libtcod.console_set_default_background(window, libtcod.gray)
    libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)

    # print all 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 = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Example #14
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):
    if fov_recompute:
        # Draw all the tiles in the game_map
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

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

                    game_map.tiles[x][y].explored = True

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

    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)
    # Draw all entities in the list, blits the changes to screen
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map)

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

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

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

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

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

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0,
                         panel_y)
Example #15
0
def menu(con, header, options, width, screen_width, screen_height):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')

    # calculate header height after auto-wrap and one line per option
    header_height = libtcod.console_get_height_rect(con, 0, 0, width,
                                                    screen_height, header)
    height = len(options) + header_height

    # create an off-screen console that represents the menu's window
    window = libtcod.console_new(width, height)

    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 contents of window to console
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
def menu(con, header, options, width, max_capacity=6):
    '''
    OK this menu only shows up on the center of the screen and with some transparency...
    also it only works for numeric values for the options...
    '''

    if len(options) > max_capacity: raise ValueError('No more than 6.')

    #Calculate total height for header
    header_height = tcod.console_get_height_rect(con, 0, 0, width,
                                                 const['screen_height'],
                                                 header)
    height = len(options) + header_height

    #create an offscreen console that represents the menu's window
    window = tcod.console_new(width, height)

    #print header, with autowrap
    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_rect_ex(window, 0, 0, width, height, tcod.BKGND_NONE,
                               tcod.LEFT, header)

    #print all options
    y = header_height
    num_index = 1
    for option_text in options:
        text = '(' + str(num_index) + ')' + option_text
        tcod.console_print_ex(window, 0, y, tcod.BKGND_NONE, tcod.LEFT, text)
        y += 1
        num_index += 1

    #blit the contents of 'window' to the root console
    x = int(const['screen_width'] / 2 - width / 2)
    y = int(const['screen_height'] / 2 - height / 2)
    tcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Example #17
0
def menu(con, header, options, width, screen_width, screen_height):
    if len(options) > 26:
        raise ValueError("Cannot have a menu with over 26 options")

    # Calculates height of header after text wrap
    header_height = libtcod.console_get_height_rect(con, 0, 0, width,
                                                    screen_height, header)
    height = len(options) + header_height

    # Creates new console window for the menu
    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)

    # Prints 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 = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Example #18
0
def render_all(con, entities, game_map, fov_map, fov_recompute, screen_width,
               screen_height, colors):
    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)

    for entity in entities:
        draw_entity(con, entity, fov_map)

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)
Example #19
0
def menu(con, header, options, width, screen_width, screen_height):
    if len(options) > 26:
        raise ValueError("Can't have more than 26 options in a menu")

    # 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)
    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 = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Example #20
0
def render_all(con: libtcod.console.Console, entities: List[Entity],
               game_map: GameMap, fov_map: libtcod.map.Map,
               fov_recompute: bool, screen_width: int, screen_height: int,
               colors: Dict[str, libtcod.Color]) -> None:
    # Draw 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['light_wall'], libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors['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['dark_wall'], libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors['dark_ground'],
                            libtcod.BKGND_SET)

    # Draw all entities
    for entity in entities:
        draw_entity(con, entity, fov_map)

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)
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

                color_name = None
                if visible:
                    if wall:
                        color_name = "light_wall"

                    else:
                        color_name = "light_ground"

                    game_map.tiles[x][y].explored = True

                elif game_map.tiles[x][y].explored:
                    if wall:
                        color_name = "dark_wall"

                    else:
                        color_name = "dark_ground"
                if color_name:    
                    libtcod.console_set_char_background(con, x, y, colors.get(color_name), libtcod.BKGND_SET)
    entities_in_render_order = sorted(entities, key=lambda x : x.render_order.value)
                
    #Draw all entities in the list
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map)

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

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = "Press the key of your love story to use item or Esc to cancel.\n"
        else:
            inventory_title = "Press the key of your love story to drop item or Esc to cancel.\n"
        
        inventory_menu(con, inventory_title, player.inventory, 50, screen_width, screen_height)

    libtcod.console_set_default_foreground(con, libtcod.lighter_magenta)
    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_fuchsia, libtcod.dark_fuchsia)
                
    libtcod.console_set_default_foreground(panel, libtcod.lighter_violet)
    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)
Example #22
0
def menu(header, options, width):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')

    header_height = tcod.console_get_height_rect(con, 0, 0, width,
                                                 SCREEN_HEIGHT, header)
    height = len(options) + header_height + 2

    window = tcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)

    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_rect_ex(window, 0, 1, width, height, tcod.BKGND_NONE,
                               tcod.LEFT, header)

    y = header_height + 1
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        tcod.console_print_ex(window, 0, y, tcod.BKGND_NONE, tcod.LEFT, text)
        y += 1
        letter_index += 1

    x = int(SCREEN_WIDTH / 2 - width / 2)
    y = int(SCREEN_HEIGHT / 2 - height / 2)

    tcod.console_blit(window, 0, 0, width, height, 0, x, y - 3, 1.0, 0.7)

    tcod.console_flush()
    key = tcod.console_wait_for_keypress(True)

    index = key.c - ord('a')
    if index >= 0 and index < len(options):
        return index

    return None
Example #23
0
def commandMenu(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, 'Command Information')
    libtcod.console_print_rect_ex(window, 0, 2, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Arrows : for move')
    libtcod.console_print_rect_ex(window, 0, 3, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Press for a-star move y:up-left, u:up-right, n:down-right, b:down-left')
    libtcod.console_print_rect_ex(window, 0, 4, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT,
                                  'Press z for wait')
    libtcod.console_print_rect_ex(window, 0, 6, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Press g for pickup object')
    libtcod.console_print_rect_ex(window, 0, 7, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Press c to show character menu')
    libtcod.console_print_rect_ex(window, 0, 8, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Press i for show inventory')
    libtcod.console_print_rect_ex(window, 0, 9, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Press d for drop inventory')
    libtcod.console_print_rect_ex(window, 0, 10, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Press Enter for downstairs')
    x = screen_width // 2 - character_screen_width // 2
    y = screen_height // 2 - character_screen_height // 2
    libtcod.console_blit(window, 0, 0, character_screen_width, character_screen_height, 0, x, y, 1.0, 0.7)
Example #24
0
def character_screen(player, 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, 'Character Information')
    libtcod.console_print_rect_ex(window, 0, 2, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Level: {0}'.format(player.level.current_level))
    libtcod.console_print_rect_ex(window, 0, 3, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Experience: {0}'.format(player.level.current_xp))
    libtcod.console_print_rect_ex(window, 0, 4, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Experience to Level: {0}'.format(player.level.experience_to_next_level))
    libtcod.console_print_rect_ex(window, 0, 6, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Maximum HP: {0}'.format(player.fighter.max_hp))
    libtcod.console_print_rect_ex(window, 0, 7, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Base Attack: {0}'.format(player.fighter.base_power))
    line = 0
    if player.equipment.main_hand:
        for item in player.inventory.items:
            if player.equipment.main_hand == item:
                break
        libtcod.console_print_rect_ex(window, 0, 8, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                    libtcod.LEFT, 'Main hand: {0}({1}d{2}+{3})'.format(item.name,player.equipment.main_hand.equippable.power_daice,
                                                                                       player.equipment.main_hand.equippable.daice,
                                                                                       player.equipment.main_hand.equippable.base_power
                                                                                       ))
        line+=1
    libtcod.console_print_rect_ex(window, 0, 8+line, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Defense: {0}'.format(player.fighter.defense))

    x = screen_width // 2 - character_screen_width // 2
    y = screen_height // 2 - character_screen_height // 2
    libtcod.console_blit(window, 0, 0, character_screen_width, character_screen_height, 0, x, y, 1.0, 0.7)
Example #25
0
def number_menu(con, header, options, width, screen_width, screen_height):
    if len(options) > 9:
        raise ValueError("Cannot have a number menu with more than 9 options.")

    header_height = libtcod.console_get_height_rect(con, 0, 0, width,
                                                    screen_height, header)
    height = len(options) + header_height

    window = libtcod.console_new(width, height)

    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window, 0, 0, width, height,
                                  libtcod.BKGND_NONE, libtcod.LEFT, header)

    y = header_height
    number_index = ord('1')
    for option_text in options:
        text = '(' + chr(number_index) + ') ' + option_text
        libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, text)
        y += 1
        number_index += 1

    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Example #26
0
def character_screen(con, player, menu_width, menu_height, screen_width, screen_height):
    window = libtcod.console_new(menu_width, menu_height)
    libtcod.console_set_default_foreground(window, libtcod.white)

    libtcod.console_print_rect_ex(window, 0, 1, menu_width, menu_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Character Information')
    libtcod.console_print_rect_ex(window, 0, 2, menu_width, menu_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Level: {0}'.format(player.level.current_level))
    libtcod.console_print_rect_ex(window, 0, 3, menu_width, menu_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Experience: {0}'.format(player.level.current_xp))
    libtcod.console_print_rect_ex(window, 0, 4, menu_width, menu_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Experience to Level: {0}'
                                  .format(player.level.experience_to_next_level))
    libtcod.console_print_rect_ex(window, 0, 6, menu_width, menu_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Strength: \t{0} [+{1}]'.format(player.fighter.base_strength,
                                                                                player.fighter.strength_modifier))
    libtcod.console_print_rect_ex(window, 0, 7, menu_width, menu_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Dexterity: \t{0} [+{1}]'.format(player.fighter.base_dexterity,
                                                                                 player.fighter.dexterity_modifier))
    libtcod.console_print_rect_ex(window, 0, 8, menu_width, menu_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Vitality: \t{0} [+{1}]'.format(player.fighter.base_vitality,
                                                                                player.fighter.vitality_modifier))
    libtcod.console_print_rect_ex(window, 0, 9, menu_width, menu_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Intellect: \t{0} [+{1}]'.format(player.fighter.base_intellect,
                                                                                 player.fighter.intellect_modifier))
    libtcod.console_print_rect_ex(window, 0, 10, menu_width, menu_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Perception: \t{0} [+{1}]'.format(player.fighter.base_perception,
                                                                                  player.fighter.perception_modifier))
    libtcod.console_print_rect_ex(window, 0, 12, menu_width, menu_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Armour Rating: \t{0}'.format(player.fighter.armour_total))

    x = screen_width // 2 - menu_width // 2
    y = screen_height // 2 - menu_height // 2
    libtcod.console_blit(window, 0, 0, menu_width, menu_height, con, x, y, 1, 1)
Example #27
0
def menu(con, header, options, width, screen_width, screen_height):
    if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.')

    # ヘッダーの高さの合計を計算し、 (自動折り返し後) オプションごとに1行ずつ計算
    header_height = libtcod.console_get_height_rect(con, 0, 0, width, screen_height, header)
    height = len(options) + header_height

    # メニューのウィンドウを表すコンソールを作成
    window = libtcod.console_new(width, height)

    # ヘッダを自動折り返しで表示
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)

    # すべてのオプションを表示
    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

    # ルートコンソールに "window "の内容を格納
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Example #28
0
def character_screen(player, 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, 'Character Information')
    libtcod.console_print_rect_ex(window, 0, 2, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Level: {0}'.format(player.level.current_level))
    libtcod.console_print_rect_ex(window, 0, 3, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Experience: {0}'.format(player.level.current_xp))
    libtcod.console_print_rect_ex(window, 0, 4, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Experience to Level: {0}'.format(player.level.experience_to_next_level))
    libtcod.console_print_rect_ex(window, 0, 5, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Maximum HP: {0}'.format(player.fighter.max_hp))
    libtcod.console_print_rect_ex(window, 0, 6, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Attack: {0}'.format(player.fighter.power))
    libtcod.console_print_rect_ex(window, 0, 7, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Defense: {0}'.format(player.fighter.defense))
    libtcod.console_print_rect_ex(window, 0, 8, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Maximum SP: {0}'.format(player.fighter.max_sp))
    libtcod.console_print_rect_ex(window, 0, 9, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Maximum MP: {0}'.format(player.fighter.max_mp))

    x = screen_width // 2 - character_screen_width // 2
    y = screen_height // 2 - character_screen_height // 2
    libtcod.console_blit(window, 0, 0, character_screen_width, character_screen_height, 0, x, y, 1.0, 0.7)
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)


    # Draw all entities in the list
    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)
    

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

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

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

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

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

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

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it, or Esc to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n'
                
        inventory_menu(con, inventory_title, player.inventory, 50, screen_width, screen_height)
Example #30
0
def menu(header, options, width):
    global key, mouse

    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')

    header_height = tcod.console_get_height_rect(con, 0, 0, width,
                                                 SCREEN_HEIGHT, header)

    if header == '':
        header_height = 0

    height = len(options) + header_height

    window = tcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)

    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_rect_ex(window, 0, 1, width, height, tcod.BKGND_NONE,
                               tcod.LEFT, header)

    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        tcod.console_print_ex(window, 0, y, tcod.BKGND_NONE, tcod.LEFT, text)
        y += 1
        letter_index += 1

    x = int(SCREEN_WIDTH / 2 - width / 2)
    y = int(SCREEN_HEIGHT / 2 - height / 2)

    tcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)

    x_offset = x
    y_offset = y + header_height

    while True:
        tcod.console_flush()
        tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key,
                                 mouse)

        if mouse.lbutton_pressed:
            (menu_x, menu_y) = (mouse.cx - x_offset, mouse.cy - y_offset)

            if 0 <= menu_x and menu_x <= width and 0 <= menu_y and menu_y < height - header_height:
                return menu_y

        if mouse.rbutton_pressed or key.vk == tcod.KEY_ESCAPE:
            return None

        if key.vk == tcod.KEY_ENTER and key.lalt:
            tcod.console_set_fullscreen(not tcod.console_is_fullscreen())

        index = key.c - ord('a')
        if index >= 0 and index < len(options):
            return index

        if index >= 0 and index <= 26:
            return None
Example #31
0
def _draw_status():
    con = CON_STATUS
    T.console_clear(con)
    con.default_fg = T.light_grey
    status = status_lines()
    con.print_(0, 0, '\n'.join(status))
    T.console_blit(CON_STATUS, 0, 0, STATUS_W, STATUS_H,
                   None, MAP_W+1, 1)
    def render(self):
        """
            Combine the map view and the menu view by blitting one onto the 
            other.
        """
        console = self.map_renderer.render(self.game_data.player)

        sub_console = self.menu_renderer.render(InGameMenuState.keys)

        libtcod.console_blit(sub_console, 0, 0, 0, 0, console, libtcod.console_get_width(console) - libtcod.console_get_width(sub_console), 0)

        return console
Example #33
0
 def resize(self, new_width, new_height):
     if new_width > 2 and new_height > 2:
         self._untouch_windows()
         resized_console = tcod.console_new(new_width, new_height)
         if self.framed_p:
             tcod.console_blit(self._c, 1, 1, self.width-2, self.height-2,
                               resized_console, 1, 1)
         else:
             tcod.console_blit(self._c, 0, 0, self.width, self.height,
                               resized_console, 0, 0)
         self._c = resized_console
         self.width = new_width
         self.height = new_height
         self._touch_windows()
Example #34
0
def _draw_messages():
    con = CON_BUFFER
    n = len(MESSAGES)
    if n == 0:
        return
    start = max(n-BUFFER_H,0)
    T.console_clear(con)
    for i in range(start, n):
        latest, s, color = MESSAGES[i]
        if not latest:
            color *= 0.6
        con.default_fg = color
        con.print_(0, i-start, s)
    T.console_blit(con, 0, 0, SCREEN_W, BUFFER_H,
                   None, 1, MAP_H+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, 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 render_all():
    global color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
 
    #go through all tiles, and set their background color
    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            wall = map[x][y].block_sight
            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 )
 
    #draw all objects in the list
    for object in objects:
        object.draw()
 
    #blit the contents of "con" to the root console
    libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)
Example #37
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 #38
0
    def blit(self, dest, sx, sy, width, height, dx, dy,
             fore_alpha, back_alpha):
        """Blit rectangular region of a console to a specific position
        in another console.

        dest = Destination console.

        sx, sy = Upper left corner of rectangle in source console to be
        blitted.

        width, height = Size of region in source console to be blitted.

        dx, dy = Location in destination console where rectangle will be
        blitted.

        fore_alpha, back_alpha = Foreground and background transparency
        parameters."""

        tcod.console_blit(self._c, sx, sy, width, height, dest._c, dx, dy,
                          fore_alpha, back_alpha)
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
Example #40
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 #41
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)
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
    for object in objects:
        object.draw()
 
    #blit the contents of "con" to the root console
    libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)
Example #43
0
    def render(self):
        """
            Render the current state of the battle. Called as many times as 
            required by the game loop.
        """
        console = self.renderer.render(self.game_data.battle_data, self.messages, self.selecting_pokeball)

        if len(self.messages) == 0 and self.display_level_up is not None:
            sub_console = self.level_up_renderer.render(self.display_level_up[0].creature, self.display_level_up[1])

            libtcod.console_blit(sub_console, 0, 0, 0, 0, console, 0, 0)

        # If we're in the process of catching a creature then there is an 
        # extra step which renders the catch graphics on top of the screen.
        if self.catching_with_pokeball:
            percent_to_display = self._percent_of_catch_to_display()
            message = None
            if percent_to_display == self.percent_of_creature_caught:
                message = battle_calculations.get_catch_message(self.percent_of_creature_caught,
                                                                self.game_data.battle_data.defending_creature())

            sub_console = self.catch_graphic_renderer.render(self.catching_with_pokeball, percent_to_display, message)

            libtcod.console_blit(sub_console,
                                 0, 0, 0, 0,
                                 console,
                                 libtcod.console_get_width(console) // 2 - libtcod.console_get_width(sub_console) // 2,
                                 libtcod.console_get_height(console) // 2 - libtcod.console_get_height(sub_console) // 2)

        # The check to see whether to end the battle is done once in the 
        # render function so that we can guarantee that it will get called
        # within a 30fps time frame.
        if len(self.messages) == 0 and self.display_level_up is None and self.end_battle:
            self.game.end_wild_battle()

        return console
Example #44
0
def test_console_blit(console, offscreen):
    libtcodpy.console_print(offscreen, 0, 0, 'test')
    libtcodpy.console_blit(offscreen, 0, 0, 0, 0, console, 0, 0, 1, 1)
    assertConsolesEqual(console, offscreen)
    libtcodpy.console_set_key_color(offscreen, libtcodpy.black)
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)