def main(): constants = get_constants() libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False) con = libtcod.console_new(constants['screen_width'], constants['screen_height']) panel = libtcod.console_new(constants['screen_width'], constants['panel_height']) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False main_menu_background_image = libtcod.image_load('menu_background.png') key = libtcod.Key() mouse = libtcod.Mouse() while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if show_main_menu: main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height']) if show_load_error_message: message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height']) libtcod.console_flush() action = handle_main_menu(key) new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: player, entities, game_map, message_log, game_state = get_game_variables(constants) game_state = GameStates.PLAYERS_TURN show_main_menu = False elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game() show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: break else: libtcod.console_clear(con) play_game(player, entities, game_map, message_log, game_state, con, panel, constants) show_main_menu = True
def main(): constants = get_constants() # Reads image file for font type tcod.console_set_custom_font( 'arial10x10.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD) # Creates the screen given width, height, title, and a boolean for fullscreen tcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False) console_main = tcod.console_new(constants['screen_width'], constants['screen_height']) console_panel = tcod.console_new(constants['screen_width'], constants['panel_height']) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True key = tcod.Key() mouse = tcod.Mouse() while not tcod.console_is_window_closed(): tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key, mouse) if show_main_menu: main_menu(console_main, constants['screen_width'], constants['screen_height']) tcod.console_flush() action = handle_main_menu_input(key) new_game = action.get('new_game') exit_game = action.get('exit') if new_game: player, entities, game_map, message_log, game_state = get_game_variables( constants) game_state = GameStates.PLAYERS_TURN show_main_menu = False elif exit_game: break else: tcod.console_clear(console_main) game(player, entities, game_map, message_log, game_state, console_main, console_panel, constants) show_main_menu = True
def init(game): global CON, CON_MAP, CON_BUFFER, CON_STATUS, CON_INV, MESSAGES, GAME GAME = game T.console_set_custom_font(*FONTS[FONT_INDEX]) CON = T.console_init_root(SCREEN_W, SCREEN_H, TITLE, False) CON_MAP = T.console_new(MAP_W, MAP_H) CON_BUFFER = T.console_new(SCREEN_W, BUFFER_H) CON_STATUS = T.console_new(STATUS_W, STATUS_H) CON_INV = T.console_new(INV_W, INV_H) MESSAGES = []
def test_console_rexpaint_list_save_load(console, tmpdir): con1 = libtcodpy.console_new(8, 2) con2 = libtcodpy.console_new(8, 2) libtcodpy.console_print(con1, 0, 0, 'hello') libtcodpy.console_print(con2, 0, 0, 'world') xp_file = tmpdir.join('test.xp').strpath assert libtcodpy.console_list_save_xp([con1, con2], xp_file, 1) for a, b in zip([con1, con2], libtcodpy.console_list_load_xp(xp_file)): assertConsolesEqual(a, b) libtcodpy.console_delete(a) libtcodpy.console_delete(b)
def __init_screen(self): self.root = tcod.console_init_root(CONFIG.get('WIDTH'), CONFIG.get('HEIGHT'), CONFIG.get('TITLE'), False, None, 'C', True) self.con = tcod.console_new(CONFIG.get('WIDTH'), CONFIG.get('HEIGHT')) self.hotkeys = tcod.console_new(CONFIG.get('WIDTH'), CONFIG.get('ACTION_HEIGHT')) self.panel = tcod.console_new(CONFIG.get('WIDTH'), CONFIG.get('PANEL_HEIGHT')) self.upper_bar = tcod.console_new(CONFIG.get('WIDTH'), CONFIG.get('UPPER_BAR_HEIGHT'))
def main(): screenWidth = 111 screenHeight = 80 mapWidth = 76 mapHeight = 64 panel_x = mapWidth panelWidth = 35 colors = { 'HexDivider': libtcod.Color(50, 50, 100), 'HexInterior': libtcod.Color(5, 5, 5) } entities = [] hexes = [] planets = [] subsectorMap = ssMap(mapWidth, mapHeight) subsectorMap.make_map(hexes, planets) key = libtcod.Key() mouse = libtcod.Mouse() con = libtcod.console_new(screenWidth, screenHeight) panel = libtcod.console_new(panelWidth, screenHeight) libtcod.console_set_custom_font('lefont.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(screenWidth, screenHeight, 'MGTMapper', False) while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse) libtcod.console_set_default_foreground(0, libtcod.white) libtcod.console_blit(con, 0, 0, screenWidth, screenHeight, 0, 0, 0) render_all(con, panel, entities, hexes, planets, subsectorMap, screenWidth, screenHeight, colors, mouse, panelWidth, panel_x, mapWidth, mapHeight) libtcod.console_flush() clear_all(con, entities) action = handle_keys(key) mouse_action = handle_mouse(mouse) exit = action.get('exit') fullscreen = action.get('fullscreen') left_click = mouse_action.get('left_click') right_click = mouse_action.get('right_click') if exit: return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
def menu(header, options, width): 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) if header == '': header_height = 0 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 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) libtcod.console_flush() key = libtcod.console_wait_for_keypress(True) if key.vk == libtcod.KEY_ENTER: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) index = key.c - ord('a') if index >= 0 and index < len(options): return index return None
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 total height for the header (after auto-wrap) and one line per option header_height = tcod.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 = tcod.console_new(width, height) # print the header, with auto-wrap 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 the options y = header_height letter_index = ord("a") for option_text in options: if option_text == "Inventory is empty.": text = f"( ) {option_text}" else: text = f"({chr(letter_index)}) {option_text}" tcod.console_print_ex(window, 0, y, tcod.BKGND_NONE, tcod.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) tcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
def draw_manual_page(pages, index, line, width, height, break_point): page = pages[index] page_counter = f'Page {index+1}/{len(pages)}' x = 0 y = 0 offset = 1 # ensures that strings aren't drawn on the borders # Create the window # window = tcod.console_new(width, height) window.caption = 'Manual' setup_console(window, borders=True, bordercolor=colors.darker_red) print_line(window, width - len(page_counter) - offset, 0, page_counter) print_line(window, offset, height - offset, '<Directional keys to navigate>') print_line(window, width - 15, height - offset, '<ESC to close>') for line_count, paragraph in enumerate(page[line:]): line_count += offset print_line(window, 1, line_count, paragraph) if line_count + break_point > height: breaker = '# MORE #' print_line(window, width // 2 - len(breaker), line_count + 1, breaker, color=colors.grey) break tcod.console_blit(window, 0, 0, width, height, 0, x, y, 1, 1) tcod.console_flush() return window
def character_screen(player, character_screen_width, character_screen_height, screen_width, screen_height): window = tcod.console_new(character_screen_width, character_screen_height) tcod.console_set_default_foreground(window, tcod.white) tcod.console_print_rect_ex(window, 0, 1, character_screen_width, character_screen_height, tcod.BKGND_NONE, tcod.LEFT, 'Character Information') tcod.console_print_rect_ex(window, 0, 2, character_screen_width, character_screen_height, tcod.BKGND_NONE, tcod.LEFT, 'Level: {0}'.format(player.level.current_level)) tcod.console_print_rect_ex( window, 0, 3, character_screen_width, character_screen_height, tcod.BKGND_NONE, tcod.LEFT, 'Experience: {0}'.format(player.level.current_xp)) tcod.console_print_rect_ex( window, 0, 4, character_screen_width, character_screen_height, tcod.BKGND_NONE, tcod.LEFT, 'Experience to Level: {0}'.format( player.level.experience_to_next_level)) tcod.console_print_rect_ex(window, 0, 6, character_screen_width, character_screen_height, tcod.BKGND_NONE, tcod.LEFT, 'Maximum HP: {0}'.format(player.fighter.max_hp)) tcod.console_print_rect_ex(window, 0, 7, character_screen_width, character_screen_height, tcod.BKGND_NONE, tcod.LEFT, 'Attack: {0}'.format(player.fighter.power)) tcod.console_print_rect_ex(window, 0, 8, character_screen_width, character_screen_height, tcod.BKGND_NONE, tcod.LEFT, 'Defense: {0}'.format(player.fighter.defense)) x = screen_width // 2 - character_screen_width // 2 y = screen_height // 2 - character_screen_height // 2 tcod.console_blit(window, 0, 0, character_screen_width, character_screen_height, 0, x, y, 1.0, 0.7)
def menu(con, header, options, width, screen_width, screen_height, root): if len(options) > 25: 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 = tcod.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 = tcod.console_new(width, height) # print the header, with auto-wrap 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 the options y = header_height letter_index = 1 if len(options) > 0: MenuState.menu_state = MenuState.menu_state % len(options) for option_index in range(0, len(options)): if option_index == MenuState.menu_state and MenuState.menu_state < len(options): text = '(' + "X" + ') ' + options[option_index] else: text = '(' + " " + ') ' + options[option_index] tcod.console_print_ex(window, 0, y, tcod.BKGND_NONE, tcod.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) tcod.console_blit(window, 0, 0, width, height, root, x, y, 1.0, 0.7)
def help_menu(con, width, screen_width, screen_height): height = screen_height window = libtcod.console_new(width, height) libtcod.console_set_default_foreground(window, libtcod.white) header = 'Help' text = [ 'Use wasd to move;', 'Use g to pick up items;', 'Use b to drop items;', 'Use i to open inventory;', 'Use p to toggle realtime mode on and off' 'Use t to teleport to the next floor', 'Be advised though, the deeper you go, the more dangerous dungeon becomes' 'Hover mouse over something, to see what is it. ', 'Press esc to exit', '', 'Now go explore dungeon and genocide local population.' ] libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header) y = 1 for elem in text: libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, elem) 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 menu(main_console, header, options, width, screen_width, screen_height): 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 = main_console.get_height_rect(0, 0, width, screen_height, header) height = len(options) + header_height # create an off-screen console that represents the menu's window window = tcod.console_new(width, height) # print the header, with auto-wrap window.default_bg = tcod.white tcod.console_print_rect_ex(window, 0, 0, width, height, tcod.BKGND_NONE, tcod.LEFT, header) # print all the options y = header_height letter_index = ord('a') for option_text in options: text = '({}) {}'.format(chr(letter_index), option_text) tcod.console_print_ex(window, 0, y, tcod.BKGND_NONE, tcod.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) # tcod.console_blit(window, 0, 0, width, height, main_console, x, y, 1.0, 0.7) window.blit(main_console, x, y, 0, 0, width, height, 1.0, 0.7)
def menu(con, header: str, options: List[str], width: int): if len(options) > 26: raise ValueError('Cannot have more than 26 options') # Calculate total height for the header (after textwrap) and one line per option header_height = libtcod.console_get_height_rect(con, 0, 0, width, constants.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 wrapped text libtcod.console_set_default_foreground(window, colors.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 = f'({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 = constants.screen_width // 2 - width // 2 y = constants.screen_height // 2 - height // 2 # noinspection PyTypeChecker libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
def menu(con, header, options, width, screenWidth, screenHeight): if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.') # Calculate height for header and one line per option headerHeight = tcod.console_get_height_rect(con, 0, 0, width, screenHeight, header) height = len(options) + headerHeight # Create off-screen console with menu's window window = tcod.console_new(width, height) # Print header with auto-wrap tcod.console_set_default_foreground(window, tcod.white) tcod.console_print_ex(window, 0, 0, tcod.BKGND_NONE, tcod.LEFT, header) # Print Options 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 # BLit contents to root console 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)
def menu(console, header, options, width, screen_width, screen_height): """ Main game menu (displays options available for selection) """ if len(options) > 26: raise ValueError("Cannot have a menu with more than 26 options") # total height for the header (after auto-wrap) and one line per option header_height = tcod.console_get_height_rect(console, 0, 0, width, screen_height, header) height = len(options) + header_height # create an off-screen console that represents the menu's window window = tcod.console_new(width, height) # print the header, with auto-wrap 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 the options y_pos = header_height letter_index = ord("a") for option_text in options: text = f"({chr(letter_index)})" + option_text tcod.console_print_ex(window, 0, y_pos, tcod.BKGND_NONE, tcod.LEFT, text) y_pos += 1 letter_index += 1 # blit the contents of 'window' to the root console x_pos = int(screen_width / 2 - width / 2) y_pos = int(screen_height / 2 - height / 2) tcod.console_blit(window, 0, 0, width, height, 0, x_pos, y_pos, 1.0, 0.7)
def __init__(self): # Initialization libtcodpy.console_set_custom_font('src/arial10x10.png', libtcodpy.FONT_TYPE_GREYSCALE | libtcodpy.FONT_LAYOUT_TCOD) libtcodpy.console_init_root(settings.SCREEN_WIDTH, settings.SCREEN_HEIGHT, 'ROGuelike TUTorial', False) libtcodpy.sys_set_fps(settings.LIMIT_FPS) self.con = libtcodpy.console_new(settings.SCREEN_WIDTH, settings.SCREEN_HEIGHT) self.game_map = GameMap(self.con) player_x, player_y = self.game_map.get_staring_position() # game objects self.player = Player( 'Player', self.con, player_x, player_y, '@', fighter=Fighter(hp=15, defense=5, power=5, death_function=player_death)) npc_x, npc_y = self.game_map.get_ending_position() self.npc = Npc('Trader', self.con, npc_x, npc_y, '@') self.objects = [self.npc, self.player] self.npcs = [self.npc] for monster in self.game_map.place_monsters(): self.objects.append(monster) if hasattr(monster, 'is_selfmoving') and monster.is_selfmoving: self.npcs.append(monster) self.game_state = 'playing' self.player_action = None
def render_game_menu(con, header, options, width, screen_width, screen_height, game_state, index): window = libtcodpy.console_new(width, 30) header_height = libtcodpy.console_get_height_rect(con, 0, 0, width, screen_height, header) height = len(options) + header_height y = header_height letter_index = ord('a') for i in range(len(options)): # text = '(' + chr(letter_index) + ') ' + option_text if i == index: libtcodpy.console_print_ex( window, int(width / 2), y, libtcodpy.BKGND_SET, libtcodpy.CENTER, '%c{0}%c'.format(options[i]) % (libtcodpy.COLCTRL_1, libtcodpy.COLCTRL_STOP)) else: libtcodpy.console_print_ex(window, int(width / 2), y, libtcodpy.BKGND_SET, libtcodpy.CENTER, '{0}'.format(options[i])) y += 2 letter_index += 1 libtcodpy.console_blit(window, 0, 0, width, 30, 0, int(screen_width - 80), screen_height - 30, 1.0, 0.7)
def mirror_screen(player, mirror_width, mirror_height, screen_width, screen_height): window = tcod.console_new(mirror_width, mirror_height) tcod.console_set_default_foreground(window, tcod.white) tcod.console_print_rect_ex(window, 0, 1, mirror_width, mirror_height, tcod.BKGND_NONE, tcod.LEFT, 'In the Mirror you see yourself:') tcod.console_print_rect_ex(window, 0, 2, mirror_width, mirror_height, tcod.BKGND_NONE, tcod.LEFT, 'Level: {0}'.format(player.level.current_level)) tcod.console_print_rect_ex( window, 0, 3, mirror_width, mirror_height, tcod.BKGND_NONE, tcod.LEFT, 'Experience: {0}'.format(player.level.current_xp)) tcod.console_print_rect_ex( window, 0, 4, mirror_width, mirror_height, tcod.BKGND_NONE, tcod.LEFT, 'Experience until next level: {0}'.format( player.level.experience_to_next_level)) tcod.console_print_rect_ex( window, 0, 6, mirror_width, mirror_height, tcod.BKGND_NONE, tcod.LEFT, 'Maximum HP: {0}'.format(player.combatant.max_hp)) tcod.console_print_rect_ex(window, 0, 7, mirror_width, mirror_height, tcod.BKGND_NONE, tcod.LEFT, 'Attack: {0}'.format(player.combatant.attack)) tcod.console_print_rect_ex(window, 0, 8, mirror_width, mirror_height, tcod.BKGND_NONE, tcod.LEFT, 'Armour Class: {0}'.format(player.combatant.ac)) x = screen_width // 2 - mirror_width // 2 y = screen_height // 2 - mirror_height // 2 tcod.console_blit(window, 0, 0, mirror_width, mirror_height, 0, x, y, 1.0, 0.7)
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) 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) #present the root console to the player and wait for a key-press libtcod.console_flush() key = libtcod.console_wait_for_keypress(True) #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
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 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)
def process(self): window = tcod.console_new(self.width, self.height) tcod.console_set_default_foreground(window, tcod.white) """(con, x, y, w, h, flag, alignment, fmt)""" info = self.get_player_info() for y, text in enumerate(info): tcod.console_print_rect_ex( con=window, x=0, y=y, w=self.width, h=self.height, flag=tcod.BKGND_NONE, alignment=tcod.LEFT, fmt=text ) x = const.SCREEN_WIDTH // 2 - self.width // 2 y = const.SCREEN_HEIGHT // 2 - self.height // 2 window.blit( dest=self.scene.manager.root_console, dest_x=x, dest_y=y, src_x=0, src_y=0, width=self.width, height=self.height, fg_alpha=1.0, bg_alpha=0.7, key_color=None ) tcod.console_flush()
def __init__(self, x, y, w, h, default, mode, insert): # init self.console = libtcod.console_new(w, h) self.init_time = time.time() self.x = x self.w = w self.y = y self.h = h self.mode = mode self.text = default self.default = default self.keyInput = '' self.redraw_cursor = True self.render_text = True self.flush = False self.key = key self.mouse = mouse self.cursor = Cursor() self.cursor.set_pos(x, y) self.insert_mode = insert #replace the character under the cursor or shift it aside? #ignore buffer get_raw_input()
def menu(con, header, options, width, screen_width, screen_height): if len(options) > 26: raise ValueError('Cannot have menu with more than 26 options') #calc total height for header after auto-wrap, one line per option header_height = libtcod.console_get_height_rect(con, 0, 0, width, screen_height, header) height = len(options) + header_height #create off-screen console for menu window window = libtcod.console_new(width, height) #print 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 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 to to root console from window y = int(screen_height / 2 - height / 2) x = int(screen_width / 2 - width / 2) libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
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 total height for header, auto wrap, and one line per option header_height = tcod.console_get_height_rect(con, 0, 0, width, screen_height, header) height = len(options) + header_height # create off-screen console representing menu's window window = tcod.console_new(width, height) # print header w/ auto wrap 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 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 # blit contents of window to root console 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)
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
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 total height for the header (after auto-wrap) and one line per option header_height = tcod.console_get_height_rect(con, 0, 0, width, screen_height, header) height = len(options) + header_height # Offscreen console that shows the menu window = tcod.console_new(width, height) # Print the head with auto-wrap 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 options 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 # blit contents of window to the root console x = int(screen_width / 2 - width / 2) y = int(screen_height / 2 - height / 2) # If header is empty string, don't draw that line if header == '': tcod.console_blit(window, 0, 1, width, height, 0, x, y, 1.0, 0.5) else: tcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.5)
def __init__(self, x, y, w, h, name, color=tcod.black): self.x = x self.y = y self.name = name self.con = tcod.console_new(w, h) self.con.default_bg = color self.con.default_fg = tcod.white
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, 'Maximum HP: {0}'.format(player.fighter.max_hp)) libtcod.console_print_rect_ex(window, 0, 4, character_screen_width, character_screen_height, libtcod.BKGND_NONE, libtcod.LEFT, 'Attack: {0}'.format(player.fighter.power)) libtcod.console_print_rect_ex( window, 0, 5, character_screen_width, character_screen_height, libtcod.BKGND_NONE, libtcod.LEFT, 'Defence: {0}'.format(player.fighter.defence)) libtcod.console_print_rect_ex( window, 0, 6, character_screen_width, character_screen_height, libtcod.BKGND_NONE, libtcod.LEFT, 'Intelligence: {0}'.format(player.fighter.intelligence)) libtcod.console_print_rect_ex( window, 0, 7, character_screen_width, character_screen_height, libtcod.BKGND_NONE, libtcod.LEFT, 'Dexterity: {0}'.format(player.fighter.dexterity)) 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 menu(console, header, options, width, screen_width, screen_height): if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.') # Calculates the total height for the header and does one line per option header_height = tcod.console_get_height_rect(console, 0, 0, width, screen_height, header) height = len(options) + header_height # Creates a new console that represents the menu window window = tcod.console_new(width, height) # Prints the header tcod.console_set_default_foreground(window, tcod.white) tcod.console_print_rect_ex(window, 0, 0, width, height, tcod.BKGND_NONE, tcod.LEFT, header) # Prints the options in the menu y = header_height letter_index = ord('a') for option in options: text = '(' + chr(letter_index) + ')' + option 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)
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_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 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 __init__(self, width, height, buffered=False): self.width = width self.height = height self._c = tcod.console_new(width, height) self.default_background_color = tcod.black self.default_foreground_color = tcod.white # tcod.console_set_default_background(self._c, tcod.black) # tcod.console_set_default_foreground(self._c, tcod.white) tcod.console_clear(self._c) if buffered: self.buffer = ConsoleBuffer(self)
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()
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
def __init__(self, game): self.game = game self.console = libtcod.console_new(settings.SCREEN_WIDTH, settings.SCREEN_HEIGHT)
def __init__(self, game): self.game = game self.console = libtcod.console_new(CatchGraphicRenderer.width, CatchGraphicRenderer.height)
def __init__(self, game): self.game = game self.console = libtcod.console_new(LevelUpRenderer.width, LevelUpRenderer.height)
def create_console(title: str, console_width: int, console_height: int, font_file: str, fps_limit: int): libtcod.console_set_custom_font(fontFile=font_file, flags=libtcod.FONT_LAYOUT_ASCII_INROW) libtcod.console_init_root(w=console_width, h=console_height, title=title, fullscreen=False) libtcod.sys_set_fps(fps_limit) return libtcod.console_new(w=console_width, h=console_height)
player.move(-1, 0) fov_recompute = True elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT): player.move(1, 0) fov_recompute = True ############################################# # Initialization & Main Loop ############################################# libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/libtcod tutorial', False) libtcod.sys_set_fps(LIMIT_FPS) con = libtcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT) #create object representing the player player = Object(SCREEN_WIDTH//2, SCREEN_HEIGHT//2, '@', libtcod.white) #create an NPC npc = Object(SCREEN_WIDTH//2 - 5, SCREEN_HEIGHT//2, '@', libtcod.yellow) #the list of objects with those two objects = [npc, player] #generate map (at this point it's not drawn to the screen) make_map() #create the FOV map, according to the generated map fov_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT)
#heal the player if player.fighter.hp == player.fighter.max_hp: message('You are already at full health.', libtcod.red) return 'cancelled' message('Your wounds start to feel better!', libtcod.light_violet) player.fighter.heal(HEAL_AMOUNT) ############################################# # Initialization & Main Loop ############################################# libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/libtcod tutorial', False) libtcod.sys_set_fps(LIMIT_FPS) con = libtcod.console_new(MAP_WIDTH, MAP_HEIGHT) panel = libtcod.console_new(SCREEN_WIDTH, PANEL_HEIGHT) #create object representing the player fighter_component = Fighter(hp=30, defense=2, power=5, death_function=player_death) player = Object(0, 0, '@', 'player', libtcod.white, blocks=True, fighter=fighter_component) #the list of objects with just the player objects = [player] #generate map (at this point it's not drawn to the screen) make_map() #create the FOV map, according to the generated map fov_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for y in range(MAP_HEIGHT):
def __init__(self, game): self.game = game self.console = libtcod.console_new(settings.SCREEN_WIDTH, settings.SCREEN_HEIGHT) self.max_rows = self.column_height - 1 self.max_columns = len(self.game.static_game_data.species) // self.column_height
def __init__(self): self.console = libtcod.console_new(settings.SCREEN_WIDTH, settings.SCREEN_HEIGHT) self.start_x = self.start_y = 0