def draw(self, console: tcod.console.Console): for i in range(self.height): console.print(int(self.x), int(self.y - i), ' ' * self.length, bg=self.col, bg_blend=tcod.BKGND_ADD)
def _process_messages(self, console: tcod.console.Console) -> None: messages = self.world.try_resource(Messages) if messages is None: return for y, message in enumerate(messages.messages): console.print(config.MESSAGE_X, y + 1, message.message, message.color)
def on_draw(self, console: tcod.console.Console) -> None: """Draw inventory menu over the previous state.""" inventory_ = self.model.player.inventory rendering.draw_main_view(self.model, console) style: Any = {"fg": (255, 255, 255), "bg": (0, 0, 0)} console.print(0, 0, self.desc, **style) for i, item in enumerate(inventory_.contents): sym = inventory_.symbols[i] console.print(0, 2 + i, f"{sym}: {item.name}", **style)
def on_render(self, console: tcod.Console) -> None: """Render the main menu on a background image.""" console.print(x=console.width // 2 - 5, y=console.height // 2, string="SUPER DS9") console.print(x=console.width // 2 - 9, y=console.height // 2 + 2, string="Press any key to begin")
def on_draw(self, console: tcod.console.Console) -> None: super().on_draw(console) style: Any = {"fg": (255, 255, 255), "bg": (0, 0, 0)} console.print(0, 0, self.desc, **style) cam_x, cam_y = self.model.active_map.get_camera_pos(console) x = self.cursor_xy[0] - cam_x y = self.cursor_xy[1] - cam_y if 0 <= x < console.width and 0 <= y < console.height: console.tiles_rgb.T[["fg", "bg"]][x, y] = (0, 0, 0), (255, 255, 255)
def render(self, console: tcod.console.Console, entities): """ Render the game map. TODO: - Render based on entity vision """ for y in range(self.height): for x in range(self.width): tile = self.tiles[x][y] if tile.revealed: console.print(x, y, tile.char, tile.fg_color, tile.bg_color) else: tcod.console_set_char_background(console, x, y, (50, 50, 50)) tcod.console_set_char_foreground(console, x, y, (50, 50, 50))
def _process_choice_menu(self, console: tcod.console.Console, menu: Menu) -> None: if len(menu.options) > 26: raise ValueError("Cannot have a menu with more than 26 options.") # print all the options y = 0 letter_index = ord("a") for option_text in menu.options: text = "(" + chr(letter_index) + ") " + option_text console.print(0, y, text, bg_blend=tcod.BKGND_NONE) y += 1 letter_index += 1
def _process_entities(self, console: tcod.console.Console) -> None: fov = self.world.try_resource(Fov) if fov is None: return fov_map = fov.fov_map matches = self.world.get_components(Position, Visual) matches.sort(key=lambda item: item[1][1].render_order.value) for ent, (position, visual) in matches: if not fov_map.fov[position.y, position.x]: continue console.print(position.x, position.y, visual.char, fg=visual.color)
def render_bar( console: tcod.console.Console, x: int, y: int, width: int, text: str, fullness: float, fg: Tuple[int, int, int], bg: Tuple[int, int, int], ) -> None: """Render a filled bar with centered text.""" console.print(x, y, text.center(width)[:width], fg=(255, 255, 255)) bar_bg = console.tiles_rgb.T["bg"][x:x + width, y] bar_bg[...] = bg fill_width = max(0, min(width, int(fullness * width))) bar_bg[:fill_width] = fg
def _render_bar( self, console: tcod.console.Console, x: int, y: int, total_width: int, name: str, value: int, maximum: int, bar_color: tcod.color.Color, back_color: tcod.color.Color, ): bar_width = int(float(value) / maximum * total_width) console.draw_rect( x, y, total_width, height=1, ch=ord(" "), bg=back_color, bg_blend=tcod.BKGND_SCREEN, ) if bar_width > 0: console.draw_rect( x, y, bar_width, height=1, ch=ord(" "), bg=bar_color, bg_blend=tcod.BKGND_SCREEN, ) console.print( int(x + total_width / 2), y, f"{name}: {value}/{maximum}", bg_blend=tcod.BKGND_NONE, alignment=tcod.CENTER, )
def _process_character_menu(self, console: tcod.console.Console) -> None: # This would ideally be refactored into Menu containing a list of non-choice lines # or maybe a dedicated InformationMenu component, or maybe a flag on Menu switching # between an information-only and a choice menu player = self.player if not player: return level = self.world.component_for_entity(player, Level) fighter = self.world.component_for_entity(player, Fighter) lines = [ f"Level: {level.current_level}", f"Experience: {level.current_xp}", f"Experience to Level: {level.experience_to_next_level}", f"Maximum HP: {fighter.max_hp}", f"Attack: {power(self.world, player)}", f"Defense: {defense(self.world, player)}", ] for y, line in enumerate(lines): console.print(0, y, line, bg_blend=tcod.BKGND_NONE)
def _process_map(self, console: tcod.console.Console) -> None: map = self.world.try_resource(Map) if map is None: return fov_map = self.world.get_resource(Fov).fov_map for x, column in enumerate(map.tiles): for y, tile in enumerate(column): if not tile.explored: continue wall = tile.block_sight visible = fov_map.fov[y, x] if wall: char = "#" else: char = "." console.print(x, y, char, bg=config.theme.background_color(wall, visible))
def _run_main_loop(self): while True: console = self.root_console tcod.console_flush() console.clear() brick_height = 4 brick_width = 8 for x in range(0, SCREEN_WIDTH): for y in range(0, SCREEN_HEIGHT): console.print(x, y, ' ', bg=(90, 90, 98)) if y % (brick_height + 1) == 0: console.print(x, y, ' ', bg=(50, 50, 58)) if y % ( (brick_height * 2) + 2) - 2 < (brick_height / 2) + 1: if x % (brick_width + 1) == 0: console.print(x, y, ' ', bg=(50, 50, 58)) else: if x % (brick_width + 1) == (brick_width / 2): console.print(x, y, ' ', bg=(50, 50, 58)) console.draw_frame(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, clear=False, title='Logue Regacy') if self.game_client.connected: self.chat_view.draw(console) if self.main_menu.is_open(): self.main_menu.menu_stack[-1].draw() for event in tcod.event.get(): if event.type == "QUIT": if self.game_client.connected: self.game_client.disconnect() exit() if event.type == "KEYDOWN" or event.type == "TEXTINPUT": if self.main_menu.is_open(): self.main_menu.menu_stack[-1].dispatch(event) elif self.chat_view: self.chat_view.message_input.dispatch(event) self.chat_view.message_box.dispatch(event)
def game_loop(console): mist = { 'fade': 0.0000000001, 'col': (2, 4, 8), 'length': 25, 'height': 5, 'vx': (-5, 5), 'vy': (-4, -1), 'life': 200 } rain = { 'fade': 0.0005, 'col': (20, 20, 40), 'vx': (-100, -80), 'vy': (70, 100), 'life': 90, 'height': 2 } lantern = { 'vy': (-10, -5), 'vx': (-10, 10), 'fade': 0.000000002, 'col': (30, 25, 10), 'life': 140 } emitter = particle.Emitter(console, mist, 1, SCREEN_HEIGHT - 1, SCREEN_WIDTH - 23, 1) lantern = particle.Emitter(console, lantern, 1540 // 12, 816 // 12, 3, 1) rain = particle.Emitter(console, rain, 1, 0, SCREEN_WIDTH - 2, 1, rate=3) bee = open('assets/bee.txt').read() wiz = tcod.image_load('assets/wizard_idle_dark.bmp') # wiz.set_key_color((0, 0, 0)) i = 20 glow = 0 while True: tcod.console_flush() console.clear() rain.create_particle() rain.draw() lantern.create_particle() lantern.draw() emitter.create_particle() emitter.draw() console.draw_frame(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 'Welcome to game :)', clear=False) wiz.blit(console, SCREEN_WIDTH - 32, SCREEN_HEIGHT // 2, tcod.BKGND_SCREEN, 1.5, 1.5, 0) console.print_box(3, 3, SCREEN_WIDTH - 64, SCREEN_HEIGHT - 3, bee[0:i], fg=(217, 130, 67)) console.print(SCREEN_WIDTH - 2, 1, str(chr(30)), fg=(252, 149, 71)) console.print(SCREEN_WIDTH - 2, SCREEN_HEIGHT - 2, str(chr(31)), fg=(252, 149, 71)) console.print(SCREEN_WIDTH - 8, 1, str(tcod.sys_get_fps()), fg=(230, 230, 230)) glow = (glow + 0.1) % 6 if i < len(bee): i += 1 print(glow) # console.print(0,0,'lol hi!') for event in tcod.event.get(): if event.type == "QUIT": exit() if event.type == "MOUSEMOTION": console.print(SCREEN_WIDTH - 40, 1, str(event.pixel)) if event.type == "KEYDOWN": print(i)
def draw(self, console: tcod.console.Console): console.print(self.x, self.y, self.char, fg=self.col)
def on_render(self, console: tcod.Console) -> None: hw = 12 console.draw_frame( x=0, y=0, width=hw, height=hw, bg=(255, 0, 0), fg=(0, 255, 0), bg_blend=constants.BKGND_ADD, title="testDF", ) console.draw_frame( x=0, y=hw * 2, width=hw, height=hw, bg_blend=constants.BKGND_ADD, title="testDF", ) console.draw_rect(x=hw, y=hw, width=hw, height=hw, bg=(255, 0, 0), fg=(0, 255, 0), bg_blend=constants.BKGND_ADD, ch=ord("A")) console.print_box(x=2 * hw, y=0, width=hw, height=hw, string="testPB", bg=(255, 0, 0), fg=(0, 255, 0), bg_blend=constants.BKGND_ADD, alignment=constants.RIGHT) console.print_box(x=2 * hw, y=2 * hw, width=hw, height=hw, string="testPB", bg_blend=constants.BKGND_ADD, alignment=constants.RIGHT) console.print_frame( x=3 * hw, y=hw, width=hw, height=hw, string="testPF", bg_blend=constants.BKGND_ADD, ) console.print_rect( x=4 * hw, y=0, width=hw, height=hw, string="testPR", bg_blend=constants.BKGND_ADD, alignment=constants.RIGHT, ) a = Decimal(12.3 + 45 / 7193) s_str = f"{a}\n{a:.4}\n{a:.4g}\n{a:8.4}\n{a:=.4}\n{a:>.4}\n{a:<.4}\n{a:0.4}\n{a:2.4}\n{a:1.4}" console.print(x=3 * hw, y=2 * hw + 14, string=s_str) self.number_handeler.render(console, ) le = 5 ma = "AAAaaa" console.print(x=60, y=45, string=f"{ma:>{le}}") self.text_wrap_handler.render(console)
def _process_dungeon_level(self, console: tcod.console.Console) -> None: map = self.world.try_resource(Map) if map is None: return console.print(1, 3, f"Dungeon Level: {map.dungeon_level}")