def panel2_display(): str_s = 'Str:' + str(player.fighter.status.Str) con_s = 'Con:' + str(player.fighter.status.Con) dex_s = 'Dex:' + str(player.fighter.status.Dex) int_s = 'Int:' + str(player.fighter.status.Int) car_s = player.fighter.status.career panel2_msgs = [player.name, str_s, con_s, dex_s, int_s, ' ', 'career', car_s, ' '] skill_msgs = ['Skills:'] #print skills s = player.fighter.total_skills for index in s: skill_msgs.append(str(index) + ')' + s[index][0] + ' [' + s[index][1] + ']') passive_msgs = ['','Passive:'] #print passive for index in player.fighter.status.passives: passive_msgs.append(player.fighter.status.passives[index]) panel2_msgs.extend(skill_msgs) panel2_msgs.extend(passive_msgs) libtcod.console_set_default_background(panel2, libtcod.black) libtcod.console_clear(panel2) y = 1 for lines in panel2_msgs: libtcod.console_set_default_foreground(panel2, libtcod.white) libtcod.console_print_ex(panel2, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, lines) y += 1 libtcod.console_blit(panel2, 0 , 0, PANEL2_WIDTH, PANEL2_HEIGHT, 0 ,PANEL2_X, 0)
def main_menu(): """ Game main menu """ img = libtcod.image_load('menu_background.png') title = 'Rumble in the Underdeep' author = 'By @cr8ivecodesmith' while not libtcod.console_is_window_closed(): # blit the bg image at twice the regular console resolution libtcod.image_blit_2x(img, 0, 0, 0) libtcod.console_set_default_foreground(0, libtcod.gold) libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 4, libtcod.BKGND_NONE, libtcod.CENTER, title) libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.CENTER, author) # show the options and wait for the player's input choice = menu('', ['New game', 'Continue', 'Quit'], 24) if choice == 0: # New game new_game() play_game() elif choice == 1: try: load_game() play_game() except Exception as e: print(e) msgbox('\nNo saved game to load.\n', 24) continue elif choice == 2: # Quit break
def main_menu(): img = libtcod.image_load('menu_background.png') while not libtcod.console_is_window_closed(): #show the menu image in a terrible way libtcod.image_blit_2x(img, 0, 0, 0) #fancy main menu title and crediting libtcod.console_set_default_foreground(0, libtcod.white) libtcod.console_set_default_background(0, libtcod.black) libtcod.console_print_ex(0, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-4, libtcod.BKGND_ALPHA(0.7), libtcod.CENTER, 'JOTAF\'S COMPLETE ROGUELIKE TUTORIAL,') libtcod.console_print_ex(0, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-3, libtcod.BKGND_ALPHA(0.7), libtcod.CENTER, 'USING PYTHON+LIBTCOD') #libtcod.console_print_ex(0, SCREEN_WIDTH/2, SCREEN_HEIGHT-2, libtcod.BKGND_ALPHA(0.7), libtcod.CENTER, 'Implemented By') #show main menu optionss and request selection choice = menu('', ['Play a new game', 'Continue last game', 'Quit'], 24) #fullscreen toggle needs to work in main menu too #if key.vk == libtcod.KEY_ENTER and key.lalt: # libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) if choice == 0: #new game new_game() play_game() elif choice == 1: #load game try: load_game() except: msgbox('\n No saved game to load.\n', 24) continue play_game() elif choice == 2: #quit break
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 and key.lalt: #(special case) Alt+Enter: toggle fullscreen 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 draw_panel(player, pointer_location): """ Refreshes the UI display and blits it to the window. """ libtcod.console_set_default_background(_panel, libtcod.black) libtcod.console_clear(_panel) # Only display the (log.MSG_HEIGHT) most recent write_log(log.game_msgs[-log.MSG_HEIGHT:], _panel, MSG_X, 1) _render_bar(1, 1, config.BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp, libtcod.light_red, libtcod.darker_red) libtcod.console_print_ex( _panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT, 'Dungeon level ' + str(player.current_map.dungeon_level)) # _debug_positions(player, mouse) # _debug_room(player) # _debug_danger(player) _debug_fps() 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(player, pointer_location)) # Done with "_panel", blit it to the root console. libtcod.console_blit(_panel, 0, 0, config.SCREEN_WIDTH, config.PANEL_HEIGHT, 0, 0, PANEL_Y)
def menu(header, options, width): if len(options) > 26: raise ValueError("Cannot have a menu with more than 26 options.") #TODO: expand inventory. 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") #can be replaced with a list i'll iterate over when i want more positions for option_text in options: text = "({0}) {1}".format(chr(letter_index), option_text) libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text) y += 1 letter_index += 1 #center and show menu 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) index = key.c - ord("a") if index >= 0 and index < len(options): return index else: return None
def menu(header, options, width): if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.') #menu cannot have 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 #creating new window to draw menu window = libtcod.console_new(width, height) #print header 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 main screen 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) #last two parameters represent foreground and background transparency, respectively #flush and wait for keypress libtcod.console_flush() key = libtcod.console_wait_for_keypress(True) if key.vk == libtcod.KEY_ENTER and key.lalt: 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 menu(header, options, width): if len(options) > 26: raise ValueError('Cannot have a menu with over 26 options.') header_height = libtcod.console_get_height_rect(view, 0, 0, width, const.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 = const.SCREEN_WIDTH / 2 - width / 2 y = const.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) index = key.c - ord('a') if index >= 0 and index < len(options): return index return None
def main_menu(): img = libtcod.image_load('menu_background1.png') libtcod.image_blit_2x(img, 0, 0, 0) # Make a new mini-game-loop. 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 and W. Stacks') # Show options and wait for the player's choice choice = menu('', ['Play a new game', 'Continue last game', 'Quit'], 24) if choice == 0: # Index of "play a new game" new_game() play_game() elif 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 main_menu(window, background_image, screen_width, screen_height, mouse): libtcod.image_blit_2x(background_image, 0, 0, 0) libtcod.console_set_default_foreground(0, libtcod.black) libtcod.console_print_ex( 0, screen_width // 2 - 7, screen_height // 2 - 4, libtcod.BKGND_NONE, libtcod.CENTER, "You look hungry" ) return menu_clickable( window, "", ["Play a new game", "Continue last game", "Quit"], 24, screen_width, screen_height, mouse )
def areyousure(con,screen_width, screen_height): libtcod.console_set_default_foreground(0, libtcod.white) libtcod.console_print_ex(0, int(screen_width / 2), int(screen_height / 2) - 4, libtcod.BKGND_NONE, libtcod.CENTER, 'Are you sure? This will delete your previous save.') menu(con, '', ['Yes, I am sure.', 'No, take me back!'], 24, screen_width, screen_height)
def menu(con, header, options, width, screenWidth, screenHeight): if len(options) > 28: raise ValueError('Cannot have a menu with more than 26 options.') # calculate height of header (post auto-wrap) and one line per option headerHeight = libtcod.console_get_height_rect(con,0,0,width, screenHeight, header) height = len(options) + headerHeight # create off-screen console that reps the menu's window window = libtcod.console_new(width,height) # print header w/ 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 = headerHeight letterIndex = ord('a') for optionText in options: text = '(' + chr(letterIndex) + ') ' + optionText libtcod.console_print_ex(window,0,y,libtcod.BKGND_NONE, libtcod.LEFT, text) y += 1 letterIndex += 1 # blit contents of window to root console x = int(screenWidth/2 - width/2) y = int(screenHeight/2 - height/2) libtcod.console_blit(window,0,0,width,height,0,x,y,1.0,0.7)
def menu(header, options, width): #add functionality of pages 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 = 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) index = key.c - ord('a') if index >= 0 and index < len(options): return index return None
def print_string(self, x, y, s, alignment=None, bkgnd_flag=None): if alignment or bkgnd_flag: if not alignment: alignment = self.get_alignment() if not bkgnd_flag: bkgnd_flag = self.get_background_flag() libtcod.console_print_ex(self.con,x,y,bkgnd_flag,alignment,s) else: libtcod.console_print(self.con,x,y,s)
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) #title and 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, 'JESUS CHRIST: PATH TO RESSURECTION') libtcod.console_print_ex(0, SCREEN_WIDTH/2, SCREEN_HEIGHT-2, libtcod.BKGND_NONE, libtcod.CENTER, 'a game by Peter Rao') #show main menu choice = menu("", ["Play a new game", "Continue last game", "Quit"], 24) if choice == 0: #new game new_game() play_game() if choice == 1: #load game try: load_game() except: msgbox('\n No saved game to load.\n', 24) #libtcod.console_wait_for_keypress(True) continue play_game() if choice == 2: #quit break
def draw(self): """Draws borders around the info panel.""" libt.console_set_default_background(self.handler.gui, data.COLOURS['gui_bg']) libt.console_clear(self.handler.gui) upper_height = config.BORDER_WIDTH / 2 left_height = config.GUI_HEIGHT - upper_height*2 libt.console_set_default_background(self.handler.gui, data.COLOURS['gui_border']) # Upper border libt.console_rect(self.handler.gui, 0, 0, config.GUI_WIDTH, upper_height, False, libt.BKGND_SCREEN) # Lower border libt.console_rect(self.handler.gui, 0, config.GUI_HEIGHT - config.BORDER_WIDTH/2, config.GUI_WIDTH, upper_height, False, libt.BKGND_SCREEN) # Left border libt.console_rect(self.handler.gui, 0, upper_height, config.BORDER_WIDTH / 2, left_height, False, libt.BKGND_SCREEN) # Right border libt.console_rect(self.handler.gui, config.GUI_WIDTH - config.BORDER_WIDTH/2, upper_height, config.BORDER_WIDTH / 2, left_height, False, libt.BKGND_SCREEN) # Middle border libt.console_rect(self.handler.gui, (config.GUI_WIDTH - 1)/2 - config.BORDER_WIDTH/2, upper_height, config.BORDER_WIDTH, left_height, False, libt.BKGND_SCREEN) # Hover details libt.console_set_default_foreground(self.handler.gui, data.COLOURS['text']) libt.console_print_ex(self.handler.gui, (config.GUI_WIDTH - 1)/2, 0, libt.BKGND_NONE, libt.CENTER, self.objects_under_mouse())
def main_menu(): main_init() while not libtcod.console_is_window_closed(): #now show the imageAt twice the size. libtcod.console_set_default_foreground(0, libtcod.light_yellow) libtcod.console_print_ex(0, R.SCREEN_WIDTH / 2, R.SCREEN_HEIGHT / 2 - 4, libtcod.BKGND_NONE, libtcod.CENTER, 'Trader-RL') libtcod.console_print_ex(0, R.SCREEN_WIDTH / 2, R.SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.CENTER, 'By Lemmily') choice = R.ui.menu("", ["Play a new game", "Continue last game", "Quit"], 24) if choice == 0: #new game #game_screen_init() new_game() play_game() #msgbox("Hey there") elif choice == 1: try: load_game() except: R.ui.msgbox("\n No saved game to load. \n", 24) continue play_game() elif choice == 2: break
def show_status(self, con): libtcod.console_set_default_foreground(con, libtcod.white) hptext = "Dead." if self.player.properties['combat'] is not None: hptext = 'HP: ' + str(self.player.properties['combat'].hp) + '/' + str(self.player.properties['combat'].max_hp) libtcod.console_print_ex(con, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, hptext)
def finish_welcome(): libtcod.console_set_default_foreground(0, libtcod.darker_yellow) libtcod.console_print_ex(0, config.SCREEN_WIDTH / 2, config.SCREEN_HEIGHT - 4, libtcod.BKGND_NONE, libtcod.CENTER, 'Press any key to continue...') libtcod.console_flush() block_for_key()
def main_menu(): img = libtcod.image_load('title.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.black) libtcod.console_print_ex(0, SCREEN_WIDTH / 2, int(SCREEN_HEIGHT * .75), libtcod.BKGND_NONE, libtcod.CENTER, 'WizRL') libtcod.console_print_ex(0, SCREEN_WIDTH / 2, int(SCREEN_HEIGHT * .75) + 2, libtcod.BKGND_NONE, libtcod.CENTER, 'By Dragyn') # 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 libtcod.console_clear(0) 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: 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 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(header, options, width): #First, make sure the menu has 26 or fewer items (This is due to an alphabetical selection limitation) if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options!') #implicitly calculate the height of the window, based on the header height (after word wrap) and the number # of 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 #Create an offscreen console that represents the menus window, and a slightly larger one to nest the menu inside of #This will create a border effect for the inner menu, strictly asthetic outer_window = libtcod.console_new(width + 2, height + 2) window = libtcod.console_new(width, height) #Print the header to our offscreen console libtcod.console_set_default_foreground(window, libtcod.white) libtcod.console_set_default_background(window, libtcod.darker_sepia) libtcod.console_clear(window) libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header) #Print all the options, with a corresponding ASCII character y = header_height #Get the ASCII value of the letter 'a' 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 the window to the main game screen, centered x = SCREEN_WIDTH / 2 - width / 2 y = SCREEN_HEIGHT /2 - height / 2 #Set up the outer window (which only acts as a border for the inner window, strictly graphical) libtcod.console_set_default_background(outer_window, libtcod.brass) libtcod.console_clear(outer_window) #Blit the actual message window onto the outer window, centered and one off from the borders libtcod.console_blit(window, 0, 0, width, height, outer_window, 1, 1) #Blit the outer window onto the screen, centered libtcod.console_blit(outer_window, 0, 0, width + 2, height + 2, 0, x, y) #Now that the console is presented to the player, wait for them to make a choice before doing anything else libtcod.console_flush() key = libtcod.console_wait_for_keypress(True) #Clear the main console, so no artifacts from the menu appear libtcod.console_clear(0) #Check for fullscreen keys if key.vk == libtcod.KEY_ENTER and key.lalt: #ALT + Enter, toggle fullscreen libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) #Convert the ASCII code to an index; if it corresponds to a valid menu item, return it index = key.c - ord('a') if index >= 0 and index < len(options): return index return None
def main_menu(con, background_image, screen_width, screen_height): libtcod.image_blit_2x(background_image, 0, 0, 0) 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, "JANGO AND THE SKETS", ) libtcod.console_print_ex( 0, int(screen_width / 2), int(screen_height - 2), libtcod.BKGND_NONE, libtcod.CENTER, "By The Beej", ) menu( con, "", ["Play a new game", "Continue last game", "Quit"], 24, screen_width, screen_height, )
def show_menu(self, options, header, hide_options=False): """ Show menu with header and options in the screen. """ #calculate total height for the header (after auto-wrap) header_height = libtcod.console_get_height_rect(self.inv_window, 0, 0, MAP_WIDTH, MAP_HEIGHT, header) #print the header, with auto-wrap libtcod.console_set_default_foreground(self.inv_window, libtcod.white) libtcod.console_print_rect_ex(self.inv_window, 0, 0, MAP_WIDTH, MAP_HEIGHT, libtcod.BKGND_NONE, libtcod.LEFT, header) #print all the options y = header_height for (option_key, option_text) in options: if hide_options is True: text = option_text else: text = '(' + option_key + ') ' + option_text libtcod.console_print_ex(self.inv_window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text) y += 1 #blit the contents of "self.inv_window" to the root console x, y, _ = SCREEN_RECT.top_left.coords libtcod.console_blit(self.inv_window, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, x, y, 1.0, 0.7) libtcod.console_flush() libtcod.console_clear(self.inv_window)
def main_menu(): while not libtcod.console_is_window_closed(): # show the game's title, and some credits! libtcod.console_set_default_foreground(0, libtcod.light_yellow) libtcod.console_print_ex(0, const.SCREEN_WIDTH / 2, const.SCREEN_HEIGHT / 2 - 4, libtcod.BKGND_NONE, libtcod.CENTER, 'LOOMINGS') libtcod.console_print_ex(0, const.SCREEN_WIDTH / 2, const.SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.CENTER, 'By nsv') # 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 main_menu(): while not libtcod.console_is_window_closed(): libtcod.console_disable_keyboard_repeat() libtcod.console_set_default_background(0, libtcod.black) libtcod.console_set_default_foreground(0, libtcod.black) libtcod.console_clear(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, 'BALL LABYRINTH') libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.CENTER, 'By Eric Williams') # Show options and wait for the player's choice. choice = menu('', ['Play a new game', 'Load saved game', 'Play custom level', 'Quit'], 24) if choice == 0: # New game. new_game() libtcod.console_set_keyboard_repeat(5, 5) play_game() elif choice == 1: # Load saved game. loaded = load_game() if loaded: libtcod.console_set_keyboard_repeat(5, 5) play_game() elif choice == 2: # Open the test arena level. custom = new_custom_game() if custom: libtcod.console_set_keyboard_repeat(5, 5) play_game() elif choice == 3: # Quit. break
def render_bar(panel, x, y, total_width, name, value, maximum, bar_color, back_color, fore_color=libtcod.white): bar_width = int(float(value) / maximum * total_width) # Render the background libtcod.console_set_default_background(panel, back_color) libtcod.console_rect(panel, x, y, total_width, 1, False, libtcod.BKGND_SCREEN) # Render the filled section of the bar 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) # Render centered text containing the actual value libtcod.console_set_default_foreground(panel, fore_color) label = consts.BAR_TEXT_TEMPLATE.format(name=name, value=value.__str__(), max=maximum.__str__()) bar_center = x + total_width // 2 libtcod.console_print_ex(panel, bar_center, y, libtcod.BKGND_NONE, libtcod.CENTER, label)
def menu(header, options, width): if len(options) > 26: raise ValueError('Cannot have 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 and key.lalt: 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_bar(panel, x, y, total_width, name, value, maximum, bar_color, back_color): """ Draws the health bar in the bottom panel. :param panel: :param x: :param y: :param total_width: :param name: :param value: :param maximum: :param bar_color: :param back_color: :return: """ # Stores the width of the current HP rectangle. bar_width = int(float(value) / maximum * total_width) # The colour of the back/maximum hp rectangle. libtcod.console_set_default_background(panel, back_color) # Creates the maximum HP rectangle. libtcod.console_rect(panel, x, y, total_width, 1, False, libtcod.BKGND_SCREEN) # The colour of the HP portion of the HP bar *(probably best to set it to red). libtcod.console_set_default_background(panel, bar_color) # If the player has any hp left. if bar_width > 0: # Draws the inner HP rectangle. libtcod.console_rect(panel, x, y, bar_width, 1, False, libtcod.BKGND_SCREEN) # Prints the HP text next to the bar. libtcod.console_set_default_foreground(panel, libtcod.white) libtcod.console_print_ex(panel, int(x + total_width / 2), y, libtcod.BKGND_NONE, libtcod.CENTER, "{0}: {1}/{2}".format(name, value, maximum))
def render_bar(self, x, y, total_width, name, value, maximum, bar_color, back_color, text_color=libtcod.white, show_values=False, title_inset=True): #render a bar (HP, experience, etc). first calculate the width of the bar bar_width = int(round(value / maximum * total_width)) # Make sure the value doesn't have a million repeating decimals value = round(value, 1) #render the background first libtcod.console_set_default_background(self.con, back_color) libtcod.console_rect(self.con, x, y, total_width, 1, False, libtcod.BKGND_SCREEN) #now render the bar on top libtcod.console_set_default_background(self.con, bar_color) if bar_width > 0: libtcod.console_rect(self.con, x, y, bar_width, 1, False, libtcod.BKGND_SCREEN) # This will cause the title to appear above the bar if not title_inset: y = y - 1 #finally, some centered text with the values libtcod.console_set_default_foreground(self.con, text_color) if show_values: libtcod.console_print_ex(self.con, (x + int(round(total_width / 2))), y, libtcod.BKGND_NONE, libtcod.CENTER, name + ': ' + str(value) + '/' + str(maximum)) else: libtcod.console_print_ex(self.con, (x + int(round(total_width / 2))), y, libtcod.BKGND_NONE, libtcod.CENTER, name) libtcod.console_set_default_background(self.con, self.backcolor) libtcod.console_set_default_background(self.con, self.frontcolor)
def main_menu(): img = libtcod.image_load('menu_background1.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 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, 'DRAGONSLAYER') libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.CENTER, 'A Dreaming Insomniac production') #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(header, options, width): if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options') # get geometry header_height = libtcod.console_get_height_rect(con, 0, 0, width, SCREEN_HEIGHT, header) height = len(options) + header_height # create an off screen 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 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) index = key.c - ord('a') if index >= 0 and index < len(options): return index return None
def build(self,con): libtcod.console_set_default_background(con,self.bcg_color) libtcod.console_set_default_foreground(con,self.color) libtcod.console_print_ex(con,0,0,libtcod.BKGND_SET,libtcod.LEFT,self.text) self.width=len(self.text) self.height=1
def menu(header, options, width): if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options') # Calc the header height after auto-wrap, one line per option header_height = libtcod.console_get_height_rect(con, 0, 0, width, opt.SCREEN_HEIGHT, header) if header == '': header_height = 0 height = len(options) + header_height # Create new offscreen window window = libtcod.console_new(width, height) # Print header with auto-wrap libtcod.console_set_default_foreground(window, libtcod.Color(230,230,230)) 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: # Print options in format a) Option 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 = opt.SCREEN_WIDTH/2 - width/2 y = opt.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 and key.lalt: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) # If an item was chosen, return it index = key.c - ord('a') if index >= 0 and index < len(options): return index return None
def build(self,con): #build the menu itself libtcod.console_print_ex(con,self.width/2,0,libtcod.BKGND_NONE,libtcod.CENTER,self.name) i=1 temp=libtcod.console_new(self.width,self.height) for elem in self.content: #print elem #print "built" dh=elem.build(temp) dh=elem.height #updated from dh libtcod.console_blit(temp,0,0,elem.width,dh,con,1,i) elem.set_pos(1,i) # print 'elem placed at', elem.pos libtcod.console_clear(temp) libtcod.console_put_char_ex(con,0,i,chr(26),libtcod.white,libtcod.black) # libtcod.console_set_char_background(con, 0, i, libtcod.blue) i+=dh #---------------7Drl---------------------------------- if self.height<i+1: #Bricolage, to change later on self.height=i+1
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 autowrap 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 another offscreen console for the menu's window window = libtcod.console_new(width, height) #print the header, with autowrap 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') #start the list of inventory items with ordinal letter a for option_text in options: text = '(' + chr(letter_index) + ') ' + option_text #converts ordinal to a string for selection libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text) y += 1 letter_index += 1 #blit the contents of the inventory window to the root console in the middle of the screen 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) #last two values transparency% #present to the root console to the player and wait for key-press libtcod.console_flush() key = libtcod.console_wait_for_keypress(True)
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)) #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
def main_menu(new_game, play_game, load_game): """ Prompt the player to start a new game, continue playing the last game, or exit. """ 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) libtcod.console_set_default_foreground(0, libtcod.light_yellow) libtcod.console_print_ex( 0, config.SCREEN_WIDTH/2, config.SCREEN_HEIGHT/2-4, libtcod.BKGND_NONE, libtcod.CENTER, 'TOMBS OF THE ANCIENT KINGS') libtcod.console_print_ex( 0, config.SCREEN_WIDTH/2, config.SCREEN_HEIGHT-2, libtcod.BKGND_NONE, libtcod.CENTER, 'By Jotaf') (char, choice) = menu('', ['Play a new game', 'Continue last game', 'Quit'], 24) if choice == 0: play_game(new_game()) if choice == 1: try: player = load_game() except: msgbox('\n No saved game to load.\n', 24) continue play_game(player) elif choice == 2: break
def do_main_menu(key, mouse): title_panel_h = 28 title_panel = tcod.console_new(g.screen_width, title_panel_h) tcod.console_set_alignment(title_panel, tcod.LEFT) tcod.console_set_default_foreground(title_panel, tcod.blue) for x in range(0, len(g.TITLE_GRAPHIC_TOP)): tcod.console_print_ex(title_panel, 1, x + 1, tcod.BKGND_SET, tcod.LEFT, g.TITLE_GRAPHIC_TOP[x][0]) for x in range(0, len(g.TITLE_GRAPHIC_BOTTOM)): tcod.console_print_ex(title_panel, 1, x + 4 + len(g.TITLE_GRAPHIC_TOP), tcod.BKGND_SET, tcod.LEFT, g.TITLE_GRAPHIC_BOTTOM[x][0]) selection_panel = tcod.console_new(g.screen_width, g.screen_height - title_panel_h) tcod.console_set_alignment(selection_panel, tcod.LEFT) tcod.console_set_default_foreground(selection_panel, tcod.sea) title_colors = [ tcod.azure, tcod.cyan, tcod.dark_purple, tcod.dark_violet, tcod.fuchsia, tcod.light_gray, tcod.purple, tcod.sea, tcod.turquoise, ] g.lexicon_counter = 0 questions_options = { '': [ ('start', 'Start'), ('exit', 'Exit game') ] } waiting_for_response = True while waiting_for_response: for y in range(1, 1 + len(g.TITLE_GRAPHIC_TOP)): color_index = random.randint(0, len(title_colors) - 1) for x in range(0, g.screen_width): tcod.console_set_char_foreground(title_panel, x, y, title_colors[color_index]) tcod.console_blit(title_panel, 0, 0, g.screen_width, title_panel_h, 0, 0, 0) tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, key, mouse) selection = handle_questions(selection_panel, key, mouse, questions_options, 24) if len(selection) > 0: if selection[0] == 'start': g.context = Context.TEAM_CREATION waiting_for_response = False elif selection[0] == 'exit': g.context = Context.EXIT waiting_for_response = False tcod.console_clear(title_panel) tcod.console_blit(title_panel, 0, 0, g.screen_width, title_panel_h, 0, 0, 0) tcod.console_clear(selection_panel) tcod.console_blit(selection_panel, 0, 0, g.screen_width, title_panel_h, 0, 0, 0) tcod.console_flush()
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(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) 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)
def draw_main_menu(con, has_file=False): tcod.console_set_default_foreground(con, COL_A) img = tcod.image_load('small.png') tcod.image_set_key_color(img, tcod.red) tcod.image_blit(img, 0, 45, 30, tcod.BKGND_LIGHTEN, .5, .25, 0) xx=-20 yy=15 can_cont = "" can_del = '' if has_file: can_cont = '-- (c)ontinue' can_del = '-- (D)elete' options=( """ GAME TITLE """+chr(tcod.CHAR_BLOCK2)+chr(tcod.CHAR_BLOCK1)+chr(tcod.CHAR_BLOCK1)+""" | | \t-- (n)ew game | \t--\t%s | | | \t%s | \t-- (esc)cape """ % (can_cont, can_del) ) tcod.console_print_ex(con, game.GAME_WIDTH/4+xx, game.GAME_HEIGHT/3+yy, tcod.BKGND_LIGHTEN, tcod.LEFT,options) tcod.console_print(con, 2, game.GAME_HEIGHT-2, 'oyyooyoyoyoyyooyoyoy') tcod.console_flush() tcod.console_clear(con)
def main_menu(): img = libtcod.image_load('menu_background1.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, 'TOMBS OF THE ANCIENT KINGS') libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.CENTER, 'By COOSK-KUNKUN') # 显示选项并等待玩家的选择 choice = menu('', ['Play a new game', 'Continue last game', 'Quit'], 24) if choice == 0: #new game # new_game() # play_game() race_menu() 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_bar3(panel, x, y, total_width, name, value, maximum, real_maximum, bar_color, back_color, lost_color): max_bar_width = int(float(maximum) / real_maximum * total_width) if maximum > 0: bar_width = int(float(value) / maximum * max_bar_width) else: bar_width = 0 libtcod.console_set_default_background(panel, lost_color) libtcod.console_rect(panel, x, y, total_width, 1, False, libtcod.BKGND_SCREEN) libtcod.console_set_default_background(panel, back_color) if max_bar_width > 0: libtcod.console_rect(panel, x, y, max_bar_width, 1, False, libtcod.BKGND_SCREEN) 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) libtcod.console_set_default_foreground(panel, libtcod.white) libtcod.console_print_ex(panel, int(x + total_width / 2), y, libtcod.BKGND_NONE, libtcod.CENTER, '{0}: {1}/{2}'.format(name, value, maximum))
def main_menu(): #Set up the main menu, which is presented to the player when they first load the game img = libtcod.image_load('images/menu_background1.png') while not libtcod.console_is_window_closed(): #Show the image at twice its usual resolution of the console libtcod.image_blit_2x(img, 0, SCREEN_WIDTH / 6, SCREEN_HEIGHT / 6) #Show the games 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, 'DUNGEONCRAWLER') libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.CENTER, 'By Jeremy Cerise') #Show menu options and wait for the players choice choice = menu('', ['Play a new game', 'Continue last game', 'Quit'], 24) if choice == 0: #Start a new game #Clear the base conosle, so the menu image and options don't show up under the rest of the UI libtcod.console_set_default_background(0, libtcod.brass) libtcod.console_clear(0) new_game() play_game() elif choice == 1: try: libtcod.console_set_default_background(0, libtcod.brass) libtcod.console_clear(0) load_game() except: msgbox('\n No saved game to load!\n', 24) elif choice == 2: #Exit the program break;
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) # prepare to render the GUI console libtcod.console_set_default_background(panel, libtcod.black) libtcod.console_clear(panel) # 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) # 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 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 GUI to screen libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
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 update(self): pos = self.calc_pos() libtcod.console_print_ex(self.parent().console, pos[0], pos[1], libtcod.BKGND_NONE, libtcod.LEFT, str(value_pointer)) self.width = len(str(value_pointer))
def main_menu(self): """THE main menu, no other.""" LIMIT_FPS = 20 libtcod.sys_set_fps(LIMIT_FPS) img = libtcod.image_load('main/lazor.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 credits libtcod.console_set_default_foreground(0, color_menu_text) libtcod.console_print_ex(0, SCREEN_WIDTH/2, 1, libtcod.BKGND_NONE, libtcod.CENTER, 'Laz0r Dodging Game') libtcod.console_print_ex(0, SCREEN_WIDTH/2, 2, libtcod.BKGND_NONE, libtcod.CENTER, 'by magikmw') #show options and wait for the player's choice choice = menu('Choose an option:\n', ['Real-Time', 'Turn-Based', 'Highscores', 'Help', 'Quit.'], 18, -10) if choice == 0: #new game self.new_game('RT') if choice == 1: self.new_game('TB') if choice == 2: #TODO the highscore function call here pass if choice == 3: #TODO help screen funcion call here pass if choice == 4: #quit break
def refreshMessage(self): libtcod.console_set_default_foreground(self.console, libtcod.white) libtcod.console_print_ex(self.console, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, ('{0: <' + str(self.width) + '}').format(self.message)) if self.active: libtcod.console_put_char(self.console, 1+len(self.message), 0, '_', libtcod.BKGND_NONE) else: libtcod.console_put_char(self.console, 1+len(self.message), 0, ' ', libtcod.BKGND_NONE)
def render_all(): # Go through all Tiles, and set their character and color. for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): # Draw it. libtcod.console_put_char_ex(con, x, y, map[x][y].char, map[x][y].color, libtcod.black) # 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) # Prepare to render the GUI panel. libtcod.console_set_default_background(panel, libtcod.black) libtcod.console_clear(panel) # Show the player's stats. libtcod.console_set_default_foreground(panel, libtcod.red) libtcod.console_print_ex(panel, 1, 1, libtcod.BKGND_NONE, libtcod.LEFT, 'Lives: ' + str(player.lives) + '/' + str(player.max_lives)) libtcod.console_set_default_foreground(panel, libtcod.white) libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT, 'Level ' + str(level_number)) # Blit the contents of "panel" to the root console. libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
def display(self): libtcod.console_set_default_foreground(self.console, libtcod.white) hptext = "Dead." if self.player.properties['combat'] is not None: hptext = 'HP: ' + str(self.player.properties['combat'].hp) + '/' + str(self.player.properties['combat'].max_hp) libtcod.console_print_ex(self.console, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, ('{0: <' + str(self.width) + '}').format(hptext)) libtcod.console_blit(self.console, 0, 0, self.width, self.height, 0, self.x, self.y)
def renderBar(self, panel, x, y, total_width, name, value, maximum, bar_color, back_color): """ Helper function to render interface bars """ # 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_bar(x, y, total_width, name, value, maximum, bar_color, back_color): """ Generic status bar renderer. Can be used for health bar, mana bar, experience bar, dungeon level, etc. """ global panel # determine the width of the bar to render. bar_width = int(float(value) / maximum * total_width) # render the background bar. libtcod.console_set_default_background(panel, back_color) libtcod.console_rect(panel, x, y, total_width, 1, False, libtcod.BKGND_SCREEN) # render the foreground bar. 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) # render some centered text with the values msg = '{}: {}/{}'.format(name, value, maximum) libtcod.console_set_default_foreground(panel, libtcod.white) libtcod.console_print_ex(panel, x + total_width / 2, y, libtcod.BKGND_NONE, libtcod.CENTER, msg)
def menu(header, options, width): if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.') #calculate the total height for the header 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 represent 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 option 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) #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 main_menu(): img = libtcod.image_load('menu_background1.png') while not libtcod.console_is_window_closed(): 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, 'Castle of Orkish Warlock') libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, libtcod.BKGND_NONE, libtcod.CENTER, 'By Mrzyglosz') libtcod.image_blit_2x(img, 0, 0, 0) choice = menu('', ['Play a new game', 'Continue last game', 'Quit'], 24) if choice == 0: new_game() play_game() if choice == 1: try: load_game() except: msgbox('\n No saved game to load.\n', 24) continue play_game() elif choice == 2: break