def test_console_printing(console, fg, bg): libtcodpy.console_set_background_flag(console, libtcodpy.BKGND_SET) assert (libtcodpy.console_get_background_flag(console) == libtcodpy.BKGND_SET) libtcodpy.console_set_alignment(console, libtcodpy.LEFT) assert (libtcodpy.console_get_alignment(console) == libtcodpy.LEFT) libtcodpy.console_print(console, 0, 0, 'print') libtcodpy.console_print_ex(console, 0, 0, libtcodpy.BKGND_SET, libtcodpy.LEFT, 'print ex') assert (libtcodpy.console_print_rect( console, 0, 0, 8, 8, 'print rect') > 0 ) assert (libtcodpy.console_print_rect_ex( console, 0, 0, 8, 8, libtcodpy.BKGND_SET, libtcodpy.LEFT, 'print rect ex') > 0 ) assert (libtcodpy.console_get_height_rect( console, 0, 0, 8, 8, 'get height') > 0 ) libtcodpy.console_set_color_control(libtcodpy.COLCTRL_1, fg, bg)
def inspect_banner(x, y, banner_text, new_animation=True): animation_console = Render.layers['animation_console'] # animation_console = 0 # print "printing" color = libtcod.light_blue libtcod.console_set_default_foreground(animation_console, libtcod.lighter_blue) libtcod.console_set_default_background(animation_console, libtcod.green) libtcod.console_set_background_flag(animation_console, libtcod.BKGND_MULTIPLY) length = len(banner_text) back = libtcod.green Render.draw_char(animation_console, x + 1, y, libtcod.CHAR_HLINE, color, back) Render.draw_char(animation_console, x + 2, y - 1, libtcod.CHAR_NW, color, back) Render.draw_char(animation_console, x + 2, y, libtcod.CHAR_TEEW, color, back) Render.draw_char(animation_console, x + 2, y + 1, libtcod.CHAR_SW, color, back) if new_animation: for z in range(length): Render.draw_char(animation_console, x + z + 3, y - 1, libtcod.CHAR_HLINE, color, back) Render.draw_char(animation_console, x + z + 3, y, banner_text[z], color, back) Render.draw_char(animation_console, x + z + 3, y + 1, libtcod.CHAR_HLINE, color, back) # Render.update_animations() libtcod.console_flush() # time.sleep(0.05) else: for z in range(length): Render.draw_char(animation_console, x + z + 3, y - 1, libtcod.CHAR_HLINE, color, back) Render.draw_char(animation_console, x + z + 3, y, ' ', color, back) Render.draw_char(animation_console, x + z + 3, y + 1, libtcod.CHAR_HLINE, color, back) Render.draw_char(animation_console, x + 3 + length, y - 1, libtcod.CHAR_NE, color, back) Render.draw_char(animation_console, x + 3 + length, y, libtcod.CHAR_VLINE, color, back) Render.draw_char(animation_console, x + 3 + length, y + 1, libtcod.CHAR_SE, color, back) libtcod.console_set_default_foreground(animation_console, libtcod.lightest_blue) Render.print_line(animation_console, x + 3, y, libtcod.BKGND_NONE, libtcod.LEFT, banner_text) libtcod.console_flush()
def render(self): ''' visible=true 보이는 상태이고 Screen에 포함되어 있으면 자신의 foreground color와 background color에 따라 Screen(의 콘솔에) char를 출력한다. ''' if self.visible is True: if self.ownerScreen is not None: owner = self._ownerScreen prevBackFlag = libtcod.console_get_background_flag(owner.console) prevForeColor = owner.foreColor prevBackColor = owner.backColor #renderObj의 색깔로 설정 libtcod.console_set_background_flag(owner.console, libtcod.BKGND_SET) libtcod.console_set_default_foreground(owner.console, self.foreColor) libtcod.console_set_default_background(owner.console, self.backColor) #출력 libtcod.console_print(owner.console, self.x, self.y, self.char) #원래 owner의 색깔로 되돌리기. libtcod.console_set_background_flag(owner.console, prevBackFlag) libtcod.console_set_default_foreground(owner.console, prevForeColor) libtcod.console_set_default_background(owner.console, prevBackColor) else: raise NoOwnerRenderObjError()
def console(session_console): """Return a root console. Be sure to use this fixture if the GUI needs to be initialized for a test. """ console = session_console libtcodpy.console_flush() libtcodpy.console_set_default_foreground(console, libtcodpy.white) libtcodpy.console_set_default_background(console, libtcodpy.black) libtcodpy.console_set_background_flag(console, libtcodpy.BKGND_SET) libtcodpy.console_set_alignment(console, libtcodpy.LEFT) libtcodpy.console_clear(console) return console
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color): #render a bar (HP, experience, etc). first calculate the width of the bar bar_width = int(float(value) / maximum * total_width) #render the background first libtcod.console_set_default_background(panel, back_color) libtcod.console_set_background_flag(panel, libtcod.BKGND_SET) libtcod.console_rect(panel, x, y, total_width, True, False) #now render the bar on top libtcod.console_set_default_background(panel, bar_color) if bar_width > 0: libtcod.console_set_background_flag(panel, libtcod.BKGND_SET) libtcod.console_rect(panel, x, y, bar_width, True, False) #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 main(argv = None): """ Entry-point into program.""" settings, args = process_command_line(argv) # Initialise libtcod libtcod.console_set_custom_font('arial12x12.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, PROGRAM_NAME, False) libtcod.sys_set_fps(10) libtcod.console_set_background_flag(0, libtcod.BKGND_SET) # Create a map and add starting entities. map = Map(maps.ground_control.level_1_raw) player = Human("Bob Smith", "male", 15, 30) player.report = ReportType.PLAYER map.add_entity(map.entry_point[0], map.entry_point[1], player) # Ghost is used to move around map for viewing ghost = Human("Ghost", "male", 15, 0) # Set up UI ui.Screens.map = ui.MapScreen(MAP_WINDOW[0], MAP_WINDOW[1], MAP_WINDOW[2], MAP_WINDOW[3]) ui.Screens.msg = ui.MessageScreen(MSG_WINDOW[0], MSG_WINDOW[1], MSG_WINDOW[2], MSG_WINDOW[3]) ui.Screens.inv = ui.InventoryScreen(INVENTORY_WINDOW[0], INVENTORY_WINDOW[1], INVENTORY_WINDOW[2], INVENTORY_WINDOW[3]) ui.Screens.map.show_and_activate() ui.Screens.msg.show_and_activate() ui.Screens.inv.hide_and_deactivate() # Set up main game loop. # turn_taken - did the action actually take a turn - ie do we want to update the simulation now? Initially true, to force a initial render. # input_type - what input state did the action leave us in? Are we expecting the next input to be part of the current action? # delayed_action - if we are in the middle of a multi-stage action, this is the action (closure) to be performed at the end of it. turn_taken = True input_type = InputType.IMMEDIATE delayed_action = None current_turn = 1 # main loop while not libtcod.console_is_window_closed(): libtcod.console_clear(0) libtcod.console_set_default_foreground(0, libtcod.white) # set up render bounds centre_bounds = int(MAP_WINDOW[2] / 2), int(MAP_WINDOW[3] / 2), map.x_max - int(MAP_WINDOW[2] / 2) - 1, map.y_max - int(MAP_WINDOW[3] / 2) - 1 # are we viewing the player or the ghost entity which acts as the automap viewer? view_centre = max(centre_bounds[0], min(player.x, centre_bounds[2])), max(centre_bounds[1], min(player.y, centre_bounds[3])) # Render screens if ui.Screens.map.show: ui.Screens.map.render(map, view_centre, player) if ui.Screens.msg.show: ui.Screens.msg.render() if ui.Screens.inv.show: ui.Screens.inv.render(player) ui.render_entity_info(player, map) libtcod.console_set_default_foreground(0, libtcod.white) libtcod.console_print(0, 0, 0, "Turn: %d" % current_turn) # Blit to console libtcod.console_flush() # Process input player_action = input.handle_input(player, input_type, delayed_action) turn_taken, input_type, delayed_action = player_action[0](player, map, player_action[1:]) if turn_taken: current_turn += 1 # Quit the loop? if turn_taken is None: break # If we've done something, update world and render if turn_taken: sim.update_world() # Return peacefully return 0
def bg_effect(self, effect): """ The default background effect which is used for functions that do not explicitly ask for one. """ return dlib.console_set_background_flag(self._intern, effect)
def main(argv=None): """ Entry-point into program.""" settings, args = process_command_line(argv) # Initialise libtcod libtcod.console_set_custom_font( 'arial12x12.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, PROGRAM_NAME, False) libtcod.sys_set_fps(10) libtcod.console_set_background_flag(0, libtcod.BKGND_SET) # Create a map and add starting entities. map = Map(maps.ground_control.level_1_raw) player = Human("Bob Smith", "male", 15, 30) player.report = ReportType.PLAYER map.add_entity(map.entry_point[0], map.entry_point[1], player) # Ghost is used to move around map for viewing ghost = Human("Ghost", "male", 15, 0) # Set up UI ui.Screens.map = ui.MapScreen(MAP_WINDOW[0], MAP_WINDOW[1], MAP_WINDOW[2], MAP_WINDOW[3]) ui.Screens.msg = ui.MessageScreen(MSG_WINDOW[0], MSG_WINDOW[1], MSG_WINDOW[2], MSG_WINDOW[3]) ui.Screens.inv = ui.InventoryScreen(INVENTORY_WINDOW[0], INVENTORY_WINDOW[1], INVENTORY_WINDOW[2], INVENTORY_WINDOW[3]) ui.Screens.map.show_and_activate() ui.Screens.msg.show_and_activate() ui.Screens.inv.hide_and_deactivate() # Set up main game loop. # turn_taken - did the action actually take a turn - ie do we want to update the simulation now? Initially true, to force a initial render. # input_type - what input state did the action leave us in? Are we expecting the next input to be part of the current action? # delayed_action - if we are in the middle of a multi-stage action, this is the action (closure) to be performed at the end of it. turn_taken = True input_type = InputType.IMMEDIATE delayed_action = None current_turn = 1 # main loop while not libtcod.console_is_window_closed(): libtcod.console_clear(0) libtcod.console_set_default_foreground(0, libtcod.white) # set up render bounds centre_bounds = int(MAP_WINDOW[2] / 2), int( MAP_WINDOW[3] / 2), map.x_max - int( MAP_WINDOW[2] / 2) - 1, map.y_max - int(MAP_WINDOW[3] / 2) - 1 # are we viewing the player or the ghost entity which acts as the automap viewer? view_centre = max(centre_bounds[0], min( player.x, centre_bounds[2])), max(centre_bounds[1], min(player.y, centre_bounds[3])) # Render screens if ui.Screens.map.show: ui.Screens.map.render(map, view_centre, player) if ui.Screens.msg.show: ui.Screens.msg.render() if ui.Screens.inv.show: ui.Screens.inv.render(player) ui.render_entity_info(player, map) libtcod.console_set_default_foreground(0, libtcod.white) libtcod.console_print(0, 0, 0, "Turn: %d" % current_turn) # Blit to console libtcod.console_flush() # Process input player_action = input.handle_input(player, input_type, delayed_action) turn_taken, input_type, delayed_action = player_action[0]( player, map, player_action[1:]) if turn_taken: current_turn += 1 # Quit the loop? if turn_taken is None: break # If we've done something, update world and render if turn_taken: sim.update_world() # Return peacefully return 0