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 main_menu(): img = libtcod.image_load(b'img/backgrounds/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 libtcod.console_set_default_foreground(0, libtcod.light_yellow) libtcod.console_set_alignment(0, libtcod.CENTER) libtcod.console_print(0, int(round(SCREEN_WIDTH / 2)), int(round(SCREEN_HEIGHT / 2 - 4)), 'THE LEGEND OF THARSA') libtcod.console_print(0, int(round(SCREEN_WIDTH / 2)), int(round(SCREEN_HEIGHT - 2)), 'By Athemis') # Show the 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() 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 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 storyScreen(console): libtcod.console_set_default_background(console, STORY_BACKGROUND_COLOUR1) libtcod.console_clear(console) done = False counter = 0 blinkOn = True blinkSpeed = 10 while not done and not libtcod.console_is_window_closed(): key = libtcod.console_check_for_keypress(True) if not key.vk == libtcod.KEY_NONE: done = True #print the story message libtcod.console_set_default_foreground(console, STORY_FOREGROUND_COLOUR1) libtcod.console_print_rect(console, 1, 3, SCREEN_WIDTH, SCREEN_HEIGHT, STORY_TEXT1) if(blinkOn): libtcod.console_set_default_foreground(console, SPLASH_FOREGROUND_COLOUR3) libtcod.console_print_rect(console, 16, 22, SCREEN_WIDTH, SCREEN_HEIGHT, "press any key") # blit the panel to the screen libtcod.console_blit(console, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-(2*1), 0, 0, 1) libtcod.console_flush() counter += 1 if counter >= blinkSpeed: counter = 0 blinkOn = not blinkOn libtcod.console_clear(console) libtcod.console_clear(console)
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(): 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 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 draw(self): #only show if it's visible to the player; or it's set to "always visible" and on an explored tile if (libtcod.map_is_in_fov(fov_map, self.x, self.y) or (self.always_visible and map[self.x][self.y].explored)): #set the color and then draw the character that represents this object at its position libtcod.console_set_default_foreground(con, self.color) libtcod.console_put_char(con, self.x, self.y, self.char, 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 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_red) libtcod.console_print_ex(0, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-8, libtcod.BKGND_NONE, libtcod.CENTER, 'R- U- N-') libtcod.console_print_ex(0, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-6, libtcod.BKGND_NONE, libtcod.CENTER, 'Something cool') libtcod.console_print_ex(0, SCREEN_WIDTH/2, SCREEN_HEIGHT-2-2, libtcod.BKGND_NONE, libtcod.CENTER, '- w5748 -') #show options and wait for the player's choice choice = menu('', ['New Game', 'Load File', '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 story_slide(): img = libtcod.image_load('menu_background2.png') if dungeon_level == 0: level_subtitle = 'LEVEL 0' elif dungeon_level == 1: level_subtitle = 'LEVEL 1' elif dungeon_level == 2: level_subtitle = 'BEFORE THE STARDUST FADES' elif dungeon_level == 3: level_subtitle = 'WISH UPON THE DIAMOND DUST' 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-6, libtcod.BKGND_NONE, libtcod.CENTER, 'CHAPTER '+str(dungeon_level)) libtcod.console_print_ex(0, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-4, libtcod.BKGND_NONE, libtcod.CENTER, level_subtitle) libtcod.console_print_ex(0, SCREEN_WIDTH/2, SCREEN_HEIGHT-2-2, libtcod.BKGND_NONE, libtcod.CENTER, '- w5748 -') #show options and wait for the player's choice choice = menu('', ['PROCEED'], 11) if choice == 0: #PROCEED PATH, THINK ABOUT A save_game() ROUTE break elif choice == 1: break
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height, bar_width, panel_height, panel_y, mouse, colors, game_state): # Draw all the tiles in the game map if fov_recompute: for y in range(game_map.height): for x in range(game_map.width): visible = libtcod.map_is_in_fov(fov_map, x, y) wall = game_map.tiles[x][y].block_sight if visible: if wall: libtcod.console_set_char_background(con, x, y, colors.get('light_wall'), libtcod.BKGND_SET) else: libtcod.console_set_char_background(con, x, y, colors.get('light_ground'), libtcod.BKGND_SET) game_map.tiles[x][y].explored = True elif game_map.tiles[x][y].explored: if wall: libtcod.console_set_char_background(con, x, y, colors.get('dark_wall'), libtcod.BKGND_SET) else: libtcod.console_set_char_background(con, x, y, colors.get('dark_ground'), libtcod.BKGND_SET) 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, game_map) libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0) libtcod.console_set_default_background(panel, libtcod.black) libtcod.console_clear(panel) #Print the game messages, one line at a time y = 1 for message in message_log.messages: libtcod.console_set_default_foreground(panel, message.color) libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE, libtcod.LEFT, message.text) y += 1 render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp, player.fighter.max_hp, libtcod.light_red, libtcod.darker_red) libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT, 'Dungeon level: {0}'.format(game_map.dungeon_level)) libtcod.console_set_default_foreground(panel, libtcod.light_gray) libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse(mouse, entities, fov_map)) libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y) if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY): if game_state == GameStates.SHOW_INVENTORY: inventory_title = 'Press the key next to the item to use it, or Esc to cancel.\n' else: inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n' inventory_menu(con, inventory_title, player.inventory, 50, screen_width, screen_height) elif game_state == GameStates.LEVEL_UP: level_up_menu(con, 'Level up! Choose a stat to raise:', player, 40, screen_width, screen_height) elif game_state == GameStates.CHARACTER_SCREEN: character_screen(player, 30, 10, 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 = 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 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 RenderEverything(): player = None for ent in ActiveEntityList: if 'ControlledByPlayer' and 'CanSee' in ent.flags: player = ent break #player = TestDummy for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): terraintile = Map[x][y] if player != None: canseetile = player.Vision.CanSee(x,y) if canseetile: libtcod.console_set_char_background(MainConsole,x,y,terraintile.bgcolour,libtcod.BKGND_SET) libtcod.console_set_default_foreground(MainConsole,terraintile.fgcolour) libtcod.console_put_char(MainConsole, x, y, terraintile.char, libtcod.BKGND_NONE) else: libtcod.console_set_char_background(MainConsole,x,y,terraintile.bgcolour*UNSEEN_TERRAIN_DARKNESS,libtcod.BKGND_SET) libtcod.console_set_default_foreground(MainConsole,terraintile.fgcolour*UNSEEN_TERRAIN_DARKNESS) libtcod.console_put_char(MainConsole, x, y, terraintile.char, libtcod.BKGND_NONE) for ent in ActiveEntityList: ent.Draw() DrawAllPaths(MainConsole) RenderGui() libtcod.console_blit(MainConsole, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0) libtcod.console_blit(GUIBottomConsole, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, GUI_BOTTOM_Y)
def main_menu(): img = libtcod.image_load('rltutBackdrop.png') while not libtcod.console_is_window_closed(): #libtcod.image_blit(img, 0, 0, 0) #show the background image at twice the regular console resolution libtcod.image_blit_2x(img, 0, 0, 0) #show 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, MAIN_TITLE) libtcod.console_print_ex(0, SCREEN_WIDTH/2, SCREEN_HEIGHT-2, libtcod.BKGND_NONE, libtcod.CENTER, 'by Austin McGee') #print controls libtcod.console_print_ex(0, 1, 1, libtcod.BKGND_NONE, libtcod.LEFT, CONTROLS_TEXT) #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 draw(self): #only show if visible to the player if (libtcod.map_is_in_fov(fov_map, self.x, self.y) or (self.always_visible and map[self.x][self.y].explored) or self.name=='room number'): #set the color and then draw the character that represents this object at its position libtcod.console_set_default_foreground(con, self.color) libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_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 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(): 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 render_all(): global fov_map, color_dark_wall, color_light_wall, color_dark_ground, color_light_ground global fov_recompute, hunger, msg_index x_range = range(camera.x, camera.x + CAMERA_WIDTH) y_range = range(camera.y, camera.y + CAMERA_HEIGHT) if fov_recompute: # recompute FOV if need be (player movement or whatever) fov_recompute = False if 'fog' in map[player.x][player.y].mod_set: libtcod.map_compute_fov(fov_map, player.x, player.y, FOG_TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO) else: libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO) for y in y_range: for x in x_range: # uncomment this to return to exploration mode #visible = libtcod.map_is_in_fov(fov_map, x, y) visible = True wall = map[x][y].block_sight mods = map[x][y].mod_set if not visible: if map[x][y].explored: if wall: libtcod.console_set_char_background(con, x-camera.x, y-camera.y, color_dark_wall, libtcod.BKGND_SET) else: libtcod.console_set_char_background(con, x-camera.x, y-camera.y, color_dark_ground, libtcod.BKGND_SET) else: libtcod.console_set_char_background(con, x-camera.x, y-camera.y, libtcod.black, libtcod.BKGND_SET) else: if wall: #libtcod.console_set_default_foreground(con, libtcod.white) libtcod.console_set_char_background(con, x-camera.x, y-camera.y, color_light_wall, libtcod.BKGND_SET) else: # THIS ELIF IS FOR A DEBUG COLOR if map[x][y].h == 1: libtcod.console_set_char_background(con, x-camera.x, y-camera.y, color_blood, libtcod.BKGND_SET) else: libtcod.console_set_char_background(con, x-camera.x, y-camera.y, color_light_ground, libtcod.BKGND_SET) map[x][y].explored = True for obj in objects: # prevents drawing over the player if obj != player and (obj.x in x_range) and (obj.y in y_range): libtcod.console_set_default_foreground(con, obj.color) libtcod.console_put_char(con, obj.x-camera.x, obj.y-camera.y, obj.char, libtcod.BKGND_NONE) libtcod.console_set_default_foreground(con, player.color) libtcod.console_put_char(con, player.x-camera.x, player.y-camera.y, player.char, libtcod.BKGND_NONE) 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 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 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 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(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 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 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 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;
playery = SCREEN_HEIGHT / 2 libtcod.console_set_custom_font( 'terminal8x8_gs_ro.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW) libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'mines', False) def handle_keys(key): global playerx, playery if key.vk == libtcod.KEY_UP: playery -= 1 if key.vk == libtcod.KEY_LEFT: playerx -= 1 if key.vk == libtcod.KEY_DOWN: playery += 1 if key.vk == libtcod.KEY_RIGHT: playerx += 1 if key.vk == libtcod.KEY_ESCAPE: return True while not libtcod.console_is_window_closed(): exit = handle_keys(libtcod.console_wait_for_keypress(True)) if exit: break libtcod.console_clear(0) libtcod.console_set_default_foreground(0, libtcod.white) libtcod.console_put_char(0, playerx, playery, '@', libtcod.BKGND_NONE) libtcod.console_flush()
def test_console_defaults(console, fg, bg): libtcodpy.console_set_default_foreground(console, fg) libtcodpy.console_set_default_background(console, bg) libtcodpy.console_clear(console) assert_char(console, 0, 0, None, fg, bg)
def draw_entity(con, entity): libtcod.console_set_default_foreground(con, entity.color) libtcod.console_put_char(con, entity.x, entity.y, entity.char, libtcod.BKGND_NONE)
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height, bar_width, panel_height, panel_y, mouse, colors, game_state): if fov_recompute: # Draw all the tiles in the game map for y in range(game_map.height): for x in range(game_map.width): visible = libtcod.map_is_in_fov(fov_map, x, y) wall = game_map.tiles[x][y].block_sight if visible: if wall: libtcod.console_set_char_background( con, x, y, colors.get('light_wall'), libtcod.BKGND_SET) else: libtcod.console_set_char_background( con, x, y, colors.get('light_ground'), libtcod.BKGND_SET) game_map.tiles[x][y].explored = True elif game_map.tiles[x][y].explored: if wall: libtcod.console_set_char_background( con, x, y, colors.get('dark_wall'), libtcod.BKGND_SET) else: libtcod.console_set_char_background( con, x, y, colors.get('dark_ground'), libtcod.BKGND_SET) entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value) # Draw all entities in the list for entity in entities_in_render_order: draw_entity(con, entity, fov_map) libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0) if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY): if game_state == GameStates.SHOW_INVENTORY: inventory_title = 'Press the key next to an item to use it, or Esc to cancel.\n' else: inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n' inventory_menu(con, inventory_title, player.inventory, 50, screen_width, screen_height) libtcod.console_set_default_background(panel, libtcod.black) libtcod.console_clear(panel) # Print the game messages, one line at a time y = 1 for message in message_log.messages: libtcod.console_set_default_foreground(panel, message.color) libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE, libtcod.LEFT, message.text) y += 1 render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp, player.fighter.max_hp, libtcod.light_red, libtcod.darker_red) libtcod.console_set_default_foreground(panel, libtcod.light_gray) libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse(mouse, entities, fov_map)) libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y)
def draw_entity(con, entity, fov_map): if libtcod.map_is_in_fov(fov_map, entity.x, entity.y): libtcod.console_set_default_foreground(con, entity.color) libtcod.console_put_char(con, entity.x, entity.y, entity.char, libtcod.BKGND_NONE)
def render(self, panel): if 'position' in self.components: pos = self.components['position'] libtcod.console_set_default_foreground(panel, self.color) libtcod.console_put_char(panel, pos.x, pos.y, self.char, libtcod.BKGND_NONE)
def draw(self): libtcod.console_set_default_foreground(0, self.color) libtcod.console_put_char(0, self.x, self.y, self.char, libtcod.BKGND_NONE)
def render_hud(w, h, pc, turn, level): def get_color(stat): col = COL['white'] if stat[:3] == 'Lo:': col = COL['blue'] if stat[:3] == 'Hi:': col = COL['red'] return col class Stat(): def __init__(self, x, y, text, color): self.x = x self.y = y self.text = text self.color = color # Setup # get = pc.stats.get con = libtcod.console_new(w, h) strngStats = "__{name}__|Lo: {hp}|Hi: {mp}|Speed: {spd}/{asp}/{msp}|Hit: {hit}({hitb})|Pow: {dmg}({dmgb})|DV: {dfn}({dfnb})|AV: {arm}({armb})|FIR: {fir}|BIO: {bio}|DLvl: {dlv}|T: {t}".format( name=pc.name, hp=get('hp'), mp=get('mp'), spd=get('spd'), asp=get('asp'), msp=get('msp'), dlv=level, t=turn, hit=get('atk'), hitb=pc.stats.atk, dmg=get('dmg'), dmgb=pc.stats.dmg, dfn=get('dfn'), dfnb=pc.stats.dfn, arm=get('arm'), armb=pc.stats.arm, fir=get('resfire'), bio=get('resbio'), ) stats = strngStats.split('|') statLines = [[]] tot = 0 y = 0 for stat in stats: lenStat = len(stat) + 1 col = get_color(stat) new = Stat(tot, y, stat, col) tot += lenStat if tot >= rog.window_w(): tot = lenStat y += 1 new.x = 0 new.y = y statLines.append([new]) continue statLines[-1].append(new) # Print # for line in statLines: for stat in line: libtcod.console_set_default_foreground(con, stat.color) libtcod.console_print(con, stat.x, stat.y, stat.text) # return con
def render_all(window, ui_panel, entities, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height, ui_panel_width, ui_panel_height, ui_panel_y, mouse, colors, game_state): results = [] # draw game map if fov_recompute or libtcod.map_is_in_fov(fov_map, mouse.cx, mouse.cy): 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( window, x, y, colors.get("light_wall"), libtcod.BKGND_SET) libtcod.console_set_char_foreground( window, x, y, libtcod.white) libtcod.console_set_char(window, x, y, '#') else: libtcod.console_set_char_background( window, x, y, colors.get("light_ground"), libtcod.BKGND_SET) libtcod.console_set_char_foreground( window, x, y, libtcod.white) libtcod.console_set_char(window, x, y, '.') if mouse.cx == x and mouse.cy == y: libtcod.console_set_char_background( window, x, y, libtcod.white, libtcod.BKGND_ALPHA(0.5)) game_map.tiles[x][y].explored = True elif game_map.tiles[x][y].explored: if wall: libtcod.console_set_char_background( window, x, y, colors.get("dark_wall"), libtcod.BKGND_SET) libtcod.console_set_char_foreground( window, x, y, libtcod.light_gray) libtcod.console_set_char(window, x, y, '#') else: libtcod.console_set_char_background( window, x, y, colors.get("dark_ground"), libtcod.BKGND_SET) libtcod.console_set_char_foreground( window, x, y, libtcod.lighter_gray) libtcod.console_set_char(window, x, y, '.') # Draw all entities in rendering order e.g. corpses should be below player. entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value) for entity in entities_in_render_order: draw_entity(window, entity, fov_map, game_map) # Blit offscreen window to main window libtcod.console_blit(window, 0, 0, screen_width, screen_height, 0, 0, 0) # Prepare offscreen UI panel for drawing player = entities[0] # first entity is always player libtcod.console_set_default_background(ui_panel, libtcod.black) libtcod.console_clear(ui_panel) # Draw event message log to offscreen UI panel for y, message in enumerate(message_log.messages): # Draw message log libtcod.console_set_default_foreground(ui_panel, message.color) libtcod.console_print_ex(ui_panel, message_log.x, y + 1, libtcod.BKGND_NONE, libtcod.LEFT, message.text) # Draw player info bar to offscreen UI panel render_bar(ui_panel, 1, 1, ui_panel_width, "HP", player.fighter.hp, player.fighter.max_hp, libtcod.light_red, libtcod.darker_red) libtcod.console_print_ex( ui_panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT, "Dungeon level: {0}".format(game_map.dungeon_level)) # Draw entity name at mouse position to offscreen UI panel libtcod.console_set_default_foreground(ui_panel, libtcod.light_gray) libtcod.console_print_ex(ui_panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse(mouse, entities, fov_map)) # Blit UI panel to main window libtcod.console_blit(ui_panel, 0, 0, screen_width, ui_panel_height, 0, 0, ui_panel_y) if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY): if game_state == GameStates.SHOW_INVENTORY: inventory_header = "Press the key next to item to use it. Press Esc to cancel.\n" else: inventory_header = "Press the key next to item to drop it. Press Esc to cancel.\n" results.extend( inventory_menu(window, inventory_header, player, 50, screen_width, screen_height, mouse)) elif game_state == GameStates.LEVEL_UP: results.extend( level_up_menu(window, "Level up! Choose a stat to raise:", player, 40, screen_width, screen_height, mouse)) elif game_state == GameStates.CHARACTER_SCREEN: character_screen_menu(player, 30, 10, screen_width, screen_height) return results
def render_all(): global fov_map, color_dark_wall, color_light_wall global color_dark_ground, color_light_ground global fov_recompute move_camera(player.x, player.y) 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, const.TORCH_RADIUS, const.FOV_LIGHT_WALLS, const.FOV_ALGO) libtcod.console_clear(const.con) # go through all tiles, and set their background color according to the FOV for y in range(const.CAMERA_HEIGHT): for x in range(const.CAMERA_WIDTH): (map_x, map_y) = (camera_x + x, camera_y + y) visible = libtcod.map_is_in_fov(fov_map, map_x, map_y) wall = map[map_x][map_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[map_x][map_y].explored: if wall: libtcod.console_set_char_background( const.con, x, y, const.color_dark_wall, libtcod.BKGND_SET) else: libtcod.console_set_char_background( const.con, x, y, const.color_dark_ground, libtcod.BKGND_SET) else: # it's visible if wall: libtcod.console_set_char_background( const.con, x, y, const.color_light_wall, libtcod.BKGND_SET) else: libtcod.console_set_char_background( const.con, x, y, const.color_light_ground, libtcod.BKGND_SET) # since it's visible, explore it map[map_x][map_y].explored = True for object in objects: if object != player: object.draw() player.draw() look_cursor.draw() libtcod.console_blit(const.con, 0, 0, const.SCREEN_WIDTH, const.SCREEN_HEIGHT, 0, 0, 0) # prepare to render the GUI panel libtcod.console_set_default_background(const.panel, libtcod.black) libtcod.console_clear(const.panel) # print the game messages, one line at a time y = 1 for (line, color) in game_msgs: libtcod.console_set_default_foreground(const.panel, color) libtcod.console_print_ex(const.panel, const.MSG_X, y, libtcod.BKGND_NONE, libtcod.LEFT, line) y += 1 if looking == True: # display names of objects under the mouse libtcod.console_set_default_foreground(const.panel, libtcod.light_gray) libtcod.console_print_ex(const.panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, looking_oracle()) # show the player's stats render_bar(1, 1, const.BAR_WIDTH, 'HP', 28, 50, libtcod.light_red, libtcod.darker_red) # blit the contents of "panel" to the root console libtcod.console_blit(const.panel, 0, 0, const.SCREEN_WIDTH, const.PANEL_HEIGHT, 0, 0, const.PANEL_Y)
def draw(self): #if the object is in FOV if libtcod.map_is_in_fov(fov_map, self.x, self.y): #set the color and draw the character libtcod.console_set_default_foreground(con, self.color) libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_NONE)
def draw(self): #set the color and then draw the character that represents this object at its position libtcod.console_set_default_foreground(con, self.color) libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_NONE)
def draw(self, fov_map, tile_map, con): if (libtcod.map_is_in_fov(fov_map, self.x, self.y) or (self.always_visible and tile_map[self.x][self.y].explored)): libtcod.console_set_default_foreground(con, self.color) libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_NONE)
def clear(self): #erase the character that represents this object libtcod.console_set_default_foreground(con, self.color) libtcod.console_put_char(con, self.x, self.y, ' ', libtcod.BKGND_NONE )
def refresh(self): rl.console_clear(0) # Fill the window the background color. rl.image_blit_2x(self.image, 0, 0, 0) # Display the title screen image. rl.console_set_default_foreground(0, rl.white) # Sets the foreground (text) color to white. rl.console_set_default_background(0, rl.black) # Sets the background color to black. self.box.draw() # Draws the menu box on the screen.
def draw_entity(self, entity): tcod.console_set_default_foreground(self.con, entity.color) tcod.console_put_char(self.con, entity.x, entity.y, entity.icon, tcod.BKGND_NONE)
def render_all(): global fov_map, color_dark_wall, color_light_wall global color_dark_ground, color_light_ground global fov_recompute global con global dungeon_level if fov_recompute: #Recompute the Field of view (Player movement, door opened, etc) fov_recompute = False libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO) #Draw the map, set each tiles color according to the Field of View 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: #This tile is not visible, check if its been explored if map[x][y].explored: #This tile has not been explored yet, so do not show it 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: #This tile is 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) #Mark the tile as explored, so it will continue to show on the map map[x][y].explored = True #Draw all objects in the list for object in objects: if object != player: object.draw(fov_map, con) #Draw the player last so it appears on top of everything else player.draw(fov_map, con) #Blit the map console onto the screen libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 1, 1) #Prepare to render the GUI panel libtcod.console_set_default_background(panel, libtcod.black) libtcod.console_clear(panel) libtcod.console_print_ex(panel, 1, 1, libtcod.BKGND_NONE, libtcod.LEFT, 'Dungeon level ' + str(dungeon_level)) #Display the 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()) #Print out messages in the game messages log 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 #Blit the new console for the GUI onto the screen libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH - 2, PANEL_HEIGHT - 1, 0, 1, PANEL_Y) #Blit the info panel onto the screen render_info_panel(info)
def draw(self): """ draw object at its position with its color. """ tcod.console_set_default_foreground(con, self._color) tcod.console_put_char(con, self._x, self._y, self._char, tcod.BKGND_NONE)
def menu(header, options, width=30, talk=False): #The player is presented with some options and makes a choice based on graphics choice = 0 new_choice = 0 #Calculate total height for header (after auto-wrap) and one line per option header_height = libtcod.console_get_height_rect(mapcon, 0, 0, width, SCREEN_HEIGHT, header) height = len(options) + header_height if talk: width = 50 x = 0 y = SCREEN_HEIGHT - height else: x = SCREEN_WIDTH / 2 - width / 2 y = SCREEN_HEIGHT / 2 - height / 2 #Create the virtual console to write the menu on window = libtcod.console_new(width, height) while not libtcod.console_is_window_closed(): #Clear the console ready to draw libtcod.console_clear(window) #Draw the 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) #Iterate through and print the options, highlighting the current selection. i = header_height for index, option in enumerate(options): libtcod.console_set_default_foreground(window, libtcod.white) if index == choice: #Draw an arrow and hilight the option. libtcod.console_set_default_foreground(window, MENU_HILIGHT) libtcod.console_print_ex(window, 0, i, libtcod.BKGND_NONE, libtcod.LEFT, '>') libtcod.console_print_ex(window, 1, i, libtcod.BKGND_NONE, libtcod.LEFT, option) i += 1 #Blit the window to the root and flush to render everything. libtcod.console_blit(window, 0, 0, width, height, 0, x, y) libtcod.console_flush() libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, key, mouse, True) if key.vk == libtcod.KEY_ENTER: return choice if key.vk == libtcod.KEY_ESCAPE: return None #Up and down arrows change selection elif key.vk == libtcod.KEY_UP or key.vk == libtcod.KEY_KP8: new_choice = choice - 1 elif key.vk == libtcod.KEY_DOWN or key.vk == libtcod.KEY_KP2: new_choice = choice + 1 #Check that we're not selecting outside the boundary if 0 <= new_choice < len(options): choice = new_choice
def render_info_panel(console): libtcod.console_set_default_background(info, libtcod.darker_sepia) libtcod.console_set_default_foreground(info, libtcod.light_gray) libtcod.console_clear(info) #Print out the characters name, class, and level libtcod.console_print_ex(info, INFO_WIDTH / 2, 1, libtcod.BKGND_NONE, libtcod.CENTER, 'Jeraman the Green') libtcod.console_print_ex(info, INFO_WIDTH / 2, 3, libtcod.BKGND_NONE, libtcod.CENTER, 'Novice Adventurer') libtcod.console_print_ex(info, INFO_WIDTH / 2, 5, libtcod.BKGND_NONE, libtcod.CENTER, 'Level: ' + str(player.level)) libtcod.console_print_ex(info, INFO_WIDTH / 2, 7, libtcod.BKGND_NONE, libtcod.CENTER, '---------------------------') #Show the players stats render_bar(info, 2, 9, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp, libtcod.light_red, libtcod.darker_red) render_bar(info, 2, 11, BAR_WIDTH, 'MANA', 30, 30, libtcod.light_blue, libtcod.darker_blue) libtcod.console_print_ex(info, INFO_WIDTH / 2, 13, libtcod.BKGND_NONE, libtcod.RIGHT, 'Strength: ' + str(player.fighter.base_strength)) libtcod.console_print_ex(info, INFO_WIDTH / 2, 15, libtcod.BKGND_NONE, libtcod.RIGHT, 'Defense: ' + str(player.fighter.base_defence)) libtcod.console_print_ex(info, INFO_WIDTH / 2, 17, libtcod.BKGND_NONE, libtcod.RIGHT, 'Agility: ' + str(player.fighter.base_agility)) libtcod.console_print_ex(info, INFO_WIDTH / 2, 19, libtcod.BKGND_NONE, libtcod.RIGHT, 'Accuracy: ' + str(player.fighter.base_accuracy)) libtcod.console_print_ex( info, INFO_WIDTH / 2, 22, libtcod.BKGND_NONE, libtcod.CENTER, 'Damage: ' + str(player.fighter.base_strength) + ' (+' + str(player.fighter.equipmentDamage) + ')') libtcod.console_print_ex( info, INFO_WIDTH / 2, 24, libtcod.BKGND_NONE, libtcod.CENTER, 'Protection: ' + str(player.fighter.base_protection) + ' (+' + str(player.fighter.equipmentProtection) + ')') libtcod.console_print_ex(info, INFO_WIDTH / 2, 26, libtcod.BKGND_NONE, libtcod.CENTER, '---------------------------') libtcod.console_print_ex(info, INFO_WIDTH / 2, 28, libtcod.BKGND_NONE, libtcod.CENTER, 'Equipment') #Loop through the inventory, and identify all equipped items and their equipment slot equipped_items = {} for item in inventory: text = item.name if item.equipment and item.equipment.is_equipped: equipped_items[item.equipment.slot] = text libtcod.console_print_ex(info, INFO_WIDTH / 14, 30, libtcod.BKGND_NONE, libtcod.LEFT, 'Head:') if 'head' in equipped_items: libtcod.console_print_ex(info, INFO_WIDTH / 2, 31, libtcod.BKGND_NONE, libtcod.CENTER, equipped_items['head']) else: libtcod.console_print_ex(info, INFO_WIDTH / 2, 31, libtcod.BKGND_NONE, libtcod.CENTER, 'N/A') libtcod.console_print_ex(info, INFO_WIDTH / 5, 33, libtcod.BKGND_NONE, libtcod.CENTER, 'Torso:') if 'torso' in equipped_items: libtcod.console_print_ex(info, INFO_WIDTH / 2, 34, libtcod.BKGND_NONE, libtcod.CENTER, equipped_items['torso']) else: libtcod.console_print_ex(info, INFO_WIDTH / 2, 34, libtcod.BKGND_NONE, libtcod.CENTER, 'N/A') libtcod.console_print_ex(info, INFO_WIDTH / 12, 36, libtcod.BKGND_NONE, libtcod.LEFT, 'Left hand:') if 'left-hand' in equipped_items: libtcod.console_print_ex(info, INFO_WIDTH / 2, 37, libtcod.BKGND_NONE, libtcod.CENTER, equipped_items['left-hand']) else: libtcod.console_print_ex(info, INFO_WIDTH / 2, 37, libtcod.BKGND_NONE, libtcod.CENTER, 'N/A') libtcod.console_print_ex(info, INFO_WIDTH / 12, 39, libtcod.BKGND_NONE, libtcod.LEFT, 'Right hand:') if 'right-hand' in equipped_items: libtcod.console_print_ex(info, INFO_WIDTH / 2, 40, libtcod.BKGND_NONE, libtcod.CENTER, equipped_items['right-hand']) else: libtcod.console_print_ex(info, INFO_WIDTH / 2, 40, libtcod.BKGND_NONE, libtcod.CENTER, 'N/A') libtcod.console_print_ex(info, INFO_WIDTH / 5, 42, libtcod.BKGND_NONE, libtcod.CENTER, 'Gloves:') if 'hands' in equipped_items: libtcod.console_print_ex(info, INFO_WIDTH / 2, 43, libtcod.BKGND_NONE, libtcod.CENTER, equipped_items['hands']) else: libtcod.console_print_ex(info, INFO_WIDTH / 2, 43, libtcod.BKGND_NONE, libtcod.CENTER, 'N/A') libtcod.console_print_ex(info, INFO_WIDTH / 14, 45, libtcod.BKGND_NONE, libtcod.LEFT, 'Legs:') if 'legs' in equipped_items: libtcod.console_print_ex(info, INFO_WIDTH / 2, 46, libtcod.BKGND_NONE, libtcod.CENTER, equipped_items['legs']) else: libtcod.console_print_ex(info, INFO_WIDTH / 2, 46, libtcod.BKGND_NONE, libtcod.CENTER, 'N/A') libtcod.console_print_ex(info, INFO_WIDTH / 14, 48, libtcod.BKGND_NONE, libtcod.LEFT, 'Feet:') if 'feet' in equipped_items: libtcod.console_print_ex(info, INFO_WIDTH / 2, 49, libtcod.BKGND_NONE, libtcod.CENTER, equipped_items['feet']) else: libtcod.console_print_ex(info, INFO_WIDTH / 2, 49, libtcod.BKGND_NONE, libtcod.CENTER, 'N/A') libtcod.console_print_ex(info, INFO_WIDTH / 2, 51, libtcod.BKGND_NONE, libtcod.CENTER, '---------------------------') libtcod.console_print_ex(info, INFO_WIDTH / 2, 52, libtcod.BKGND_NONE, libtcod.CENTER, 'Experience') level_up_xp = LEVEL_UP_BASE + player.level * LEVEL_UP_FACTOR render_bar(info, 2, 54, BAR_WIDTH, 'XP', player.fighter.xp, level_up_xp, libtcod.light_yellow, libtcod.darker_yellow) libtcod.console_blit(info, 0, 0, INFO_WIDTH, INFO_HEIGHT, 0, MAP_WIDTH + 2, 1)
def render_all(): global fov_map, color_dark_wall, color_light_wall global color_dark_ground, color_light_ground global fov_recompute, color_index1, color_index2, step 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, libtcod.Color(color_index2, 0, color_index1), libtcod.BKGND_SET) #since it's visible, explore it map[x][y].explored = True # some fun color cycling with offset cosine waves. it cycles blue and red if color_index <= 255: step += .01 color_index1 = int(255 / 8 * (math.cos(step) + 1)) color_index2 = int(255 / 8 * (math.cos(step + 3.14) + 1)) #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)) libtcod.console_print_ex( 0, SCREEN_WIDTH - 2, 1, libtcod.BKGND_NONE, libtcod.RIGHT, 'hi there') #playing around with placing text around the screen.
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 _draw_object(player, o): global _con libtcod.console_set_default_foreground(_con, o.color) (x, y) = ScreenCoords.fromWorldCoords(player.camera_position, o.pos) libtcod.console_put_char(_con, x, y, o.char, libtcod.BKGND_NONE)
def draw_entity(con, entity, fov_map, game_map): if libtcod.map_is_in_fov(fov_map, entity.x, entity.y) or ( entity.stairs and game_map.tiles[entity.x][entity.y].explored): libtcod.console_set_default_foreground(con, entity.color) libtcod.console_put_char(con, entity.x, entity.y, entity.char, libtcod.BKGND_NONE)
def main(userID): global changeLevel global PlayerID PlayerID = userID global player PlayerName = sqlcon.sqlQuery("SELECT Name FROM User WHERE ID=%s" % PlayerID)[0][0] # playerstats all the values ID(Primary Key) and User_ID(Fotrign Key) are useless for now ID, MaxHP, CurrentHP, PositionX, PositionY, Attack, Defence, User_ID = sqlcon.getPlayersStats( PlayerID)[0] player = Actors.Player(PlayerName, MaxHP, CurrentHP, Attack, Defence, 0, PositionY, PositionX, '@') global exity, exitx global playerScore playerScore = getScore(PlayerID)[0][0] if playerScore == None: playerScore = 0 global smap smap = [] smap = sqlcon.getMapDataForID(PlayerID) global LevelID LevelID = sqlcon.getLevelIDforUserID(PlayerID)[0][0] changeLevel(LevelID) global moveTimer moveTimer = 0 libtcod.console_set_default_foreground(0, libtcod.lighter_grey) for Object in objects: Object.draw() while not libtcod.console_is_window_closed(): libtcod.console_set_default_foreground(0, libtcod.white) libtcod.console_print(0, 1, 23, " ") libtcod.console_print(0, 1, 23, "HP: %s/%s" % (player.Hp, player.HPMax)) if player.Hp <= 0: gameOver() break libtcod.console_print(0, exitx, exity, ">") player.draw() libtcod.console_flush() # draws(flushes) the buffer player.clear() for Enemy in enemies: Enemy.clear() # handle keys and exit game if needed exit = handleKeys() if levelChange: continue moveEnemies() libtcod.console_set_default_foreground(0, libtcod.green) for Enemy in enemies: Enemy.draw() moveTimer += 1 if exit: break sqlcon.endConnection()
def _pwrite(line, string, color=libtcod.white): global _panel libtcod.console_set_default_foreground(_panel, color) libtcod.console_print_ex(_panel, 1, line, libtcod.BKGND_NONE, libtcod.LEFT, string)
def render_all(): global cam_x, cam_y #clear the city locations using OLD cam position. for city in R.cities: loc = R.tiles[city.x][city.y] colour = loc.bg libtcod.console_set_char_background(con, cam_x + city.x, cam_y + city.y, colour, libtcod.BKGND_SET) libtcod.console_set_char(con, cam_x + city.x, cam_y + city.y, ord(' ')) cam_x = scrolling_map(player.x, R.MAP_VIEW_WIDTH / 2, R.MAP_VIEW_WIDTH, R.MAP_WIDTH) cam_y = scrolling_map(player.y, R.MAP_VIEW_HEIGHT / 2, R.MAP_VIEW_HEIGHT, R.MAP_HEIGHT) #now draw the map! for y in range(min(R.MAP_VIEW_HEIGHT, len( R.world.tiles[0]))): #this refers to the SCREEN position. NOT map. for x in range(min(R.MAP_VIEW_WIDTH, len(R.world.tiles))): map_pos_x = x + cam_x map_pos_y = y + cam_y if map_pos_x >= R.MAP_WIDTH: map_pos_x = R.MAP_WIDTH - 1 if map_pos_y >= R.MAP_HEIGHT: map_pos_y = R.MAP_HEIGHT - 1 tile = R.world.tiles[map_pos_x][map_pos_y] #=============================================================== # try: # tile = map[map_pos_x][map_pos_y] # except: # print str(map_pos_x) + " or " + str(map_pos_y) + " is out of bounds." # break #=============================================================== #visible = libtcod.map_is_in_fov(fov_map, tile.x, tile.y) visible = True #wall = tile.block_sight if not visible: pass #TODO: re-do the visible/ not visible code. #if it"s not visible right now, the player can only see it if it"s explored #if tile.explored: #if wall: # libtcod.console_set_char_background(con, x, y, color_dark_wall, libtcod.BKGND_SET) # libtcod.console_set_char(con, x, y, " ") #else: # libtcod.console_set_char_background(con, x, y, color_dark_ground, libtcod.BKGND_SET) # libtcod.console_set_char(con, x, y, " ") else: #it"s visible if tile.POI is None: if traffic: # for b&w image. v = world.get_foot_traffic(map_pos_x, map_pos_y) colour = libtcod.Color(v, v, v) libtcod.console_set_char_background( con, x, y, colour, libtcod.BKGND_SET) libtcod.console_set_char(con, x, y, " ") elif temperature: # for b&w image. v = world.get_temperature(map_pos_x, map_pos_y) v = int(v) colour = libtcod.Color(v, v, v) libtcod.console_set_char_background( con, x, y, colour, libtcod.BKGND_SET) libtcod.console_set_char(con, x, y, " ") else: colour = tile.bg libtcod.console_set_char(con, x, y, " ") libtcod.console_set_char_background( con, x, y, colour, libtcod.BKGND_SET) #libtcod.console_set_char_foreground(con, x, y, libtcod.black) #libtcod.console_set_char(con, x, y, libtcod.CHAR_BULLET) else: libtcod.console_set_char_background( con, x, y, tile.POI.colour, libtcod.BKGND_SET) libtcod.console_set_char_foreground( con, x, y, libtcod.white) libtcod.console_set_char(con, x, y, tile.POI.char) #since it"s visible, explore it tile.explored = True #now draw the mini map for cell_x in range(len(world.mini_map)): for cell_y in range(len(world.mini_map[cell_x])): colour = world.mini_map[cell_x][cell_y].bg libtcod.console_set_char_background(minmap, cell_x, cell_y, colour, libtcod.BKGND_SET) #libtcod.console_set_char_foreground(con, x, y, libtcod.white) # for char in R.world_obj: # if char != player: # char.draw(cam_x, cam_y) #now draw all the merchants for city in cities: for merchant in city.trade_house.caravans_out: merchant.draw(cam_x, cam_y) for objects in R.world_obj: if objects.ai: objects.clear(cam_x, cam_y) objects.draw(cam_x, cam_y) player.draw(cam_x, cam_y) libtcod.console_clear(message_bar) libtcod.console_set_default_foreground(message_bar, libtcod.white) libtcod.console_print_ex( message_bar, 0, 0, libtcod.BKGND_NONE, libtcod.LEFT, str(date[0]) + " " + str(date[1][2]) + " " + str(date[1][0]) + " " + str(date[2][0])) # print the messages, one line at a time. y = 2 for (line, colour) in R.game_msgs: libtcod.console_set_default_foreground(message_bar, colour) libtcod.console_print_ex(message_bar, R.MSG_X, R.MSG_HEIGHT - y, libtcod.BKGND_NONE, libtcod.LEFT, line) y += 1 # y = 0 # for y in range(R.MAP_HEIGHT): # for x in range(R.MAP_WIDTH): # libtcod.console_set_char_background(con, x, y, map_[x][y].bg, libtcod.BKGND_SET) #libtcod.console_print_ex(message_bar, R.SCREEN_WIDTH - R.INFO_BAR_WIDTH, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse()) libtcod.console_set_default_background(con, libtcod.white) libtcod.console_blit(con, 0, 0, R.MAP_VIEW_WIDTH, R.MAP_VIEW_HEIGHT, 0, 0, 0) #libtcod.console_blit(con, mini_map_x, mini_map_y, mini_map_x+ mini_map_width, mini_map_y +mini_map_height, 0, 0, 0) libtcod.console_blit(con_char, 0, 0, R.MAP_VIEW_WIDTH, R.MAP_VIEW_HEIGHT, 0, 0, 0, 1.0, 0.0) libtcod.console_blit(inf, 0, 0, R.INFO_BAR_WIDTH, R.SCREEN_HEIGHT, 0, R.MAP_VIEW_WIDTH, 0) libtcod.console_blit(minmap, 0, 0, R.INFO_BAR_WIDTH, R.PANEL_HEIGHT, 0, R.MAP_VIEW_WIDTH, R.PANEL_Y) libtcod.console_blit(message_bar, 0, 0, R.PANEL_WIDTH, R.PANEL_HEIGHT, 0, 0, R.PANEL_Y) libtcod.console_flush()
def drawStats(): libtcod.console_set_default_foreground(0, libtcod.white) libtcod.console_print(0, 15, 23, "Atk: %s" % player.Attack) #Attack points libtcod.console_print(0, 15, 24, "Def: %s" % player.Defence) #Defence points
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height, bar_width, panel_height, panel_y, mouse, colors, game_state): if fov_recompute: for y in range(game_map.height): for x in range(game_map.width): visible = libtcod.map_is_in_fov(fov_map, x, y) wall = game_map.tiles[x][y].block_sight 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) for entity in entities_in_render_order: draw_entity(con, entity, fov_map, game_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)) ''' Danny code to center player and have window scroll r = 20 libtcod.console_blit(con, player.x - r, player.y - r, 2*r+1, 2*r+1, 0, int(screen_width/2) - r, int(screen_height/2) - r) ''' libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0) libtcod.console_set_default_background(panel, libtcod.black) libtcod.console_clear(panel) y = 1 for message in message_log.messages: libtcod.console_set_default_foreground(panel, message.color) libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE, libtcod.LEFT, message.text) y += 1 render_bar(panel, 1, 1, bar_width, "HP", player.fighter.hp, player.fighter.max_hp, libtcod.light_red, libtcod.darker_red) render_bar(panel, 1, 2, bar_width, "EXP", player.level.current_xp, player.level.experience_to_next_level, libtcod.light_blue, libtcod.darker_blue) libtcod.console_print_ex(panel, 1, 4, libtcod.BKGND_NONE, libtcod.LEFT, "Gold: {0}".format(player.fighter.gold)) if player.inventory.search("Health Talisman") is not None: render_bar(panel, 1, 3, bar_width, "Talisman HP", player.fighter.talismanhp, player.fighter.max_hp, libtcod.light_purple, libtcod.darker_purple) libtcod.console_print_ex( panel, 1, 5, libtcod.BKGND_NONE, libtcod.LEFT, "Dungeon Level: {0}".format(game_map.dungeon_level)) libtcod.console_set_default_foreground(panel, libtcod.light_gray) libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse(mouse, entities, fov_map)) libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y) if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY): if game_state == GameStates.SHOW_INVENTORY: inventory_title = "Press the key next to an item to use it, or ESC to cancel.\n" else: inventory_title = "Press the key next to an item to drop it, or ESC to cancel.\n" inventory_menu(con, inventory_title, player, 50, screen_width, screen_height) elif game_state == GameStates.SHOW_EQUIPMENT_INVENTORY: inventory_title = "Press the key next to an item to equip it, or ESC to cancel.\n" equipment_inventory_menu(con, inventory_title, player, 50, screen_width, screen_height) elif game_state == GameStates.LEVEL_UP: level_up_menu(con, "Level up! Choose a stat to raise:", player, 40, screen_width, screen_height) elif game_state == GameStates.CHARACTER_SCREEN: character_screen(player, 30, 10, screen_width, screen_height) elif game_state == GameStates.SHOW_BAG: bag_title = "Press the key next to the option to open the bag.\n" bag_menu(con, bag_title, player, 50, screen_width, screen_height) elif game_state == GameStates.HELP_MENU: help_menu(player, 30, 10, screen_width, screen_height)
def city_menu(): width, height = R.MAP_VIEW_WIDTH - 4, R.MAP_VIEW_HEIGHT - 4 city_select_pop = libtcod.console_new(width, height) selected_city = None limit = len(cities) - 1 pos_x = R.MAP_VIEW_WIDTH / 2 - width / 2 pos_y = R.MAP_VIEW_HEIGHT / 2 - height / 2 for a in range(R.MAP_VIEW_WIDTH - 4): #clear screen, colour dark grey, every cycle for b in range(R.MAP_VIEW_HEIGHT - 4): #libtcod.console_print_rect(window, a, b, libtcod.console_print_rect_ex(city_select_pop, a, b, R.MAP_VIEW_WIDTH - 4, R.MAP_VIEW_HEIGHT - 4, libtcod.BKGND_NONE, libtcod.LEFT, " ") libtcod.console_blit(city_select_pop, 0, 0, width, height, 0, pos_x, pos_y, 1.0, 0.9) libtcod.console_flush() offset = 0 key = libtcod.console_check_for_keypress() while selected_city == None: #or key.vk != libtcod.KEY_ENTER: libtcod.console_clear(city_select_pop) libtcod.console_set_default_foreground(city_select_pop, libtcod.yellow) libtcod.console_print_ex(city_select_pop, 1, 1, libtcod.BKGND_NONE, libtcod.LEFT, "Select the city") libtcod.console_set_default_foreground(city_select_pop, libtcod.light_yellow) #city_length = len(cities) for lines in range(min(len(cities), 10)): # picks the smaller of the two. libtcod.console_print_ex( city_select_pop, 2, 3 + lines, libtcod.BKGND_NONE, libtcod.LEFT, chr(48 + lines) + ": " + cities[lines + offset].name) # libtcod.console_blit(city_select_pop, 0, 0, width, height, 0, pos_x, pos_y, 1.0, 0.9) libtcod.console_flush() key = libtcod.console_wait_for_keypress(True) max_key = 48 + min( len(cities) - 1, 10) # and again, picks the smaller f the two values. #to prevent it trying to be longer than amount of cities if key.c == 122: #z offset -= 1 if offset < 0: offset = 0 elif key.c == 120: #x offset += 1 if 9 + offset > limit: offset = limit - 10 elif key.c == 48: # 0 selected_city = cities[0 + offset] elif key.c == 49: # 1 if max_key >= 49: selected_city = cities[1 + offset] #I want to interact with the item in the '1' slot in the interface elif key.c == 50: # 2 if max_key >= 50: selected_city = cities[2 + offset] elif key.c == 51: #3 if max_key >= 51: selected_city = cities[3 + offset] elif key.c == 52: #4 if max_key >= 52: selected_city = cities[4 + offset] elif key.c == 53: #5 if max_key >= 53: selected_city = cities[5 + offset] elif key.c == 54: #6 if max_key >= 54: selected_city = cities[6 + offset] elif key.c == 55: #7 if max_key >= 55: selected_city = cities[7 + offset] elif key.c == 56: #8 if max_key >= 56: selected_city = cities[8 + offset] elif key.c == 57: #9 if max_key >= 57: selected_city = cities[9 + offset] elif key.vk == libtcod.KEY_ENTER or key.vk == libtcod.KEY_BACKSPACE: break else: pass #selected_city = None libtcod.console_blit(city_select_pop, 0, 0, width, height, 0, pos_x, pos_y, 1.0, 0.9) libtcod.console_flush() for a in range(R.MAP_WIDTH - 4): #clear screen, colour dark grey, every cycle for b in range(R.MAP_HEIGHT - 4): #libtcod.console_print_rect(window, a, b, libtcod.console_print_rect_ex(city_select_pop, a, b, R.MAP_VIEW_WIDTH - 4, R.MAP_VIEW_HEIGHT - 4, libtcod.BKGND_NONE, libtcod.LEFT, " ") if selected_city != None: key = libtcod.console_check_for_keypress() while not key.vk == libtcod.KEY_ENTER or key.vk == libtcod.KEY_BACKSPACE: current_offset = offset for a in range(R.MAP_WIDTH - 4): #clear screen, colour dark grey, every cycle for b in range(R.MAP_HEIGHT - 4): #libtcod.console_print_rect(window, a, b, libtcod.console_put_char(city_select_pop, a, b, ' ', libtcod.BKGND_NONE) #print the header with auto-wrap libtcod.console_set_default_foreground(city_select_pop, libtcod.white) libtcod.console_print_rect_ex(city_select_pop, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, selected_city.name + " stats!") libtcod.console_print_ex(city_select_pop, 2, 5, libtcod.BKGND_NONE, libtcod.LEFT, "-----------------") libtcod.console_print_ex(city_select_pop, 3, 6, libtcod.BKGND_NONE, libtcod.LEFT, "produces:-") y = 8 for resource in selected_city.producing: if selected_city.producing[resource][1] > 0: libtcod.console_print_ex(city_select_pop, 4, y, libtcod.BKGND_NONE, libtcod.LEFT, resource) libtcod.console_print_ex( city_select_pop, 13, y, libtcod.BKGND_NONE, libtcod.LEFT, str(selected_city.producing[resource][1])) y += 1 libtcod.console_print_ex(city_select_pop, 2, y, libtcod.BKGND_NONE, libtcod.LEFT, "\n") y += 1 libtcod.console_print_ex(city_select_pop, 3, y, libtcod.BKGND_NONE, libtcod.LEFT, "desires:-") y += 2 for resource in selected_city.desired: desire = selected_city.desired[resource] libtcod.console_print_ex(city_select_pop, 4, y, libtcod.BKGND_NONE, libtcod.LEFT, resource) libtcod.console_print_ex(city_select_pop, 13, y, libtcod.BKGND_NONE, libtcod.LEFT, str(desire)) y += 1 libtcod.console_print_ex(city_select_pop, 2, y, libtcod.BKGND_NONE, libtcod.LEFT, "-----------------") for resource in selected_city.trade_house.supply_demand: supply_demand = selected_city.trade_house.supply_demand[ resource] libtcod.console_print_ex(city_select_pop, 30, y, libtcod.BKGND_NONE, libtcod.LEFT, resource) libtcod.console_print_ex(city_select_pop, 40, y, libtcod.BKGND_NONE, libtcod.LEFT, str(supply_demand[0])) libtcod.console_print_ex(city_select_pop, 47, y, libtcod.BKGND_NONE, libtcod.LEFT, ", " + str(supply_demand[1])) libtcod.console_print_ex(city_select_pop, 54, y, libtcod.BKGND_NONE, libtcod.LEFT, ", " + str(supply_demand[2])) #libtcod.console_print_ex(window, 30, y, libtcod.BKGND_NONE, libtcod.LEFT, str(resource.quantity)) #libtcod.console_print_ex(window, 30, y, libtcod.BKGND_NONE, libtcod.LEFT, str(resource.quantity)) y += 1 libtcod.console_print_ex(city_select_pop, 2, y, libtcod.BKGND_NONE, libtcod.LEFT, "-----------------") libtcod.console_blit(city_select_pop, 0, 0, width, height, 0, pos_x, pos_y, 1.0, 0.9) libtcod.console_flush() key = libtcod.console_wait_for_keypress(True) libtcod.console_blit(city_select_pop, 0, 0, width, height, 0, pos_x, pos_y, 1.0, 0.9) libtcod.console_flush()