def render(self, console: Console, context: Context) -> None: #render the map first self.game_map.render(console) context.present(console) console.clear()
def render(self, console: Console, context: Context) -> None: self.game_map.render(console) render_menu(console=console, map_height=self.game_map.height, menu_width=100) self.message_log.render(console=console) # If the current event handler is the Inventory handler, show the inventory screen. if isinstance(self.event_handler, InventoryEventHandler): render_inventory_menu(console=console, engine=self) render_bar(console=console, character=self.player, current_value=self.player.fighter.hp, maximum_value=self.player.fighter.max_hp, total_width=20) render_names_at_mouse_location(console=console, x=21, y=44, engine=self) context.present(console) console.clear()
def render(self, console: Console, context: Context) -> None: for entity in self.entities: console.print(entity.x, entity.y, entity.char, fg=entity.color) context.present(console) console.clear()
def render(self, console: Console, context: Context): self.game_map.render(console) for entity in self.entities: if self.game_map.visible[entity.x, entity.y]: console.print(entity.x, entity.y, entity.char, fg=entity.color) context.present(console) console.clear()
def render(self, console: Console, context: Context) -> None: """Method for rendering objects in TCOD terminal""" self.g_map.render(console) console.print(x=1, y=47, string=f"HP: {self.player.stats.hp}/{self.player.stats.max_hp}") context.present(console) console.clear()
def render(self, console: Console, context: Context) -> None: self.game_map.render(console) for entity in self.entities: # Only print entities that are in the FOV if self.game_map.visible[entity.x, entity.y]: console.print(entity.x, entity.y, entity.char, fg=entity.color) context.present(console) console.clear()
def render(self, console: Console, context: Context) -> None: """The render function renders the tcod console and tcod context for us. by doing this it can display all the entities and respond to actions for us. The rendering function is run each game loop to update what is displayed to the user """ # Shall call the game renderer object to render the different elements of the game, including the game map, the entities and the console. self.game_map.render_map(console) context.present(console) console.clear()
def render(self, console: Console, context: Context) -> None: self.game_map.render(console) console.print( x=1, y=47, string=f"HP: {self.player.fighter.hp}/{self.player.fighter.max_hp}", ) context.present(console) console.clear()
def render(self, console: tConsole, context: Context) -> None: self.__mockup_render(console) self.screen.render_main(console, self.player_ship, 1, 1, SCREEN_WIDTH - SIDEBAR_WIDTH - 1, SCREEN_HEIGHT - CONSOLE_HEIGHT - 2) self.sidebar.render(console, SCREEN_WIDTH - SIDEBAR_WIDTH + 1, 1, SIDEBAR_WIDTH - 2, SCREEN_HEIGHT - 8) self.console.render(console, 1, SCREEN_HEIGHT - CONSOLE_HEIGHT, CONSOLE_HEIGHT - 2, SCREEN_WIDTH - SIDEBAR_WIDTH - 1) self.render_frames(console) context.present(console) console.clear()
def render(self, console: Console, context: Context) -> None: ''' GameMap instance renders independently using its own .render() method. Then 'tcod.context' displays the console to the screen. ''' self.game_map.render(console) console.print( x=1, y=47, string= f"HP: {self.player.fighter.hp} / {self.player.fighter.max_hp}") context.present(console) console.clear()
def render(self, console: Console, context: Context) -> None: """ The display portion of the game loop, now as its own method. :param console: :param context: :return: None """ # draw the game map on screen self.game_map.render(console) # loop through all the entities for entity in self.entities: # and place them on the console console.print(entity.x, entity.y, entity.char, entity.color) # update the screen so we can see them context.present(console) # clear console to prevent 'trailing' console.clear()
def main(): screen_width = 90 screen_height = 60 tcod.console_set_custom_font( 'terminal8x12_gs_tc.png', tcod.FONT_TYPE_GRAYSCALE | tcod.FONT_LAYOUT_TCOD) tcod.console_init_root(screen_width, screen_height, 'Spaceship', False, renderer=tcod.RENDERER_SDL2, vsync=True) tcod.console_map_ascii_code_to_font(7, 12, 2) tcod.console_map_ascii_code_to_font(9, 13, 2) object_view_width = 40 object_view_height = 40 main_console = Console(screen_width, screen_height, order='F') object_console = Console(screen_width, screen_height, order='F') parse(all_objects, object_list) frame = all_objects['base'][1] spaceship_x, spaceship_y = 0, 0 file_path = getcwd() + '/spaceship.dat' if not path.exists(file_path) or path.getsize(file_path) == 0: pickle.dump(Object('Spaceship', 50, 50), open(file_path, 'wb+')) try: spaceship = pickle.load(open(getcwd() + '/spaceship.dat', 'rb')) except pickle.UnpicklingError: pickle.dump(Object('Spaceship', 50, 50), open(file_path, 'wb+')) spaceship = pickle.load(open(file_path, 'rb')) examine_x = screen_width - 50 examine_y = 1 examine_width = 50 examine_height = screen_height - 2 examine_menu = None build_menu_object_key_list = ['default'] for x in range(spaceship.width): for y in range(spaceship.height): for part in spaceship.tiles[x][y]: for object in object_list: if not 'json_id' in part.__dict__ and object.name == part.name: part.json_id = object.json_id print('Assigned {} to {}'.format( part.name, object.json_id)) if 'json_id' in part.__dict__ and object.json_id == part.json_id: part.fg = object.fg part.bg = object.bg part.char = object.char part.sorting_index = object.sorting_index part.mass = object.mass break else: print( 'Could not find corresponding JSON part for existing part {}' .format(part.name)) spaceship.add_part(0, 0, frame, override=True) spaceship.calculate_rooms() viewing_mode = 0 num_modes = len(view_dict) + 2 selection_index = 0 max_select_index = 0 build_menu_open = False selection_box = (0, 0), (0, 0) screen_offset_x, screen_offset_y = 0, 0 selection_console = Console(screen_width, screen_height, order='F') selection_console.clear(bg=tcod.lightest_blue) while True: response = None prev_select_index = selection_index prev_selection_coord = selection_box[0] for event in tcod.event.get(): if event.type == 'KEYDOWN': response = {} input_resp = handle_input(event) if input_resp: response.update(input_resp) if build_menu_open and ord('z') >= event.sym >= ord('a'): response['select_item'] = event.sym - ord('a') elif event.type == 'MOUSEBUTTONDOWN' or event.type == 'MOUSEBUTTONUP' or event.type == 'MOUSEMOTION': response = handle_mouse(event) elif event.type == 'QUIT': pickle.dump(spaceship, open(file_path, 'wb+')) return if response: if response.get('move'): move = response.get('move') if examine_menu: examine_menu.selected_index += move[1] if move[0] != 0: if examine_menu.try_change_option(move[0]): spaceship.update_all() else: screen_offset_x = max(0, screen_offset_x + move[0]) screen_offset_y = max(0, screen_offset_y + move[1]) elif response.get('viewing_mode'): viewing_mode = (viewing_mode + response.get('viewing_mode')) % num_modes elif response.get('navigate'): selection_index += response.get('navigate') if selection_index < 0: selection_index += max_select_index elif selection_index >= max_select_index: selection_index -= max_select_index if response.get('build'): if not build_menu_open: build_menu_open = True build_menu_object_key_list = [] selection_index = 0 if response.get('delete') and not build_menu_open: if spaceship.is_valid_coord( selection_box[0][0] - spaceship_x, selection_box[0][1] - spaceship_y) and selection_index < len( spaceship.tiles[selection_box[0][0] - spaceship_x][ selection_box[0][1] - spaceship_y]): part_name = spaceship.tiles[ selection_box[0][0] - spaceship_x][selection_box[0][1] - spaceship_y][selection_index].name for x in range(selection_box[0][0], selection_box[1][0]): for y in range(selection_box[0][1], selection_box[1][1]): for part in spaceship.tiles[x][y]: if part.name == part_name: spaceship.remove_part( x - spaceship_x, y - spaceship_y, part) elif (response.get('select') or response.get('mouse_move_lheld') or response.get('lclick_down')) and build_menu_open: if type(get_object(build_menu_object_key_list)) is list: if response.get('mouse_move_lheld'): selection_box = response.get('mouse_move_lheld'), ( response.get('mouse_move_lheld')[0] + 1, response.get('mouse_move_lheld')[1] + 1) for x in range(selection_box[0][0], selection_box[1][0]): for y in range(selection_box[0][1], selection_box[1][1]): spaceship.add_part( x - spaceship_x, y - spaceship_y, get_object(build_menu_object_key_list) [selection_index]) else: build_menu_object_key_list.append( list(get_object(build_menu_object_key_list).keys()) [selection_index]) selection_index = 0 elif response.get('run'): for x in range(spaceship.width): for y in range(spaceship.height): for part in [ part for part in spaceship.tiles[x][y] if part.runnable ]: part.runnable.run(spaceship, part, x, y) spaceship.update_all() if response.get('rclick_down'): selection_box = response.get('rclick_down'), response.get( 'rclick_down') elif response.get('lclick_down'): selection_box = response.get('lclick_down'), response.get( 'lclick_down') elif response.get('mouse_move_rheld'): selection_box = selection_box[0], ( response.get('mouse_move_rheld')[0] + 1, response.get('mouse_move_rheld')[1] + 1) elif response.get( 'mouse_move' ) and selection_box[1][0] - selection_box[0][ 0] <= 1 and selection_box[1][1] - selection_box[0][1] <= 1: selection_box = response.get('mouse_move'), ( response.get('mouse_move')[0] + 1, response.get('mouse_move')[1] + 1) elif response.get('select_item') is not None: index = response.get('select_item') if index < max_select_index: selection_index = index if type(get_object(build_menu_object_key_list)) is dict: build_menu_object_key_list.append( list( get_object(build_menu_object_key_list).keys()) [selection_index]) selection_index = 0 if response.get('escape'): if build_menu_open: if len(build_menu_object_key_list) == 0: build_menu_open = False selection_index = 0 else: build_menu_object_key_list.pop(-1) elif examine_menu: examine_menu = None if prev_select_index != selection_index or prev_selection_coord != selection_box[ 0]: if spaceship.is_valid_coord( selection_box[0][0] - spaceship_x, selection_box[0][1] - spaceship_y) and selection_index < len( spaceship.tiles[selection_box[0][0] - spaceship_x][ selection_box[0][1] - spaceship_y]): examine_menu = PartMenu( spaceship, spaceship.tiles[selection_box[0][0] - spaceship_x][selection_box[0][1] - spaceship_y][selection_index], examine_width, examine_height, selection_box[0][0], selection_box[0][1]) else: examine_menu = None tcod.console_flush() main_console.clear(bg=tcod.black) selection_pos = selection_box[0] object_console.clear() render_object(object_console, spaceship, spaceship_x, spaceship_y, viewing_mode) object_console.blit(main_console, 0, 0, screen_offset_x, screen_offset_y, object_view_width, object_view_height) # main_console.put_char(selection_box[0][0], selection_box[0][1], ord('X')) # main_console.fg[selection_box[0][0], selection_box[0][1]] = tcod.cyan if build_menu_open: iterable = get_object(build_menu_object_key_list) if type(iterable) is list: iterable = [item.name for item in iterable] else: iterable = [item.capitalize() for item in iterable] for i in range(len(iterable)): main_console.print(screen_width - 50, i, chr(ord('a') + i) + ' - ' + iterable[i], bg=(tcod.desaturated_blue if selection_index == i else tcod.black)) main_console.fg[screen_width - 50, i] = tcod.light_green max_select_index = len(iterable) else: main_console.print(0, screen_height - 1, str(viewing_mode)) if spaceship_x <= selection_pos[ 0] < spaceship_x + spaceship.width and spaceship_y <= selection_pos[ 1] < spaceship_y + spaceship.height: room = spaceship.find_room(selection_pos[0] - spaceship_x, selection_pos[1] - spaceship_y) parts = [ part for part in spaceship.tiles[selection_pos[0] - spaceship_x][selection_pos[1] - spaceship_y] ] if room: gas_y = len(parts) + 2 for gas in room.gas_content: main_console.print( 20, gas_y, '{1}: {0:.2f} kPa'.format( components.calc_pressure( room.gas_content[gas], len(room.tiles)), gas.capitalize())) gas_y += 1 for i in range(len(parts)): part = parts[i] string = part.name if part.gas_grid: string += ' {}'.format(part.gas_grid.index) main_console.print( 20, i + 1, string, bg=(tcod.desaturated_blue if selection_index == i else tcod.black)) max_select_index = len(parts) if examine_menu: examine_menu.draw() examine_menu.console.blit(main_console, examine_x, examine_y, 0, 0, examine_width, examine_height) dsel_x = selection_box[1][0] - selection_box[0][0] dsel_y = selection_box[1][1] - selection_box[0][1] if dsel_x > 0 and dsel_y > 0: selection_console.blit(main_console, selection_box[0][0], selection_box[0][1], 0, 0, dsel_x, dsel_y, bg_alpha=0.25) main_console.blit(tcod.console._root_console, width=screen_width, height=screen_height, bg_alpha=1)
class PartMenu: def __init__(self, object, part, width, height, x, y): self.object = object self.part = part self.width = width self.height = height self.console = Console(width, height) self.selected_index = 0 self.x = x self.y = y def draw(self): #format: key=option name, value = (list of options, selected_option) options = {} self.console.clear() x = 0 y = 2 self.console.print(x, 0, 'Examining: ' + self.part.name) index = 0 for component in self.part.components: if component in self.part.__dict__ and self.part.__dict__[ component] and isinstance(self.part.__dict__[component], BaseComponent): part_component = self.part.__dict__[component] y += self.console.print_box(x, y, self.width, self.height - y, part_component.get_desc(), fg=tcod.gray) component_options = part_component.get_options(self.part) for option_name, ( part_options, selected_option) in component_options.items(): self.console.print( x, y, option_name, bg=(tcod.desaturated_green if index == self.selected_index else tcod.black)) x += len(option_name) + 1 for i in range(len(part_options)): if x >= self.width: x = 0 y += 1 part_option = part_options[i] self.console.print( x, y, part_option, bg=(tcod.desaturated_blue if i == selected_option else tcod.black)) x += len(part_option) + 1 index += 1 x = 0 y += 1 if index == 0: self.selected_index = 0 else: self.selected_index = self.selected_index % index def try_change_option(self, change): index = 0 for component in self.part.components: if self.part.__dict__[component] and isinstance( self.part.__dict__[component], BaseComponent): part_component = self.part.__dict__[component] component_options = part_component.get_options(self.part) for option_name, ( part_options, selected_option) in component_options.items(): if index == self.selected_index: selected_option = (selected_option + change) % len(part_options) part_component.change_option(option_name, selected_option, self.part, self.object, self.x, self.y) return True index += 1 return False