def main_menu(): img = libtcod.image_load('assets/menu.png') while not libtcod.console_is_window_closed(): #show the background image, at twice the regular console resolution libtcod.image_blit_2x(img, 0, 0, 0) #show the game's title, and some credits! libtcod.console_set_default_foreground(0, libtcod.light_yellow) libtcod.console_print_ex(0, int(SCREEN_WIDTH/2), int(SCREEN_HEIGHT/2-4), libtcod.BKGND_NONE, libtcod.CENTER, 'TYRMÄ') libtcod.console_print_ex(0, int(SCREEN_WIDTH/2), int(SCREEN_HEIGHT-2), libtcod.BKGND_NONE, libtcod.CENTER, 'By Hakaponttoauto') #show options and wait for the player's choice choice = menu('', ['Uusi peli', 'Jatka tallennuksesta', 'Lopeta'], 24) if choice == 0: #new game new_game() play_game() elif choice == 1: #load last game try: load_game() except: msgbox('\n Ei tallennettua peliä.\n', 24) continue play_game() elif choice == 2: #quit break
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 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 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 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 test_console_printing(console, fg, bg): libtcodpy.console_set_background_flag(console, libtcodpy.BKGND_SET) assert (libtcodpy.console_get_background_flag(console) == libtcodpy.BKGND_SET) libtcodpy.console_set_alignment(console, libtcodpy.LEFT) assert (libtcodpy.console_get_alignment(console) == libtcodpy.LEFT) libtcodpy.console_print(console, 0, 0, 'print') libtcodpy.console_print_ex(console, 0, 0, libtcodpy.BKGND_SET, libtcodpy.LEFT, 'print ex') assert (libtcodpy.console_print_rect( console, 0, 0, 8, 8, 'print rect') > 0 ) assert (libtcodpy.console_print_rect_ex( console, 0, 0, 8, 8, libtcodpy.BKGND_SET, libtcodpy.LEFT, 'print rect ex') > 0 ) assert (libtcodpy.console_get_height_rect( console, 0, 0, 8, 8, 'get height') > 0 ) libtcodpy.console_set_color_control(libtcodpy.COLCTRL_1, fg, bg)
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 menu(con, header, options, width, screen_width, screen_height): if len(options) > 26: raise ValueError('You cannot have more than 26 menu options') # calculate total height for header header_height = tcod.console_get_height_rect(con, 0, 0, width, screen_height, header) height = len(options) + header_height # create an off-screen console for menu's window window = tcod.console.Console(width, height) # print 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 out the options y = 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, tcod.BKGND_NONE, tcod.LEFT, text) y += 1 letter_index += 1 # blit the 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 render_des(root_console, des_panel, map_height, string): """ render the description bar """ tcod.console_set_default_foreground(des_panel, const.base2) tcod.console_print_ex(des_panel, 1, 0, tcod.BKGND_NONE, tcod.LEFT, string) des_panel.blit(dest=root_console, dest_y=map_height)
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 main_menu(): #img = libtcod.image_load('menu_background.png') while not libtcod.console_is_window_closed(): #libtcod.image_blit_2x(img,0,0,0) libtcod.console_set_default_foreground(0, libtcod.light_yellow) libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 4, libtcod.BKGND_NONE, libtcod.CENTER, "Libtcod Tutorial") libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.CENTER, "By Caleb") choice = menu('', ["Play a new game", "Continue last game", "Quit"], 24) if choice == 0: new_game() play_game() elif choice == 1: try: load_game() except: msgbox('\n No saved game to load.\n, 24') continue play_game() elif choice == 2: break
def render_popup(root_console, popup_panel, map_width, map_height, strings): """ Render the popup (description screen) """ tcod.console_clear(popup_panel) tcod.console_set_default_foreground(popup_panel, const.base2) # the first item of the list is the window title popup_panel.print_frame(0, 0, popup_panel.width, popup_panel.height, string=strings[0]) wraped_strings = [] first = True for s in strings: if first: first = False continue if s == "": wraped_strings.append(s) else: wraped_strings += textwrap.wrap(s, int(0.75 * popup_panel.width)) y = int(popup_panel.height / 2 - len(wraped_strings) / 2) for s in wraped_strings: tcod.console_print_ex(popup_panel, int(popup_panel.width / 2), y, tcod.BKGND_NONE, tcod.CENTER, s) y += 1 popup_panel.blit(dest=root_console, dest_x=round(5 * map_width / 24), dest_y=round(5 * map_height / 24), bg_alpha=0.9)
def main_menu(console, screen_width, screen_height): tcod.console_set_default_foreground(0, tcod.light_blue) tcod.console_print_ex(0, int(screen_width / 2), int(screen_height / 2) - 4, tcod.BKGND_NONE, tcod.CENTER, 'CS 4483 Game') tcod.console_print_ex(0, int(screen_width / 2), int(screen_height - 2), tcod.BKGND_NONE, tcod.CENTER, 'By Ralph Barac') menu(console, '', ['New Game', 'Quit'], 24 ,screen_width, screen_height)
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 main_menu(): img = libtcod.image_load('menu_background.png') while not libtcod.console_is_window_closed(): #show the background image, at twice the regular console resolution libtcod.image_blit_2x(img, 0, 0, 0) #show the game's title, and some credits! libtcod.console_set_default_foreground(0, libtcod.light_yellow) libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 4, libtcod.BKGND_NONE, libtcod.CENTER, 'TOMBS OF THE ANCIENT KINGS') libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.CENTER, 'By Jotaf') #show options and wait for the player's choice choice = menu('', ['Play a new game', 'Continue last game', 'Quit'], 24) if choice == 0: #new game new_game() play_game() if choice == 1: #load last game try: load_game() except: msgbox('\n No saved game to load.\n', 24) continue play_game() elif choice == 2: #quit break
def render_all(con, entities, player, game_map, fov_map, fov_recompute, SCREEN_WIDTH, SCREEN_HEIGHT, colors): if fov_recompute: # Draw all 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) # 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_set_default_foreground(con, libtcod.white) libtcod.console_print_ex(con, 1, SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.LEFT, 'HP: {0:02}/{1:02}'.format(player.fighter.hp, player.fighter.max_hp)) libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 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 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(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 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 main_menu(con, screen_width, screen_height): tcod.console_print_ex(0, int(screen_width / 2), int(screen_height / 2) - 10, tcod.BKGND_NONE, tcod.CENTER, 'ROGUESIMILAR') menu(con, '', ['NEW GAME', 'CONTINUE', 'QUIT'], 24, screen_width, screen_height)
def draw(self, console: int, colors: dict, force: bool = False) -> None: """ """ if self.needs_fov_recompute or force: for tile in self: visible = tcod.map_is_in_fov(self.fov_map, tile.x, tile.y) # XXX tile should take more responsibility for what it's color # is depending on it's configuration. # color = 0x000000 if tile.is_wall: color = colors["light_wall"] if visible else colors[ "dark_wall"] if tile.is_floor: color = colors["light_grnd"] if visible else colors[ "dark_grnd"] tcod.console_set_char_background(console, tile.x, tile.y, color, tcod.BKGND_SET) self.needs_fov_recompute = False for entity in sorted(self.entities, key=lambda x: x.kind.value): entity.draw(console) tcod.console_set_default_foreground(console, tcod.white) tcod.console_print_ex( console, 1, self.h - 2, tcod.BKGND_NONE, tcod.LEFT, f"HP: {self.player.hp:02d}/{self.player.max_hp:02d}", )
def render_bar(panel, x, y, total_width, name, value, bar_color, back_color): bar_width = total_width # int(float(value) / maximum * total_width) libtcod.console_set_default_background(con=panel, col=back_color) libtcod.console_rect(panel, x, y, total_width, 1, False, libtcod.BKGND_SCREEN) libtcod.console_set_default_background(con=panel, col=bar_color) if bar_width > 0: libtcod.console_rect(con=panel, x=x, y=y, w=bar_width, h=1, clr=False, flag=libtcod.BKGND_SCREEN) libtcod.console_set_default_foreground(con=panel, col=libtcod.white) libtcod.console_print_ex(con=panel, x=1, y=y, flag=libtcod.BKGND_NONE, alignment=libtcod.LEFT, fmt='[{}] {}'.format(y, name)) libtcod.console_print_ex(con=panel, x=total_width, y=y, flag=libtcod.BKGND_NONE, alignment=libtcod.RIGHT, fmt='CD:{}'.format(value))
def main_menu(): img = libtcod.image_load('kawaii.png') while not libtcod.console_is_window_closed(): #show bkgnd img at twice the size libtcod.image_blit_2x(img, 0, 0, 0) #show game title and credits libtcod.console_set_default_foreground(0, libtcod.purple) libtcod.console_print_ex(0, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-4, libtcod.BKGND_NONE, libtcod.CENTER, '~WOGUEY WIKEY~') libtcod.console_print_ex(0, SCREEN_WIDTH/2, SCREEN_HEIGHT-2, libtcod.BKGND_NONE, libtcod.CENTER, 'by n8uv') #show options and wait for the player's choice choice = menu('', ['Pway a new game!', 'Return to Daddy', 'Quit OwO'], 24) if choice == 0: #new game new_game() play_game() if choice == 1: #load last game try: load_game() except: msgbox('\n u dont have saved game \n', 24) continue play_game() elif choice == 2: #quit break
def menu(header, options, width, renderer): if len(options) > 26: raise ValueError('Cannot have 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(renderer.con, 0, 0, width, renderer.screen_height, header) height = len(options) + header_height # create an off-screen console that represents the menu's window window = tcod.console.Console(width, height) # print the header, with auto-wrap window.default_fg = 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 = '(' + 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(renderer.screen_width / 2 - width / 2) y = int(renderer.screen_height / 2 - height / 2) window.blit(renderer.root, x, y, 0, 0, width, height, 1.0, 0.7)
def main_menu(): img = libtcod.image_load('menu_background.png') while not libtcod.console_is_window_closed(): #show the background image, at twice the regular console resolution libtcod.image_blit_2x(img, 0, 0, 0) #show the game's title, and some credits! libtcod.console_set_default_foreground(0, libtcod.light_yellow) libtcod.console_print_ex(0, SCREEN_WIDTH//2, SCREEN_HEIGHT//2-4, libtcod.BKGND_NONE, libtcod.CENTER, 'TOMBS OF THE ANCIENT KINGS') libtcod.console_print_ex(0, SCREEN_WIDTH//2, SCREEN_HEIGHT-2, libtcod.BKGND_NONE, libtcod.CENTER, 'By Jotaf') #show options and wait for the player's choice choice = menu('', ['Play a new game', 'Continue last game', 'Quit'], 24) if choice == 0: #new game new_game() play_game() if choice == 1: #load last game try: load_game() except: msgbox('\n No saved game to load.\n', 24) continue play_game() elif choice == 2: #quit break
def 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 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(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 render_bar(x, y, total_width, name, value, maximum, bar_color, back_color): #render a bar (HP, experience, etc). first calculate the width of the bar bar_width = int(float(value) // maximum * total_width) #render the background first libtcod.console_set_default_background(panel, back_color) libtcod.console_rect(panel, x, y, total_width, 1, False, libtcod.BKGND_SCREEN) #now render the bar on top libtcod.console_set_default_background(panel, bar_color) if bar_width > 0: libtcod.console_rect(panel, x, y, bar_width, 1, False, libtcod.BKGND_SCREEN) #finally, some centered text with the values libtcod.console_set_default_foreground(panel, libtcod.white) libtcod.console_print_ex(panel, x + total_width // 2, y, libtcod.BKGND_NONE, libtcod.CENTER, name + ': ' + str(value) + '/' + str(maximum))
def render_all(): global fov_map, color_dark_wall, color_light_wall global color_dark_ground, color_light_ground global fov_recompute if fov_recompute: #recompute FOV if needed (the player moved or something) fov_recompute = False libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO) #go through all tiles, and set their background color according to the FOV for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): visible = libtcod.map_is_in_fov(fov_map, x, y) wall = map[x][y].block_sight if not visible: #if it's not visible right now, the player can only see it if it's explored if map[x][y].explored: if wall: libtcod.console_set_char_background(con, x, y, color_dark_wall, libtcod.BKGND_SET) else: libtcod.console_set_char_background(con, x, y, color_dark_ground, libtcod.BKGND_SET) else: #it's visible if wall: libtcod.console_set_char_background(con, x, y, color_light_wall, libtcod.BKGND_SET ) else: libtcod.console_set_char_background(con, x, y, color_light_ground, libtcod.BKGND_SET ) #since it's visible, explore it map[x][y].explored = True #draw all objects in the list, except the player. we want it to #always appear over all other objects! so it's drawn later. for object in objects: if object != player: object.draw() player.draw() #blit the contents of "con" to the root console libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0) #show the player's stats libtcod.console_set_default_foreground(con, libtcod.white) libtcod.console_print_ex(0, 1, SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.LEFT, 'HP: ' + str(player.fighter.hp) + '/' + str(player.fighter.max_hp))
def menu(header, options, width): if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.') #calculate total height for the header (after auto-wrap) and one line per option header_height = libtcod.console_get_height_rect(con, 0, 0, width, SCREEN_HEIGHT, header) if header == '': header_height = 0 height = len(options) + header_height #create an off-screen console that represents the menu's window window = libtcod.console_new(width, height) #print the header, with auto-wrap libtcod.console_set_default_foreground(window, libtcod.white) libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header) #print all the options y = header_height letter_index = ord('a') for option_text in options: text = '(' + chr(letter_index) + ') ' + option_text libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text) y += 1 letter_index += 1 #blit the contents of "window" to the root console x = SCREEN_WIDTH//2 - width//2 y = SCREEN_HEIGHT//2 - height//2 libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7) #present the root console to the player and wait for a key-press libtcod.console_flush() key = libtcod.console_wait_for_keypress(True) if key.vk == libtcod.KEY_ENTER and key.lalt: #(special case) Alt+Enter: toggle fullscreen libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) #convert the ASCII code to an index; if it corresponds to an option, return it index = key.c - ord('a') if index >= 0 and index < len(options): return index return None
def draw_string(self, x, y, fmt, bg_color=None, background_flag=tcod.BKGND_SET, align=tcod.LEFT): """Draw the string STR on the window object WIN at position X,Y. The string STR can contain color-changing directives - see the documentation for {defun dormouse:make-coloured-string} for details. Parameters ---------- string : A string which may contain formatting directives (see below). x, y : Coordinates where the string should be printed, relative to the top left corner of WIN. If the coordinates are negative then they are taken as relative to the bottom right corner of WIN. If the coordinates are :CENTRE then the start of the string is taken as the centre of the window. fg, bg : Foreground and background colours for the string. align : One of `'left'`, `'right'` or `'center'`. If alignment is `'right'`, the string is drawn so that its last character is located at X, Y; if `'centre'` so that the middle character is at X, Y. Examples -------- window.draw_string_at(`"Hello {blue}world!{/}"` 1 1 :fg :green) """ xstr = make_colored_string(fmt) prev_bg_color = self.default_background_color if bg_color is not None: # Hear the cries for a context manager! self.default_background_color = bg_color tcod.console_print_ex(self._c, x, y, background_flag, align, xstr) self.default_background_color = prev_bg_color
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)