def end_of_frame(draw_map=True): render_scene() if is_view_in_scene('message_box'): tcod.console_set_default_foreground(0, tcod.gray) tcod.console_print_frame(0, 0, MAP_WINDOW_SIZE[1], MESSAGE_WINDOW_SIZE[0], MESSAGE_WINDOW_SIZE[1], clear=False, fmt='Messages') _dialog = None if SETTINGS['controlling'] and LIFE[SETTINGS['controlling']]['dialogs']: _dialog = LIFE[SETTINGS['controlling']]['dialogs'][0] if _dialog and 'console' in _dialog: _dialog['_drawn'] = True tcod.console_blit(_dialog['console'], 0, 0, WINDOW_SIZE[0], 40, 0, 0, 0, 1, 0.9) for menu in MENUS: tcod.console_blit(menu['settings']['console'],0,0, menu['settings']['size'][0], menu['settings']['size'][1],0, menu['settings']['position'][0], menu['settings']['position'][1],1,0.5) if SETTINGS['draw console']: tcod.console_blit(CONSOLE_WINDOW,0,0,CONSOLE_WINDOW_SIZE[0],CONSOLE_WINDOW_SIZE[1],0,0,0,1,0.5) tcod.console_flush()
def end_of_frame(draw_map=True): render_scene() if is_view_in_scene('message_box'): tcod.console_set_default_foreground(0, tcod.gray) tcod.console_print_frame(0, 0, MAP_WINDOW_SIZE[1], MESSAGE_WINDOW_SIZE[0], MESSAGE_WINDOW_SIZE[1], clear=False, fmt='Messages') _dialog = None if SETTINGS['controlling'] and LIFE[SETTINGS['controlling']]['dialogs']: _dialog = LIFE[SETTINGS['controlling']]['dialogs'][0] if _dialog and 'console' in _dialog: _dialog['_drawn'] = True tcod.console_blit(_dialog['console'], 0, 0, WINDOW_SIZE[0], 40, 0, 0, 0, 1, 0.9) for menu in MENUS: tcod.console_blit(menu['settings']['console'], 0, 0, menu['settings']['size'][0], menu['settings']['size'][1], 0, menu['settings']['position'][0], menu['settings']['position'][1], 1, 0.5) if SETTINGS['draw console']: tcod.console_blit(CONSOLE_WINDOW, 0, 0, CONSOLE_WINDOW_SIZE[0], CONSOLE_WINDOW_SIZE[1], 0, 0, 0, 1, 0.5) tcod.console_flush()
def draw_menu(console, header, items, width, height, selected_index): """Draws a menu and returns. Used in non-blocking menu loops Usually drawn to a temporary console and then blitted to wherever you need it """ truncated_items = [] for item in items: if len(item) > width - 2: truncated_items.append(item[:width - len(constant.TRUNCATE_SUFFIX) + 2] + constant.TRUNCATE_SUFFIX) else: truncated_items.append(item) truncated_header = header if len(header) < width - 2 else header[:width - len(constant.TRUNCATE_SUFFIX) + 2] + constant.TRUNCATE_SUFFIX tcod.console_set_default_foreground(console, tcod.white) tcod.console_print_frame(console, 0, 0, width, height, False, tcod.BKGND_NONE, False) if header: tcod.console_print_ex(console, width / 2, 0, tcod.BKGND_NONE, tcod.CENTER, truncated_header) for pos in xrange(len(truncated_items)): if pos == selected_index: tcod.console_set_default_foreground(console, tcod.white) else: tcod.console_set_default_foreground(console, tcod.grey) tcod.console_print_ex(console, 1, pos + 1, tcod.BKGND_NONE, tcod.LEFT, truncated_items[pos])
def build(self): #print 'built!' libtcod.console_set_default_foreground(self.console, self.get_palette().LBLUE) libtcod.console_set_default_background(self.console, self.get_palette().DGREY) libtcod.console_print_frame(self.console, 0, 0, self.width, self.height, True, libtcod.BKGND_SET, 'fenetre1') temp = libtcod.console_new(self.width - 2, self.height - 2) libtcod.console_set_default_foreground(temp, self.get_palette().LBLUE) libtcod.console_set_default_background(temp, self.get_palette().DGREY) y = 1 for elem in self.content: libtcod.console_clear(temp) height = elem.build(temp) libtcod.console_blit(temp, 0, 0, elem.width, elem.height, self.console, 1, y) y += height
def __init__(self, screen_w, screen_h, view_w, view_h, fullscreen=False): self.fullscreen = fullscreen self.screen_w, self.screen_h = screen_w, screen_h self.view_w, self.view_h = view_w, view_h # Setup Font font_filename = 'res/arial12x12.png' tcod.console_set_custom_font( font_filename, tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD) # Initialize screen title = 'Pyrouge' self.map_con = tcod.console_new( self.screen_w, self.screen_h) # This needs to only be as big as the map can be self.log_con = tcod.console_new(self.view_w, self.screen_h - self.view_h) self.status_con = tcod.console_new(self.screen_w - self.view_w, self.screen_h // 2) self.equip_con = tcod.console_new(self.screen_w - self.view_w, self.screen_h // 2) tcod.console_init_root(self.screen_w, self.screen_h, title, self.fullscreen) tcod.console_print_frame(self.status_con, 0, 0, self.screen_w - self.view_w, self.screen_h // 2, True, tcod.BKGND_NONE, 'STATUS') tcod.console_print_frame(self.equip_con, 0, 0, self.screen_w - self.view_w, self.screen_h // 2, True, tcod.BKGND_NONE, 'EQUIPMENT') self.msg_log = MessageLog(1, self.view_w - 2, self.screen_h - self.view_h - 2)
def build(self, con): libtcod.console_print_frame(con, 0, 0, self.width, self.height, False, libtcod.BKGND_SET) libtcod.console_put_char_ex(con, 13, 0, chr(196), libtcod.white, libtcod.black) if self.empty: pass else: temp = libtcod.console_new(self.width, self.height) self.unit_info.build(temp) libtcod.console_blit(temp, 0, 0, self.unit_info.width, self.unit_info.height, con, 1, 1) self.unit_info.set_pos(1, 1) libtcod.console_clear(temp) self.skill_info.build(temp) libtcod.console_blit(temp, 0, 0, self.skill_info.width, self.skill_info.height, con, 15, 1) self.skill_info.set_pos(16, 1) #libtcod.console_put_char_ex(con,0,i,chr(26),libtcod.white,libtcod.black) libtcod.console_clear(temp) libtcod.console_put_char_ex(con, 14, 0, chr(194), libtcod.white, libtcod.black) libtcod.console_put_char_ex(con, 14, self.height - 1, chr(193), libtcod.white, libtcod.black) for i in range(1, self.height - 1): libtcod.console_put_char_ex(con, 14, i, chr(179), libtcod.white, libtcod.black)
def show_popup(text, title): global popup lines = [ string for line in text.split('\n') for string in textwrap.wrap(line, width=MAX_MAP_WIDTH - 4) ] width = max( len(string) for string in lines ) + 4 # 1 space on each side, plus 1 line for the square on each side width = max(width, len(title)) height = len(lines) + 4 # ditto x = (MAX_MAP_WIDTH - width) // 2 y = (MAX_MAP_HEIGHT - height) // 2 tcod.console_print_frame(popup, x, y, width, height, fmt=title) row = 0 for line in lines: tcod.console_print(popup, x + 2, y + 2 + row, line) row += 1 tcod.console_blit(popup, 0, 0, tcod.console_get_width(popup), tcod.console_get_height(popup), 0, 0, 0) tcod.console_flush() key = tcod.console_wait_for_keypress(True) # destroy the popup tcod.console_blit(console, 0, 0, tcod.console_get_width(console), tcod.console_get_height(console), 0, 0, 0) tcod.console_flush() return key
def draw(self, main_map): #Settings libtcod.console_set_default_background(self.console, libtcod.black) libtcod.console_set_alignment(self.console, libtcod.CENTER) if main_map.selected_unit: start = (self.width - 4)/2 #Draw all units in the unit image for x in range(self.width - 4): for y in range(self.width - 4): libtcod.image_put_pixel(self.unit_image, x, y, main_map.map_list[main_map.selected_unit.x + x - start][main_map.selected_unit.y + y - start].color) for u in main_map.units: if u.x == (main_map.selected_unit.x + x - start) and u.y == (main_map.selected_unit.y + y - start): libtcod.console_set_char_foreground(self.console, x + 2, y + 4, u.color) libtcod.console_set_char(self.console, x + 2, y + 4, u.char) libtcod.console_print_frame(self.console, 0, 0, self.width, self.height, False, libtcod.BKGND_NONE, main_map.selected_unit.name) libtcod.console_rect(self.console, 0,0, 20, 1, False) libtcod.image_blit_rect(self.unit_image, self.console, 2, 4, self.width - 4, self.width - 4, libtcod.BKGND_SET) libtcod.console_set_alignment(self.console, libtcod.LEFT) #Unit stats statx = self.width + 1 libtcod.console_print(self.console, 2, statx, 'Speed') libtcod.console_print(self.console, 2, statx + 1, 'Attack') libtcod.console_print(self.console, 2, statx + 2, 'Armor') libtcod.console_set_alignment(self.console, libtcod.RIGHT) libtcod.console_print(self.console, self.width - 2, statx, str(main_map.selected_unit.speed)) libtcod.console_print(self.console, self.width - 2, statx + 1, str(main_map.selected_unit.attack)) libtcod.console_print(self.console, self.width - 2, statx + 2, str(main_map.selected_unit.armor)) libtcod.console_blit(self.console, 0, 0, self.width, self.height, 0, 1, 60 - self.height/2, 1, 0.75)
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, screen_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_print_frame(0, x - 1, y - 1, width + 2, height + 2, False, libtcod.BKGND_NONE) libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
def clear_all(self): """Prints frame in root, clears all (default clear=True)""" libtcod.console_print_frame(con=0, x=0, y=0, w=self.screen_width, h=self.screen_height, fmt=GAME_NAME)
def pop_up(width=None, height=None, title=None, text=None): mouse = Input.mouse key = Input.key # calculate total height for the header (after auto-wrap) and one line per option if width is None: width = Constants.MAP_CONSOLE_WIDTH - 30 if height is None: height = libtcod.console_get_height_rect( 0, 0, 0, width, Constants.SCREEN_HEIGHT, text) + 7 pop = libtcod.console_new(width, height) # print the header, with auto-wrap libtcod.console_set_default_foreground(pop, Constants.UI_PopFore) libtcod.console_set_default_background(pop, Constants.UI_PopBack) libtcod.console_print_frame(pop, 0, 0, width, height, clear=True, flag=libtcod.BKGND_SET, fmt=title) Render.print_rect(pop, 3, 3, width - 6, height, text) # blit the contents of "window" to the root console x = Constants.MAP_CONSOLE_WIDTH / 2 - width / 2 y = Constants.MAP_CONSOLE_HEIGHT / 2 - height / 2 button_text = 'Click to Continue' button = Button(button_text, width / 2, height - 3, function=close_window, target=pop, length=len(button_text)) libtcod.console_blit(pop, 0, 0, width, height, 0, x, y, 1.0, .85) while True: libtcod.console_blit(pop, 0, 0, width, height, 0, x, y, 1.0, 0.0) libtcod.console_flush() libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if button.draw(x, y) == 'close': return if key.vk == libtcod.KEY_ENTER and key.lalt: # Alt+Enter: toggle fullscreen libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) if key.vk == libtcod.KEY_ESCAPE or key.vk == libtcod.KEY_ESCAPE or key.vk == libtcod.KEY_SPACE: return
def loading_message(self, message, console, clear=True): if clear: libtcod.console_clear(console) libtcod.console_set_fade(255,libtcod.black) center_height = self.screen_height/2 third_width = self.screen_width/2 libtcod.console_print_ex(console, 0, center_height, libtcod.BKGND_SET, libtcod.LEFT, message.center(self.screen_width)) libtcod.console_print_frame(console, int(third_width*0.5), center_height-2, third_width, 5, clear=False, flag=libtcod.BKGND_SET, fmt=0) libtcod.console_blit(console, 0, 0, self.screen_width, self.screen_height, 0, 0, 0) libtcod.console_flush()
def _render_frame(self): """Renders the initial frame and title""" if self.active: libtcod.console_set_default_foreground(self._console, libtcod.dark_blue) else: libtcod.console_set_default_foreground(self._console, libtcod.darker_blue) libtcod.console_print_frame(self._console, 0, 0, self.width, self.height, False) libtcod.console_set_default_foreground(self._console, libtcod.light_gray) libtcod.console_print_ex(self._console, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, self.title)
def draw(self, con, border=True): if border: tcod.console_set_default_foreground(con, tcod.white) tcod.console_print_frame(con, 0, 0, self.width + 2, self.height + 2, True, tcod.BKGND_NONE, 'MESSAGE LOG') y = 1 for message in self.messages: tcod.console_set_default_foreground(con, message.color) tcod.console_print_ex(con, self.x, y, tcod.BKGND_NONE, tcod.LEFT, message.text) y += 1
def draw_inventory(con, inventory, title): INVENTORY_HEIGHT = len(inventory)+2 xx = game.GAME_WIDTH/2 - INVENTORY_WIDTH/2 yy = game.GAME_HEIGHT/2 - INVENTORY_HEIGHT/2 tcod.console_set_default_foreground(con, COL_A) tcod.console_print_frame(con, xx, yy, INVENTORY_WIDTH, INVENTORY_HEIGHT, fmt=title) for i in range(len(inventory)): line =' %s - %s' % (chr(ord('a')+i), inventory[i].name) if inventory[i].equipment and inventory[i].equipment.is_equipped: line += ' '+ chr(tcod.CHAR_BULLET_SQUARE) tcod.console_print(con, xx+2, yy+1+i, line) tcod.console_flush()
def pop_up(width=None, height=None, title=None, text=None): mouse = Input.mouse key = Input.key # calculate total height for the header (after auto-wrap) and one line per option if width is None: width = Constants.MAP_CONSOLE_WIDTH - 30 if height is None: height = libtcod.console_get_height_rect(0, 0, 0, width, Constants.SCREEN_HEIGHT, text) + 7 pop = libtcod.console_new(width, height) # print the header, with auto-wrap libtcod.console_set_default_foreground(pop, Constants.UI_PopFore) libtcod.console_set_default_background(pop, Constants.UI_PopBack) libtcod.console_print_frame(pop, 0, 0, width, height, clear=True, flag=libtcod.BKGND_SET, fmt=title) Render.print_rect(pop, 3, 3, width - 6, height, text) # blit the contents of "window" to the root console x = Constants.MAP_CONSOLE_WIDTH / 2 - width / 2 y = Constants.MAP_CONSOLE_HEIGHT / 2 - height / 2 button_text = 'Click to Continue' button = Button(button_text, width / 2, height - 3, function=close_window, target=pop, length=len(button_text)) libtcod.console_blit(pop, 0, 0, width, height, 0, x, y, 1.0, .85) while True: libtcod.console_blit(pop, 0, 0, width, height, 0, x, y, 1.0, 0.0) libtcod.console_flush() libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if button.draw(x, y) == 'close': return if key.vk == libtcod.KEY_ENTER and key.lalt: # Alt+Enter: toggle fullscreen libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) if key.vk == libtcod.KEY_ESCAPE or key.vk == libtcod.KEY_ESCAPE or key.vk == libtcod.KEY_SPACE: return
def __init__(self, x, y, panelwidth, panelheight, foreground=libtcodpy.white, background=libtcodpy.black, border=False): self.x = x self.y = y self.panelwidth = panelwidth self.panelheight = panelheight self._panel = libtcodpy.console_new(self.panelwidth, self.panelheight) libtcodpy.console_set_default_foreground(self._panel, foreground) libtcodpy.console_set_default_background(self._panel, background) self.border = border if self.border: libtcodpy.console_print_frame(self._panel, 0, 0, panelwidth, panelheight)
def galaxy_map_loop(self): self.current_screen = 'galaxy' done = False while not done: libtcod.sys_check_for_event(libtcod.KEY_PRESSED|libtcod.KEY_RELEASED|libtcod.EVENT_MOUSE, self.key, self.mouse) libtcod.console_clear(self.galaxy_map_console) self.starfield.draw() self.nebula.draw() self.galaxy.draw(self.buffer) self.buffer.blit(self.console) libtcod.console_blit(self.console, 0, 0, self.screen_width, self.screen_height, 0, 0, 0) # Galaxy Map Border/Frame libtcod.console_print_frame(self.galaxy_map_console, 0, 0, self.screen_width, self.screen_height, clear=False, flag=libtcod.BKGND_SET, fmt=0) # Title in the center of the top border top_title = "[ Galaxy Map ]" libtcod.console_print_ex(self.galaxy_map_console, (self.screen_width/2) - (len(top_title)/2), 0, libtcod.BKGND_SET, libtcod.LEFT, top_title) # Title in the center of the bottom border bottom_title = "[ Seed: {0} ]".format( self.galaxy.seed ) libtcod.console_print_ex(self.galaxy_map_console, (self.screen_width/2) - (len(bottom_title)/2), self.screen_height-1, libtcod.BKGND_SET, libtcod.LEFT, bottom_title) # Extra info in upper right info = ("Current Sector: {0}\n" "Target Sector: {1}\n").format( self.galaxy.sectors[self.galaxy.current_sector].name, self.galaxy.sectors[ self.galaxy.sectors[self.galaxy.current_sector].neighbors[self.galaxy.targeted_sector_index] ].name ) libtcod.console_print_ex(self.galaxy_map_console, 1, 1, libtcod.BKGND_SET, libtcod.LEFT, info) libtcod.console_blit(self.galaxy_map_console, 0, 0, self.screen_width, self.screen_height, 0, 0, 0, 1.0, 0.25) libtcod.console_flush() self.buffer.clear(self.sector.background[0], self.sector.background[1], self.sector.background[2]) player_action = self.handle_keys() if player_action == 1: done = True self.current_screen = 'flight'
def print_frame(self, x=0, y=0, width=None, height=None, clear=True, effect=libtcod.BKGND_SET): if width is None: width = self.width - x if height is None: height = self.height - y return libtcod.console_print_frame(self.console_id, x, y, width, height, clear, effect)
def draw_equipment(con, inventory, title): INVENTORY_HEIGHT = len(inventory)+2 xx = game.GAME_WIDTH/2 - INVENTORY_WIDTH/2 yy = game.GAME_HEIGHT/2 - INVENTORY_HEIGHT/2 tcod.console_set_default_foreground(con, COL_A) tcod.console_print_frame(con, xx, yy, INVENTORY_WIDTH, INVENTORY_HEIGHT, fmt=title) for i in range(len(inventory)): tcod.console_set_default_foreground(con, COL_B) line =' %s - %s' % (chr(ord('a')+i), inventory[i].name) if inventory[i].equipment: if inventory[i].equipment.is_equipped: line += ' ['+inventory[i].equipment.slot+']' else: tcod.console_set_default_foreground(con, tcod.lighter_gray) tcod.console_print(con, xx+2, yy+1+i, line) tcod.console_flush()
def render_all(): if glob.fov_recompute: glob.fov_recompute = False libtcod.map_compute_fov(fov_map, player.x, player.y, const.TORCH_RADIUS, const.FOV_LIGHT_WALLS, const.FOV_ALGO) for y in range(const.MAP_HEIGHT): for x in range(const.MAP_WIDTH): visible = libtcod.map_is_in_fov(fov_map, x, y) wall = glob.map[x][y].block_sight if not visible: #If out of FOV if glob.map[x][y].explored: if wall: libtcod.console_put_char_ex(view, x, y, '#', const.colour_dark_wall, const.colour_background) else: libtcod.console_put_char_ex(view, x, y, '.', const.colour_dark_ground, const.colour_background) else: #If visible if wall: libtcod.console_put_char_ex(view, x, y, '#', const.colour_light_wall, const.colour_background) else: libtcod.console_put_char_ex(view, x, y, '.', const.colour_light_ground, const.colour_background) glob.map[x][y].explored = True for object in glob.objects: if object != player: object.draw() player.draw() libtcod.console_blit(view, 0, 0, const.SCREEN_WIDTH, const.SCREEN_HEIGHT, 0, 0, 0) #Panel libtcod.console_set_default_background(panel, const.colour_background) libtcod.console_clear(panel) #Log y = 1 for (line, colour) in glob.game_msgs: libtcod.console_set_default_foreground(panel, colour) libtcod.console_print_ex(panel, const.MSG_X, y, libtcod.BKGND_NONE, libtcod.LEFT, line) y += 1 #GUI render_bar(1, 1, const.BAR_WIDTH, 'HP', player.creature.hp, player.creature.max_hp, libtcod.dark_red, libtcod.darker_red) render_bar(1, 2, const.BAR_WIDTH, 'EP', player.creature.ep, player.creature.max_ep, libtcod.dark_blue, libtcod.darker_blue) libtcod.console_set_default_foreground(panel, libtcod.light_gray) libtcod.console_print_ex(panel, 1, 5, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse()) #Outlines libtcod.console_print_frame(panel, 0, 0, const.SCREEN_WIDTH, const.PANEL_HEIGHT, clear=False, flag=libtcod.BKGND_NONE) #Blit that puppy! libtcod.console_blit(panel, 0, 0, const.SCREEN_WIDTH, const.PANEL_HEIGHT, 0, 0, const.PANEL_Y)
def title(text, padding=2, text_color=tcod.white, background_color=tcod.black): if not SETTINGS['running']: return False _center_x = (WINDOW_SIZE[0] / 2) - len(text) / 2 _center_y = WINDOW_SIZE[1] / 2 tcod.console_set_default_background(0, background_color) tcod.console_set_default_foreground(0, text_color) tcod.console_print_frame(0, _center_x - padding, _center_y - padding, len(text) + padding * 2, 1 + padding * 2, flag=tcod.BKGND_SET, clear=True) tcod.console_print(0, _center_x, _center_y, text) tcod.console_flush()
def draw(self, con): lbt.console_clear(self.w_console) lbt.console_print_frame(con, 0, 0, self.screen_width+2, self.screen_height+2, fmt="Game world") self.draw_gui(con) self.draw_world(self.get_scroll_x(), self.get_scroll_y()) if self.subscreen: self.subscreen.draw(con) lbt.console_blit(self.w_console, 0, 0, self.screen_width, self.screen_height, con, 1, 1)
def title(text, padding=2, text_color=tcod.white, background_color=tcod.black): if not SETTINGS['running']: return False _center_x = (WINDOW_SIZE[0]/2)-len(text)/2 _center_y = WINDOW_SIZE[1]/2 tcod.console_set_default_background(0, background_color) tcod.console_set_default_foreground(0, text_color) tcod.console_print_frame(0, _center_x-padding, _center_y-padding, len(text)+padding*2, 1+padding*2, flag=tcod.BKGND_SET, clear=True) tcod.console_print(0, _center_x, _center_y, text) tcod.console_flush()
def render(self, draw_frame=False, draw_index=False, align='left', fgalpha=.9, bgalpha=.3): if len(self.opts) > MAX_OPTS: raise ValueError('No more than %d options allowed.' % MAX_OPTS) # calculate height, set options window, print header _w, _h = self.width+2, self.h+2 #total width and height window = tl.console_new(_w, _h) tl.console_clear(window) tl.console_set_default_background(window, tl.violet) tl.console_set_default_foreground(window, tl.lightest_grey) if draw_frame: tl.console_print_frame(window, 0, 0, _w, _h) tl.console_print_rect_ex(window, 1,1, self.width,self.h, tl.BKGND_NONE,tl.LEFT, self.header) if self.opts != []: # draw a separator line if options are not empty tl.console_hline(window, 1, self.headerHeight+1, self.width) if draw_frame: tl.console_put_char(window, 0, self.headerHeight+1, tl.CHAR_TEEE) tl.console_put_char(window, self.width+1, self.headerHeight+1, tl.CHAR_TEEW) # print all options n,y = 0,self.headerHeight+2 sel = self.highlightedItemIdx if self.highlightedItemIdx >= 0 else MAX_OPTS+self.highlightedItemIdx for txt in self.opts: txt = txt.rjust(self.width) if align=='right'\ else txt.center(self.width) if align=='center'\ else ' '+txt.ljust(self.width)[:-3] if draw_index\ else txt.ljust(self.width) if draw_index: txt = ' %d %s' % (n, txt) txt = '{'+txt[1]+'}'+txt[6:] if sel == n else txt[3:] scolor = 'amber' if sel == n else 'light_grey' if self.isAnimated and sel == n: # hicky-hacky color animation scolor = tl.amber*(self.phase/PHASES) tl.console_set_color_control(tl.COLCTRL_1, scolor, tl.black) txt = '%c%s%c'%(tl.COLCTRL_1,txt.ljust(self.width),tl.COLCTRL_STOP) else: txt = tc.parse('{{%s}}%s{{stop}}'%(scolor,txt.ljust(self.width))) tl.console_print(window, 1, y, txt) n += 1; y += 1 # calculate window position, blit window to screen & flush x = SCREEN_W/2 - self.width/2 y = SCREEN_H/2 - self.h/2 tl.console_blit(window, 0, 0, _w, _h, 0, x, y, fgalpha, bgalpha)
def do_post_race(key, mouse): finished_race = g.season.races[g.season.current_race] full_panel = tcod.console_new(g.screen_width, g.screen_height) tcod.console_set_alignment(full_panel, tcod.CENTER) tcod.console_set_default_foreground(full_panel, tcod.sea) tcod.console_clear(full_panel) title = finished_race.circuit.name + ' Results' tcod.console_print_frame(full_panel, 1, 1, g.screen_width - 2, g.screen_height - 2, False, tcod.BKGND_DEFAULT, title) LINE_LENGTH = 50 header = 'Team' + (' ' * (LINE_LENGTH - 10)) + 'Points' underline = '=' * LINE_LENGTH tcod.console_print_ex(full_panel, 30, 20, tcod.BKGND_SET, tcod.LEFT, header) tcod.console_print_ex(full_panel, 30, 21, tcod.BKGND_SET, tcod.LEFT, underline) for place, team in finished_race.places.items(): # Record point data points = g.POINTS[place] g.season.standings[team] += points # Print info place_name = str(place) + '. ' + team.name point_string = str(points) space_count = LINE_LENGTH - (len(place_name) + len(point_string)) line = place_name + (' ' * space_count) + point_string tcod.console_print_ex(full_panel, 30, 21 + place, tcod.BKGND_SET, tcod.LEFT, line) tcod.console_blit(full_panel, 0, 0, g.screen_width, g.screen_height, 0, 0, 0) tcod.console_flush() # Wait for `tcod.Enter` to continue confirm = False while not confirm: tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, key, mouse) action = handle_keys(key) confirm = action.get('confirm') if confirm: g.season.current_race += 1 g.context = Context.SEASON_OVERVIEW
def build(self): #print 'built!' libtcod.console_set_default_foreground(self.console, self.get_color()) libtcod.console_set_default_background(self.console, self.get_bk_color()) libtcod.console_print_frame(self.console, 0, 0, self.width, self.height, True, libtcod.BKGND_SET, self.id) temp = libtcod.console_new(self.width - 2, self.height - 2) y = 1 if not self.content: print 'fenetre vide' else: #TODO: redo this, exeptions self.content.build(temp) libtcod.console_blit(temp, 0, 0, self.content.width, self.content.height, self.console, 1, y)
def landed_loop(self, planet_index): self.current_screen = 'landed' done = False planet = self.sector.planets[planet_index] while not done: libtcod.sys_check_for_event(libtcod.KEY_PRESSED|libtcod.KEY_RELEASED|libtcod.EVENT_MOUSE, self.key, self.mouse) self.starfield.draw() self.nebula.draw() planet.render_detail() self.buffer.blit(self.console) libtcod.console_blit(self.console, 0, 0, self.screen_width, self.screen_height, 0, 0, 0) libtcod.console_print_frame(self.landing_console, 0, 0, self.landing_screen_width, self.landing_screen_height, clear=True, flag=libtcod.BKGND_SET, fmt=0) title = "[ Landed at {0} ]".format(planet.name) libtcod.console_print_ex(self.landing_console, (self.landing_screen_width/2) - (len(title)/2), 0, libtcod.BKGND_SET, libtcod.LEFT, title) libtcod.console_print_ex(self.landing_console, 2, 2, libtcod.BKGND_SET, libtcod.LEFT, "Class: {0}".format(planet.planet_class.title())) libtcod.console_print_ex(self.landing_console, 2, 3, libtcod.BKGND_SET, libtcod.LEFT, "Diameter: {0}".format(planet.width)) libtcod.console_print_ex(self.landing_console, 2, 4, libtcod.BKGND_SET, libtcod.LEFT, "Seed: {0}".format(planet.seed)) libtcod.console_blit(self.landing_console, 0, 0, self.landing_screen_width, self.landing_screen_height, 0, self.screen_width/2, 2, 1.0, 0.25) libtcod.console_flush() self.buffer.clear(self.sector.background[0], self.sector.background[1], self.sector.background[2]) player_action = self.handle_keys() if player_action == 1: self.add_message("Taking off from {0}".format(planet.name)) self.current_screen = 'flight' done = True
def message(new_msg, color=lt.white): new_msg_lines = textwrap.wrap(str(new_msg), MSG_WIDTH) for line in new_msg_lines: if len(game_msgs) == LOG_HEIGHT - 4: del game_msgs[0] game_msgs.append((line, color)) # Render message log. # A frame around the log lt.console_clear(log) lt.console_set_default_foreground(log, lt.lighter_grey) lt.console_print_frame(log, 0, 0, MAP_WIDTH, LOG_HEIGHT-2, False) # Message log rendering col = 1 for (line, color) in game_msgs: lt.console_set_default_foreground(log, color) lt.console_print_ex(log, 3, col, lt.BKGND_NONE, lt.LEFT, line) col += 1 lt.console_blit(log, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, MAP_HEIGHT + 2) lt.console_flush()
def build(self): #print 'built!' libtcod.console_set_default_foreground(self.console, self.get_color()) libtcod.console_set_default_background(self.console, self.get_bk_color()) libtcod.console_print_frame(self.console, 0, 0, self.width, self.height, True, libtcod.BKGND_SET, self.id) temp = libtcod.console_new(self.width - 2, self.height - 2) y = 1 if self.vertical: for elem in self.content: libtcod.console_clear(temp) elem.build(temp) height = elem.height libtcod.console_blit(temp, 0, 0, elem.width, elem.height, self.console, 1, y) y += height
def test_console_print_frame(console): libtcodpy.console_print_frame(console, 0, 0, 9, 9)
def render_all(self): if self.player_ship.velocity > 0.0: self.starfield.scroll( self.player_ship.velocity_angle, self.player_ship.velocity ) self.starfield.draw() self.sector.update_particle_positions() self.sector.scroll_particles( self.player_ship.velocity_angle, self.player_ship.velocity ) self.sector.update_visibility(self.player_ship.sector_position_x, self.player_ship.sector_position_y) self.nebula.draw() for planet in self.sector.planets: planet.draw() for asteroid in self.sector.asteroids: asteroid.draw() self.check_for_collisions() for particle in self.sector.particles: particle.draw() self.player_ship.draw() if self.sector.selected_planet is not None or self.sector.selected_asteroid is not None: self.sector.update_selected_planet_distance(self.player_ship) if self.sector.selected_planet_distance() > (self.screen_height/2.0): self.player_ship.draw_target_arrow(self.sector.selected_planet_angle) # self.sector.draw_target_arrow(self.player_ship) self.buffer.blit(self.console) libtcod.console_blit(self.console, 0, 0, self.screen_width, self.screen_height, 0, 0, 0) if self.sector.selected_planet is not None or self.sector.selected_asteroid is not None: # Target window planet = self.sector.get_selected_planet() planet.draw_target_picture(self.targeting_buffer, 4, 2) self.targeting_buffer.blit(self.targeting_console) libtcod.console_print_frame(self.targeting_console, 0, 0, self.targeting_width, self.targeting_height, clear=False, flag=libtcod.BKGND_SET, fmt=0) name = textwrap.wrap(" Name: {0}".format(planet.name), width=self.targeting_width-4) libtcod.console_print_ex(self.targeting_console, 1, 16, libtcod.BKGND_SET, libtcod.LEFT, "\n ".join(name)+"\n" ) planet_class = planet.planet_class.title() if planet.star_class: planet_class += " ({0})".format(planet.star_class) extra_info = "" if planet.star_temp: extra_info = "\n Temp: {0} K\n".format(planet.star_temp) elif planet.planet_class == 'asteroid': extra_info = "\n HP: {0} \n".format(planet.hp) libtcod.console_print_ex(self.targeting_console, 1, 17+len(name), libtcod.BKGND_SET, libtcod.LEFT, ( " Class: {0}\n{1}\n" " Distance: {2}\n" ).format( planet_class, extra_info, int(self.sector.selected_planet_distance()), ) ) libtcod.console_blit(self.targeting_console, 0, 0, self.targeting_width, self.targeting_height, 0, 0, 0, 1.0, 0.25) # Ship Info libtcod.console_print_frame(self.ship_info_console, 0, 0, self.ship_info_width, self.ship_info_height, clear=True, flag=libtcod.BKGND_SET, fmt=0) libtcod.console_print_ex(self.ship_info_console, 1, 1, libtcod.BKGND_SET, libtcod.LEFT, ( " Heading: {0}\n" " Velocity: {1}\n" " VelAngle: {2}\n" "Particles: {3}\n" "Ship\nSeed: {4}\n" # "Nebula Position:\n" # "l:{4} r:{5}\n" # "t:{6} b:{7}\n" ).format( round(math.degrees(self.player_ship.heading),2), round(self.player_ship.velocity,2), round(math.degrees(self.player_ship.velocity_angle),2), len(self.sector.particles), hex(self.player_ship.ship_value) # self.nebula.left, self.nebula.right, self.nebula.top, self.nebula.bottom ).ljust(self.ship_info_width-2) ) libtcod.console_blit(self.ship_info_console, 0, 0, self.ship_info_width, self.ship_info_height, 0, self.screen_width-self.ship_info_width, self.screen_height-self.ship_info_height-self.message_height, 1.0, 0.25) # Bottom Messages if len(self.messages) > 0: libtcod.console_print_ex(self.message_console, 0, 0, libtcod.BKGND_SET, libtcod.LEFT, "\n".join([message.ljust(self.message_width) for message in self.messages]) ) libtcod.console_blit(self.message_console, 0, 0, self.message_width, self.message_height, 0, 0, self.screen_height-self.message_height, 1.0, 0.25) # Minimap self.sector.draw_minimap(self.minimap_buffer, self.minimap_width, self.minimap_height, self.player_ship) self.minimap_buffer.blit(self.minimap_console) libtcod.console_print_frame(self.minimap_console, 0, 0, self.minimap_width, self.minimap_height, clear=False, flag=libtcod.BKGND_SET, fmt=0) libtcod.console_print_ex(self.minimap_console, 1, self.minimap_height-1, libtcod.BKGND_SET, libtcod.LEFT, ("[ {0} {1} ]").format( int(self.player_ship.sector_position_x), int(self.player_ship.sector_position_y), ).center(self.minimap_width-2, chr(196)) ) libtcod.console_blit(self.minimap_console, 0, 0, self.minimap_width, self.minimap_height, 0, self.screen_width-self.minimap_width, 0, 1.0, 0.25) libtcod.console_flush() self.buffer.clear(self.sector.background[0], self.sector.background[1], self.sector.background[2])
def get_player_tooltip(animation_console, x, y, mouse, screen_width, screen_height): libtcod.console_set_default_background(animation_console, (0, 0, 0)) if (x, y) in [(6, 10), (7, 10), (8, 10), (9, 10), (10, 10), (11, 10), (12, 10), (13, 10), (14, 10), (15, 10), (16, 10)]: libtcod.console_print_frame(animation_console, x + 1, y + 1, 30, 13, 5, False, 'SP는 인간성을 유지할 수 있게 하는 ') libtcod.console_print_frame(animation_console, x + 1, y + 2, 30, 13, 13, False, '정신적인 힘입니다. 0이 되면 죽습니다. ') libtcod.console_print_frame(animation_console, x + 1, y + 3, 30, 13, 13, False, '얻음:오락,음식,종교물,귀중품,선행,시체에서 흡수 ') libtcod.console_print_frame(animation_console, x + 1, y + 4, 30, 13, 13, False, '잃음:마법/전투기술 시전, 탐험하며 천천히 ') if (x, y) in [(6, 11), (7, 11), (8, 11), (9, 11), (10, 11), (11, 11), (12, 11), (13, 11), (14, 11), (15, 11), (16, 11)]: libtcod.console_print_frame(animation_console, x + 1, y + 1, 20, 13, 5, False, 'DT는 캐릭터에게 가해지는 피해량을') libtcod.console_print_frame(animation_console, x + 1, y + 2, 20, 13, 13, False, '고정된 수치만큼 감소시킵니다. ') elif (x, y) in [(6, 12), (7, 12), (8, 12), (9, 12), (10, 12), (11, 12), (12, 12), (13, 12), (14, 12), (15, 12), (16, 12)]: libtcod.console_print_frame(animation_console, x + 1, y + 1, 20, 13, 5, False, 'AC는 얼마나 적의 공격을 얼마나') libtcod.console_print_frame(animation_console, x + 1, y + 2, 20, 13, 13, False, '잘 피할 수 있는지를 말합니다. ') libtcod.console_print_frame(animation_console, x + 1, y + 3, 20, 13, 13, False, '기본 수치는 10+민첩입니다. ') elif (x, y) in [(6, 13), (7, 13), (8, 13), (9, 13), (10, 13), (11, 13), (12, 13), (13, 13), (14, 13), (15, 13), (16, 13)]: libtcod.console_print_frame(animation_console, x + 1, y + 1, 20, 13, 5, False, '인내 방어는 독,몸싸움,감염 등의') libtcod.console_print_frame(animation_console, x + 1, y + 2, 20, 13, 13, False, '난관들을 신체적인 강인함으로 ') libtcod.console_print_frame(animation_console, x + 1, y + 3, 20, 13, 13, False, '극복할 수 있는 정도를 말합니다. ') libtcod.console_print_frame(animation_console, x + 1, y + 4, 20, 13, 13, False, '기본 수치는 (힘+건강)/2입니다.') elif (x, y) in [(6, 14), (7, 14), (8, 14), (9, 14), (10, 14), (11, 14), (12, 14), (13, 14), (14, 14), (15, 14), (16, 14)]: libtcod.console_print_frame(animation_console, x + 1, y + 1, 21, 13, 5, False, '반사 신경은 폭발 등의 공격 ') libtcod.console_print_frame(animation_console, x + 1, y + 2, 21, 13, 13, False, '들을 빠른 발걸음과 반응속도로 ') libtcod.console_print_frame(animation_console, x + 1, y + 3, 21, 13, 13, False, '회피할 수 있는 정도를 말합니다. ') libtcod.console_print_frame(animation_console, x + 1, y + 4, 21, 13, 13, False, '기본 수치는 (민첩+건강)/2입니다.') elif (x, y) in [(6, 15), (7, 15), (8, 15), (9, 15), (10, 15), (11, 15), (12, 15), (13, 15), (14, 15), (15, 15), (16, 15)]: libtcod.console_print_frame(animation_console, x + 1, y + 1, 21, 13, 5, False, '의지 방어는 캐릭터에게 부정적인 ') libtcod.console_print_frame(animation_console, x + 1, y + 2, 21, 13, 13, False, '영향을 끼치는 마법들을 저항할 ') libtcod.console_print_frame(animation_console, x + 1, y + 3, 21, 13, 13, False, '수 있는 정도를 말합니다. ') libtcod.console_print_frame(animation_console, x + 1, y + 4, 21, 13, 13, False, '기본 수치는 (지능+건강)/2입니다.') libtcod.console_blit(animation_console, 0, 0, screen_width, screen_height, 0, 0, 0) libtcod.console_flush() if mouse.dcx != 0 or mouse.dcy != 0 or mouse.dcx != 0 and mouse.dcy != 0: libtcod.console_clear(animation_console) if handle_mouse(mouse).get('left_click'): left_click = (x, y) return left_click sleep(0.3) libtcod.console_clear(animation_console)
def render_all(): if glob.fov_recompute: glob.fov_recompute = False libtcod.map_compute_fov(fov_map, player.x, player.y, const.TORCH_RADIUS, const.FOV_LIGHT_WALLS, const.FOV_ALGO) for y in range(const.MAP_HEIGHT): for x in range(const.MAP_WIDTH): visible = libtcod.map_is_in_fov(fov_map, x, y) wall = glob.map[x][y].block_sight if not visible: #If out of FOV if glob.map[x][y].explored: if wall: libtcod.console_put_char_ex( view, x, y, '#', const.colour_dark_wall, const.colour_background) else: libtcod.console_put_char_ex( view, x, y, '.', const.colour_dark_ground, const.colour_background) else: #If visible if wall: libtcod.console_put_char_ex(view, x, y, '#', const.colour_light_wall, const.colour_background) else: libtcod.console_put_char_ex(view, x, y, '.', const.colour_light_ground, const.colour_background) glob.map[x][y].explored = True for object in glob.objects: if object != player: object.draw() player.draw() libtcod.console_blit(view, 0, 0, const.SCREEN_WIDTH, const.SCREEN_HEIGHT, 0, 0, 0) #Panel libtcod.console_set_default_background(panel, const.colour_background) libtcod.console_clear(panel) #Log y = 1 for (line, colour) in glob.game_msgs: libtcod.console_set_default_foreground(panel, colour) libtcod.console_print_ex(panel, const.MSG_X, y, libtcod.BKGND_NONE, libtcod.LEFT, line) y += 1 #GUI render_bar(1, 1, const.BAR_WIDTH, 'HP', player.creature.hp, player.creature.max_hp, libtcod.dark_red, libtcod.darker_red) render_bar(1, 2, const.BAR_WIDTH, 'EP', player.creature.ep, player.creature.max_ep, libtcod.dark_blue, libtcod.darker_blue) libtcod.console_set_default_foreground(panel, libtcod.light_gray) libtcod.console_print_ex(panel, 1, 5, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse()) #Outlines libtcod.console_print_frame(panel, 0, 0, const.SCREEN_WIDTH, const.PANEL_HEIGHT, clear=False, flag=libtcod.BKGND_NONE) #Blit that puppy! libtcod.console_blit(panel, 0, 0, const.SCREEN_WIDTH, const.PANEL_HEIGHT, 0, 0, const.PANEL_Y)
def test_console_printing_advanced(console): libtcodpy.console_rect(console, 0, 0, 4, 4, False, libtcodpy.BKGND_SET) libtcodpy.console_hline(console, 0, 0, 4) libtcodpy.console_vline(console, 0, 0, 4) libtcodpy.console_print_frame(console, 0, 0, 11, 11)
def skill_tree(): key = libtcod.Key() mouse = libtcod.Mouse() # calculate total height for the header (after auto-wrap) and one line per option width = Constants.MAP_CONSOLE_WIDTH height = Constants.MAP_CONSOLE_HEIGHT st = libtcod.console_new(width, height) # print the header, with auto-wrap libtcod.console_set_default_foreground(st, Constants.UI_PopFore) libtcod.console_set_default_background(st, Constants.UI_PopBack) libtcod.console_print_frame(st, 0, 0, width, height, clear=True, flag=libtcod.BKGND_SET, fmt="Skill Tree") Render.print_rect(st, 4, 4, width, height, 'Insert Skill Tree') # blit the contents of "window" to the root console x = 0 y = 0 file = open('Assets\skill_tree.map', 'r') # fill map with "blocked" tiles #kills = [[' ' for y in range(Constants.MAP_CONSOLE_HEIGHT)] for x in range(Constants.MAP_CONSOLE_WIDTH)] skills = [[Skill(' ') for y in range(Constants.MAP_HEIGHT)] for x in range(Constants.MAP_WIDTH)] selected_x = 0 selected_y = 0 for y in range(Constants.MAP_CONSOLE_HEIGHT): line = file.readline() # print line x = 0 for c in line: if c == 'S': selected_x = x selected_y = y skills[x][y] = Skill(c, True) else: skills[x][y] = Skill(c) x += 1 # print selected_x, selected_y button_text = 'Exit' ct_button = Button(button_text, width / 2, height - 3, length=6, function=close_window) while True: libtcod.console_flush() libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if key.vk == libtcod.KEY_LEFT: if skills[selected_x-1][selected_y].char == "-": selected_x -= 2 elif key.vk == libtcod.KEY_RIGHT: if skills[selected_x + 1][selected_y].char == "-": selected_x += 2 elif key.vk == libtcod.KEY_UP: if skills[selected_x][selected_y-1].char == "|": selected_y -= 2 elif key.vk == libtcod.KEY_DOWN: if skills[selected_x ][selected_y+1].char == "|": selected_y += 2 elif key.vk == libtcod.KEY_SPACE: skills[selected_x][selected_y].purchased = True if selected_y < 0: selected_y = 0 if selected_x < 0: selected_x = 0 offset = 20, 10 for y in range(Constants.MAP_CONSOLE_HEIGHT): for x in range(Constants.MAP_CONSOLE_WIDTH): # print skills if selected_x == x and selected_y == y: color = Color('purple') else: if skills[x][y].purchased: color = Color('green') else: color = Color('white') char = skills[x][y].char if char == "|": Render.draw_char(st, x + x + offset[0], y + y + offset[1], libtcod.CHAR_VLINE, libtcod.white, Constants.UI_PopBack) elif char == "-": Render.draw_char(st, x + x + offset[0], y + y + offset[1], libtcod.CHAR_HLINE, libtcod.white, Constants.UI_PopBack) elif char == ".": if color == Color('purple'): Render.draw_char(st, x + x + offset[0] + 1, y + y + offset[1] - 1, libtcod.CHAR_DNE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0], y + y + offset[1] - 1, libtcod.CHAR_DHLINE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] - 1, y + y + offset[1] - 1, libtcod.CHAR_DNW, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] - 1, y + y + offset[1], libtcod.CHAR_DVLINE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] + 1, y + y + offset[1], libtcod.CHAR_DVLINE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] + 1, y + y + offset[1] + 1, libtcod.CHAR_DSE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0], y + y + offset[1] + 1, libtcod.CHAR_DHLINE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] - 1, y + y + offset[1] + 1, libtcod.CHAR_DSW, color, Constants.UI_PopBack) else: Render.draw_char(st, x + x + offset[0] + 1, y + y + offset[1] - 1, ' ', color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0], y + y + offset[1] - 1, ' ', color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] - 1, y + y + offset[1] - 1, ' ', color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] - 1, y + y + offset[1], ' ', color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] + 1, y + y + offset[1], ' ', color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] + 1, y + y + offset[1] + 1, ' ', color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0], y + y + offset[1] + 1, ' ', color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] - 1, y + y + offset[1] + 1, ' ', color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0], y + y + offset[1], chr(4), libtcod.white, Constants.UI_PopBack) elif char != ' ' and char != chr(10): Render.draw_char(st, x + x + offset[0] + 1, y + y + offset[1] - 1, libtcod.CHAR_DNE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0], y + y + offset[1] - 1, libtcod.CHAR_DHLINE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] - 1, y + y + offset[1] - 1, libtcod.CHAR_DNW, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] - 1, y + y + offset[1], libtcod.CHAR_DVLINE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0], y + y + offset[1], char, libtcod.red, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] + 1, y + y + offset[1], libtcod.CHAR_DVLINE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] + 1, y + y + offset[1] + 1, libtcod.CHAR_DSE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0], y + y + offset[1] + 1, libtcod.CHAR_DHLINE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] - 1, y + y + offset[1] + 1, libtcod.CHAR_DSW, color, Constants.UI_PopBack) if ct_button.draw(x, y) == 'close': return libtcod.console_blit(st, 0, 0, width, height, 0, 0, 0, 1.0, 1.0)
def beastiary(width=10, height=10, title=None, text=None): # calculate total height for the header (after auto-wrap) and one line per option if width is None: width = Constants.MAP_CONSOLE_WIDTH - 10 if height is None: height = libtcod.console_get_height_rect(0, 0, 0, width, Constants.SCREEN_HEIGHT, text) + 7 pop = libtcod.console_new(width, height) # print the header, with auto-wrap libtcod.console_set_default_foreground(pop, Constants.UI_PopFore) libtcod.console_set_default_background(pop, Constants.UI_PopBack) libtcod.console_print_frame(pop, 0, 0, width, height, clear=True, flag=libtcod.BKGND_SET, fmt=title) # blit the contents of "window" to the root console x = 0 y = 0 button_text = 'Click to Continue' button = Button(button_text, width / 2, height - 3, function=close_window) img = libtcod.image_load('Images//cipher_warden_80x80_test_01.png') libtcod.image_set_key_color(img, Color(0, 0, 0)) # show the background image, at twice the regular console resolution libtcod.image_blit_2x(img, pop, 9, 2) libtcod.console_set_default_foreground(pop, Constants.UI_PopFore) libtcod.console_set_default_background(pop, Constants.UI_PopBack) Render.print_rect(pop, 3, 3, width - 6, height, text) background = libtcod.console_new(Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT) libtcod.console_blit(0, 0, 0, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT, background, 0, 0, 1.0, 1.0) dragging = False click_x = None while True: Input.update() mouse = Input.mouse Render.blit(background, 0) # libtcod.console_blit(background, 0, 0, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT, 0, 0, 0, 1.0, 1.0) libtcod.console_blit(pop, 0, 0, width, height, 0, x, y, 1.0, .85) if mouse.lbutton and x <= mouse.cx <= x + width and (mouse.cy == y or dragging): if click_x is None: click_x = mouse.cx - x x = mouse.cx - click_x # (width / 2) y = mouse.cy dragging = True else: dragging = False click_x = None if button.draw(x, y) == 'close': return libtcod.console_flush()
def play_arena(ui_con): console_buffer = tcod.ConsoleBuffer(constant.SCREEN_WIDTH, constant.SCREEN_HEIGHT) map_size = (constant.SCREEN_WIDTH * 1, constant.SCREEN_HEIGHT * 1) the_map = game_map.make_map(*map_size) fov_map = tcod.map_new(*map_size) player = entity.Entity(map_size[0] / 2, map_size[1] / 2, "@", tcod.black) player.inventory_component = item.Inventory(player, constant.INENTORY_SIZE[0], constant.INENTORY_SIZE[1], constant.WEIGHT_LIMIT) blah = "Makarov PM" test_makarov = item.Item(blah, item_types.firearms[blah][-1]) test_makarov.gun_component = item.Gun(test_makarov, *item_types.firearms[blah][:-1]) makarov_entity = entity.Entity(map_size[0] / 2 + 1, map_size[1] / 2 + 1, "]", tcod.dark_grey, item_component=test_makarov, is_walkable=True) entity_list = [player, makarov_entity] camera_x, camera_y = (player.x, player.y) fov_map = fov.update_fov_map(the_map, fov_map) tcod.map_compute_fov(fov_map, player.x, player.y, constant.VISION_RANGE, True, tcod.FOV_BASIC) fov_recompute = True in_menu = False selected_inv_square = None test = tcod.image_load(os.path.join("images", "weapons", "Makarov PM.png")) tcod.image_set_key_color(test, tcod.pink) # Set initial values for key and mouse event; required to pass into sys_check_for_event key = tcod.console_check_for_keypress(tcod.KEY_PRESSED) mouse_status = tcod.mouse_get_status() while True: # Get input tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key, mouse_status) if not in_menu: # Update camera. This must be done before rendering (center_x, center_y) = geometry.get_point_ahead(player.x, player.y, mouse_status.cx + camera_x, mouse_status.cy + camera_y, constant.CAMERA_DISTANCE) (camera_x, camera_y) = geometry.update_camera(center_x, center_y, the_map.width, the_map.height) player_facing_point = (mouse_status.cx, mouse_status.cy) # Update FOV if fov_recompute: tcod.map_compute_fov(fov_map, player.x, player.y, constant.VISION_RANGE, True, tcod.FOV_BASIC) fov.update_entity_fov(entity_list, the_map, fov_map) # Render the map and entities the_map.render(console_buffer, fov_map, camera_x, camera_y, player.x, player.y, *player_facing_point) console_buffer.blit(0) # Only entities in the player's line of sight should be drawn for _entity in reversed(entity_list): if fov.in_player_fov(_entity.x, _entity.y, player.x, player.y, mouse_status.cx + camera_x, mouse_status.cy + camera_y, fov_map): _entity.render(0, camera_x, camera_y) # fps display tcod.console_print_ex(0, constant.SCREEN_WIDTH - 1, 0, tcod.BKGND_NONE, tcod.RIGHT, str(tcod.sys_get_fps())) # If in inventory, draw inventory grid if in_menu == "inventory": tcod.mouse_show_cursor(True) tcod.console_clear(ui_con) ui.draw_checkerboard(ui_con, constant.INENTORY_SIZE[0], constant.INENTORY_SIZE[1], constant.SQUARE_SIZE, tcod.grey, tcod.dark_grey) ui.draw_inventory_items(ui_con, player.inventory_component) if selected_inv_square is not None: tcod.console_print_frame(ui_con, selected_inv_square[0] * constant.SQUARE_SIZE, selected_inv_square[1] * constant.SQUARE_SIZE, constant.SQUARE_SIZE, constant.SQUARE_SIZE, False, tcod.BKGND_NONE, False) tcod.console_blit(ui_con, 0, 0, constant.INENTORY_SIZE[0] * constant.SQUARE_SIZE, constant.INENTORY_SIZE[1] * constant.SQUARE_SIZE, 0, constant.INVENTORY_X, constant.INVENTORY_Y) tcod.console_flush() fov_recompute = False # Handle input if not in_menu: if key.vk == tcod.KEY_LEFT: # Move left if not entity.check_collision(player.x - 1, player.y, the_map, entity_list): player.x -= 0 if player.x == 0 else 1 fov_recompute = True elif key.vk == tcod.KEY_RIGHT: # Move right if not entity.check_collision(player.x + 1, player.y, the_map, entity_list): player.x += 0 if player.x == the_map.width else 1 fov_recompute = True elif key.vk == tcod.KEY_UP: # Move up if not entity.check_collision(player.x, player.y - 1, the_map, entity_list): player.y -= 0 if player.y == 0 else 1 fov_recompute = True elif key.vk == tcod.KEY_DOWN: # Move down if not entity.check_collision(player.x, player.y + 1, the_map, entity_list): player.y += 0 if player.y == the_map.height else 1 fov_recompute = True elif key.c == ord("i"): in_menu = "inventory" elif key.c == ord(","): for _entity in entity_list: if (_entity.item_component is not None and _entity.x == player.x and _entity.y == player.y): player.inventory_component.add(_entity.item_component) entity_list.remove(_entity) elif key.vk == tcod.KEY_ESCAPE: # Quit back to main menu break elif in_menu == "inventory": if mouse_status.lbutton_pressed: prev_square = selected_inv_square selected_inv_square = ((mouse_status.cx - constant.INVENTORY_X) / constant.SQUARE_SIZE, (mouse_status.cy - constant.INVENTORY_Y) / constant.SQUARE_SIZE) if selected_inv_square == prev_square: selected_inv_square = None elif not ((0 <= selected_inv_square[0] < constant.INENTORY_SIZE[0]) and (0 <= selected_inv_square[1] < constant.INENTORY_SIZE[1])): selected_inv_square = prev_square elif key.c == ord("i"): tcod.mouse_show_cursor(False) in_menu = ""
def skill_tree(): key = libtcod.Key() mouse = libtcod.Mouse() # calculate total height for the header (after auto-wrap) and one line per option width = Constants.MAP_CONSOLE_WIDTH height = Constants.MAP_CONSOLE_HEIGHT st = libtcod.console_new(width, height) # print the header, with auto-wrap libtcod.console_set_default_foreground(st, Constants.UI_PopFore) libtcod.console_set_default_background(st, Constants.UI_PopBack) libtcod.console_print_frame(st, 0, 0, width, height, clear=True, flag=libtcod.BKGND_SET, fmt="Skill Tree") Render.print_rect(st, 4, 4, width, height, 'Insert Skill Tree') # blit the contents of "window" to the root console x = 0 y = 0 file = open('Assets\skill_tree.map', 'r') # fill map with "blocked" tiles #kills = [[' ' for y in range(Constants.MAP_CONSOLE_HEIGHT)] for x in range(Constants.MAP_CONSOLE_WIDTH)] skills = [[Skill(' ') for y in range(Constants.MAP_HEIGHT)] for x in range(Constants.MAP_WIDTH)] selected_x = 0 selected_y = 0 for y in range(Constants.MAP_CONSOLE_HEIGHT): line = file.readline() # print line x = 0 for c in line: if c == 'S': selected_x = x selected_y = y skills[x][y] = Skill(c, True) else: skills[x][y] = Skill(c) x += 1 # print selected_x, selected_y button_text = 'Exit' ct_button = Button(button_text, width / 2, height - 3, length=6, function=close_window) while True: libtcod.console_flush() libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if key.vk == libtcod.KEY_LEFT: if skills[selected_x - 1][selected_y].char == "-": selected_x -= 2 elif key.vk == libtcod.KEY_RIGHT: if skills[selected_x + 1][selected_y].char == "-": selected_x += 2 elif key.vk == libtcod.KEY_UP: if skills[selected_x][selected_y - 1].char == "|": selected_y -= 2 elif key.vk == libtcod.KEY_DOWN: if skills[selected_x][selected_y + 1].char == "|": selected_y += 2 elif key.vk == libtcod.KEY_SPACE: skills[selected_x][selected_y].purchased = True if selected_y < 0: selected_y = 0 if selected_x < 0: selected_x = 0 offset = 20, 10 for y in range(Constants.MAP_CONSOLE_HEIGHT): for x in range(Constants.MAP_CONSOLE_WIDTH): # print skills if selected_x == x and selected_y == y: color = Color('purple') else: if skills[x][y].purchased: color = Color('green') else: color = Color('white') char = skills[x][y].char if char == "|": Render.draw_char(st, x + x + offset[0], y + y + offset[1], libtcod.CHAR_VLINE, libtcod.white, Constants.UI_PopBack) elif char == "-": Render.draw_char(st, x + x + offset[0], y + y + offset[1], libtcod.CHAR_HLINE, libtcod.white, Constants.UI_PopBack) elif char == ".": if color == Color('purple'): Render.draw_char(st, x + x + offset[0] + 1, y + y + offset[1] - 1, libtcod.CHAR_DNE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0], y + y + offset[1] - 1, libtcod.CHAR_DHLINE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] - 1, y + y + offset[1] - 1, libtcod.CHAR_DNW, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] - 1, y + y + offset[1], libtcod.CHAR_DVLINE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] + 1, y + y + offset[1], libtcod.CHAR_DVLINE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] + 1, y + y + offset[1] + 1, libtcod.CHAR_DSE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0], y + y + offset[1] + 1, libtcod.CHAR_DHLINE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] - 1, y + y + offset[1] + 1, libtcod.CHAR_DSW, color, Constants.UI_PopBack) else: Render.draw_char(st, x + x + offset[0] + 1, y + y + offset[1] - 1, ' ', color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0], y + y + offset[1] - 1, ' ', color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] - 1, y + y + offset[1] - 1, ' ', color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] - 1, y + y + offset[1], ' ', color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] + 1, y + y + offset[1], ' ', color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] + 1, y + y + offset[1] + 1, ' ', color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0], y + y + offset[1] + 1, ' ', color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] - 1, y + y + offset[1] + 1, ' ', color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0], y + y + offset[1], chr(4), libtcod.white, Constants.UI_PopBack) elif char != ' ' and char != chr(10): Render.draw_char(st, x + x + offset[0] + 1, y + y + offset[1] - 1, libtcod.CHAR_DNE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0], y + y + offset[1] - 1, libtcod.CHAR_DHLINE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] - 1, y + y + offset[1] - 1, libtcod.CHAR_DNW, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] - 1, y + y + offset[1], libtcod.CHAR_DVLINE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0], y + y + offset[1], char, libtcod.red, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] + 1, y + y + offset[1], libtcod.CHAR_DVLINE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] + 1, y + y + offset[1] + 1, libtcod.CHAR_DSE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0], y + y + offset[1] + 1, libtcod.CHAR_DHLINE, color, Constants.UI_PopBack) Render.draw_char(st, x + x + offset[0] - 1, y + y + offset[1] + 1, libtcod.CHAR_DSW, color, Constants.UI_PopBack) if ct_button.draw(x, y) == 'close': return libtcod.console_blit(st, 0, 0, width, height, 0, 0, 0, 1.0, 1.0)
def beastiary(width=10, height=10, title=None, text=None): # calculate total height for the header (after auto-wrap) and one line per option if width is None: width = Constants.MAP_CONSOLE_WIDTH - 10 if height is None: height = libtcod.console_get_height_rect( 0, 0, 0, width, Constants.SCREEN_HEIGHT, text) + 7 pop = libtcod.console_new(width, height) # print the header, with auto-wrap libtcod.console_set_default_foreground(pop, Constants.UI_PopFore) libtcod.console_set_default_background(pop, Constants.UI_PopBack) libtcod.console_print_frame(pop, 0, 0, width, height, clear=True, flag=libtcod.BKGND_SET, fmt=title) # blit the contents of "window" to the root console x = 0 y = 0 button_text = 'Click to Continue' button = Button(button_text, width / 2, height - 3, function=close_window) img = libtcod.image_load('Images//cipher_warden_80x80_test_01.png') libtcod.image_set_key_color(img, Color(0, 0, 0)) # show the background image, at twice the regular console resolution libtcod.image_blit_2x(img, pop, 9, 2) libtcod.console_set_default_foreground(pop, Constants.UI_PopFore) libtcod.console_set_default_background(pop, Constants.UI_PopBack) Render.print_rect(pop, 3, 3, width - 6, height, text) background = libtcod.console_new(Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT) libtcod.console_blit(0, 0, 0, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT, background, 0, 0, 1.0, 1.0) dragging = False click_x = None while True: Input.update() mouse = Input.mouse Render.blit(background, 0) # libtcod.console_blit(background, 0, 0, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT, 0, 0, 0, 1.0, 1.0) libtcod.console_blit(pop, 0, 0, width, height, 0, x, y, 1.0, .85) if mouse.lbutton and x <= mouse.cx <= x + width and (mouse.cy == y or dragging): if click_x is None: click_x = mouse.cx - x x = mouse.cx - click_x # (width / 2) y = mouse.cy dragging = True else: dragging = False click_x = None if button.draw(x, y) == 'close': return libtcod.console_flush()
libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'Roguelike', False) playerx = SCREEN_WIDTH // 2 playery = SCREEN_HEIGHT // 2 floaterX = 10 floaterY = 10 while not libtcod.console_is_window_closed(): floaterX -= 1 floaterY -= 1 libtcod.console_print_frame(0, 0, 0, SCREEN_WIDTH - 20, SCREEN_HEIGHT, True, fmt="Local") libtcod.console_print_frame(0, SCREEN_WIDTH - 20, 0, 20, 20, True, fmt="Global") libtcod.console_print_frame(0, SCREEN_WIDTH - 20, 20, 20, SCREEN_HEIGHT - 20,
def console_print_frame(self,con,x,y,width,height,clear): if con == 0: libtcod.console_print_frame(con,x,y,width,height,clear) else: libtcod.console_print_frame(self.mConsole[con-1],x,y,width,height,clear)
def clear(self): libtcodpy.console_clear(self._panel) if self.border: libtcodpy.console_print_frame(self._panel, 0, 0, self.panelwidth, self.panelheight)
def drawGUI(): # Handles drawing of all GUI. # Draw stats. libtcod.console_set_default_foreground(bottomGuiConsole, libtcod.white) libtcod.console_print_ex(bottomGuiConsole, 2, 4, libtcod.BKGND_NONE, libtcod.CENTER, "D:"+str(calculateDamage(player))) libtcod.console_print_ex(bottomGuiConsole, 2, 5, libtcod.BKGND_NONE, libtcod.CENTER, "S:"+str(calculateSpeed(player))) # Draw player's name and health/energy bars to screen. libtcod.console_set_default_foreground(bottomGuiConsole, libtcod.white) libtcod.console_print_ex(bottomGuiConsole, int((barWidth+10)/2), 2, libtcod.BKGND_NONE, libtcod.CENTER, player.name) createBar(bottomGuiConsole, 5, 4, barWidth, player.alive.hp, player.alive.maxHP, libtcod.darkest_green, libtcod.dark_green, "") createBar(bottomGuiConsole, 5, 5, barWidth, player.alive.eng, player.alive.maxENG, libtcod.darkest_blue, libtcod.dark_blue, "") # Draw floor and step counters and name of area.. libtcod.console_set_default_foreground(topGuiConsole, libtcod.white) libtcod.console_print_ex(topGuiConsole, 6, 1, libtcod.BKGND_NONE, libtcod.CENTER, "Castle ") libtcod.console_print_ex(topGuiConsole, 16, 1, libtcod.BKGND_NONE, libtcod.CENTER, "Floor: "+str(floor)) libtcod.console_print_ex(topGuiConsole, 27, 1, libtcod.BKGND_NONE, libtcod.CENTER, "Turns: "+str(turns)) # Draw messages to gui. y = 2 msgNum = 0 for msg in messages: if msgNum+len(msg[0]) == msgLength: libtcod.console_set_default_foreground(bottomGuiConsole, libtcod.Color(*msg[1])) else: libtcod.console_set_default_foreground(bottomGuiConsole, libtcod.Color(*msg[2])) if len(msg[0]) > 1: for line in msg[0]: libtcod.console_print_ex(bottomGuiConsole, messageX, y, libtcod.BKGND_NONE, libtcod.LEFT, line) y += 1 else: libtcod.console_print_ex(bottomGuiConsole, messageX, y, libtcod.BKGND_NONE, libtcod.LEFT, msg[0][0]) y += 1 msgNum += len(msg[0]) # Displays name of object focused by player. focused = getUnderMouse() if focused is not None: if focused.alive: libtcod.console_set_default_foreground(bottomGuiConsole, libtcod.light_red) libtcod.console_print_ex(bottomGuiConsole, screenWidth-int((barWidth+10)/2), 2, libtcod.BKGND_NONE, libtcod.CENTER, focused.name) # health/energy bars when the object focused has hp. if focused.alive.hp > 0 and focused != player: # Makes the health/energy bars look better with odd lengthed names. nameX = 0 if len(focused.name) % 2: nameX = 1 createBar(bottomGuiConsole, 95-barWidth, 4, barWidth+nameX, focused.alive.hp, focused.alive.maxHP, libtcod.darkest_green, libtcod.dark_green, "") createBar(bottomGuiConsole, 95-barWidth, 5, barWidth+nameX, focused.alive.eng, focused.alive.maxENG, libtcod.darkest_blue, libtcod.dark_blue, "") elif focused.item: libtcod.console_set_default_foreground(bottomGuiConsole, libtcod.Color(*itemConfig[focused.name]["inViewColor"])) libtcod.console_print_ex(bottomGuiConsole, screenWidth-int((barWidth+10)/2), 2, libtcod.BKGND_NONE, libtcod.CENTER, focused.name) elif not actionMenu[0] and gameState == "ACTIVE": libtcod.console_set_default_foreground(bottomGuiConsole, libtcod.Color(*tileConfig[focused.image]["inViewColor"])) libtcod.console_print_ex(bottomGuiConsole, screenWidth-int((barWidth+10)/2), 2, libtcod.BKGND_NONE, libtcod.CENTER, focused.name) # Draw action menu if activated. if actionMenu[0]: libtcod.console_set_default_foreground(mapConsole, libtcod.white) libtcod.console_print_frame(mapConsole, actionMenu[3], actionMenu[4], actionWidth, actionHeight, True, libtcod.BKGND_DEFAULT, b"Action") # Draw inventory window if activated. if gameState == "INVENTORY": # Inventory window. libtcod.console_set_default_foreground(mapConsole, libtcod.white) libtcod.console_print_frame(mapConsole, int(mapWidth/4), int(mapHeight/5), 35, 35, True, libtcod.BKGND_DEFAULT, b"Inventory") y = 2 for item in player.alive.inventory: libtcod.console_set_default_foreground(mapConsole, libtcod.white) libtcod.console_print_ex(mapConsole, int(mapWidth/4)+2, int(mapHeight/5)+y, libtcod.BKGND_NONE, libtcod.LEFT, item.name) if item.item.equippable: if not item.item.equipped: widgets[y].text = b"Equip" else: widgets[y].text = b"Unequip" y += 1 # Equipment window. libtcod.console_set_default_foreground(mapConsole, libtcod.white) libtcod.console_print_frame(mapConsole, int(mapWidth/4)+35, int(mapHeight/5), 20, 35, True, libtcod.BKGND_DEFAULT, b"Equipment") y = 2 for key in sorted(player.alive.equipment.keys()): libtcod.console_set_default_foreground(mapConsole, libtcod.gold) libtcod.console_print_ex(mapConsole, int(mapWidth/3)+37, int(mapHeight/5)+y, libtcod.BKGND_NONE, libtcod.CENTER, key) libtcod.console_set_default_foreground(mapConsole, libtcod.white) if player.alive.equipment[key] != "": libtcod.console_print_ex(mapConsole, int(mapWidth/3)+37, int(mapHeight/5)+y+2, libtcod.BKGND_NONE, libtcod.CENTER, player.alive.equipment[key].name) y += 4 # Draw journel window if activated. if gameState == "JOURNEL": libtcod.console_set_default_foreground(mapConsole, libtcod.white) libtcod.console_print_frame(mapConsole, int(mapWidth/2.5), int(mapHeight/4), 25, 25, True, libtcod.BKGND_DEFAULT, b"Journel") # Draw message history window if activated. if gameState == "MSGHISTORY": libtcod.console_set_default_foreground(mapConsole, libtcod.white) libtcod.console_print_frame(mapConsole, messageX, 1, 55, mapHeight-1, True, libtcod.BKGND_DEFAULT, b"Message History") # Draw messages to gui. y = 2 msgNum = 0 for msg in msgHistory: if msgNum+len(msg[0]) == msgLength: libtcod.console_set_default_foreground(mapConsole, libtcod.Color(*msg[1])) else: libtcod.console_set_default_foreground(mapConsole, libtcod.Color(*msg[2])) if len(msg[0]) > 1: for line in msg[0]: libtcod.console_print_ex(mapConsole, messageX+1, 1+y, libtcod.BKGND_NONE, libtcod.LEFT, line) y += 1 else: libtcod.console_print_ex(mapConsole, messageX+1, 1+y, libtcod.BKGND_NONE, libtcod.LEFT, msg[0][0]) y += 1 msgNum += len(msg[0]) y += 1 # Draw widgets. for widget in widgets: widget.draw()
def rect(self, x, y, w, h, clear, flag=libtcodpy.BKGND_DEFAULT): libtcodpy.console_print_frame(self._panel, x, y, w, h, clear, flag)
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): fov_recompute = True center_x = int(screen_width / 2) center_y = int(screen_height / 2) camera_x = player.x camera_y = player.y top_left_x = camera_x - center_x top_left_y = camera_y - center_y #Draw tiles if fov_recompute: libtcod.console_clear(con) for y in range(screen_height - panel_height): tile_y = y + top_left_y for x in range(screen_width): tile_x = x + top_left_x if tile_x >= game_map.width - 1: tile_x = game_map.width - 1 if tile_y >= game_map.height: tile_y = game_map.height - 1 if tile_x < 0: tile_x = 0 if tile_y < 0: tile_y = 0 tile = game_map.tiles[tile_x][tile_y] visible = libtcod.map_is_in_fov(fov_map, tile_x, tile_y) name = str(game_map.theme) wall = tile.block_sight if visible: if wall: libtcod.console_put_char_ex( con, x, y, colors.get(name + '_light_wall')[0], colors.get(name + '_light_wall')[1], colors.get(name + '_light_wall')[2]) else: libtcod.console_put_char_ex( con, x, y, colors.get(name + '_light_ground')[0], colors.get(name + '_light_ground')[1], colors.get(name + '_light_ground')[2]) tile.explored = True elif tile.explored: if wall: libtcod.console_put_char_ex( con, x, y, colors.get(name + '_dark_wall')[0], colors.get(name + '_dark_wall')[1], colors.get(name + '_dark_wall')[2]) else: libtcod.console_put_char_ex( con, x, y, colors.get(name + '_dark_ground')[0], colors.get(name + '_dark_ground')[1], colors.get(name + '_dark_ground')[2]) entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value) # Draw entities for entity in entities_in_render_order: draw_entity(con, entity, fov_map, game_map, top_left_x, top_left_y) libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0) libtcod.console_clear(panel) y = 0 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 libtcod.console_set_default_foreground(panel, libtcod.light_orange) libtcod.console_print_frame(panel, 0, 0, screen_width, panel_height, False, libtcod.BKGND_NONE, "Message Log") render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp, player.fighter.max_hp, libtcod.dark_crimson, libtcod.darkest_grey) 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_grey) 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) if game_state == GameStates.LEVELED_UP: level_up_title = 'Press the key next to an option to level up accordingly.\n' level_up_menu(con, level_up_title, player, 50, screen_width, screen_height) if game_state == GameStates.CHARACTER_SCREEN: character_screen(player, 30, 10, screen_width, screen_height)