def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color): #render a bar bar_width = int(float(value) / maximum * total_width) #background first libtcod.console_set_background_color(panel, back_color) libtcod.console_rect(panel, x, y, total_width, 1, False) #put bar at top libtcod.console_set_background_color(panel, bar_color) if bar_width > 0: libtcod.console_rect(panel, x, y, bar_width, 1, False) #some text and values libtcod.console_set_foreground_color(panel, libtcod.white) libtcod.console_print_center(panel, x + total_width / 2, y, libtcod.BKGND_NONE, name + ': ' + str(value) + '/' + str(maximum))
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_background_color(panel, back_color) libtcod.console_rect(panel, x, y, total_width, 1, False) #now render the bar on top libtcod.console_set_background_color(panel, bar_color) if bar_width > 0: libtcod.console_rect(panel, x, y, bar_width, 1, False) #finally, some centered text with the values libtcod.console_set_foreground_color(panel, libtcod.white) libtcod.console_print_center(panel, x + total_width / 2, y, libtcod.BKGND_NONE, name + ': ' + str(value) + '/' + str(maximum))
def main_menu(): while not libtcod.console_is_window_closed(): #show game title libtcod.console_print_center(0, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-4, libtcod.BKGND_NONE, 'Dick Slayer') #show options choice = menu('', ['Play a new game', 'Continue last game', 'Quit'], 24) 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 main_menu(): while not libtcod.console_is_window_closed(): #show game title libtcod.console_print_center(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 4, libtcod.BKGND_NONE, 'Dick Slayer') #show options choice = menu('', ['Play a new game', 'Continue last game', 'Quit'], 24) 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 render_info(x, y, total_width, text): libtcod.console_print_center(panel, x + total_width / 2, y, libtcod.BKGND_NONE, str(text))