Example #1
0
def test_sys_time(console):
    libtcodpy.sys_set_fps(0)
    libtcodpy.sys_get_fps()
    libtcodpy.sys_get_last_frame_length()
    libtcodpy.sys_sleep_milli(0)
    libtcodpy.sys_elapsed_milli()
    libtcodpy.sys_elapsed_seconds()
def test_sys_time(console):
    libtcodpy.sys_set_fps(0)
    libtcodpy.sys_get_fps()
    libtcodpy.sys_get_last_frame_length()
    libtcodpy.sys_sleep_milli(0)
    libtcodpy.sys_elapsed_milli()
    libtcodpy.sys_elapsed_seconds()
Example #3
0
def draw_stats(root_console: tcod.console.Console) -> None:
    root_console.default_fg = tcod.grey
    root_console.print_(
        ROOT_WIDTH - 1, ROOT_HEIGHT - 1, ' last frame : %3d ms (%3d fps)' % (
            tcod.sys_get_last_frame_length() * 1000.0,
            tcod.sys_get_fps(),
        ), tcod.BKGND_NONE, tcod.RIGHT)
Example #4
0
 def step(self, root):
     fps = tcod.sys_get_fps()
     self.poll_for_event(tcod.EVENT_ANY)
     root.write(0, 0, "This is a string.")
     root.write(0, 1, "FPS = {0}".format(fps))
     root.write(0, 2, "Current event = {0}.".format(self.current_event))
     root.draw_string(0, 3, "This is {blue}blue{/}.", bg_color=tcod.light_flame)
     if issubclass(type(self.current_event),
                   tcod.events.KeyReleaseEvent) and self.current_event.vk == tcod.KEY_ESCAPE:
         root.end_game = True
Example #5
0
 def step(self, root):
     fps = tcod.sys_get_fps()
     self.poll_for_event(tcod.EVENT_ANY)
     root.write(0, 0, "This is a string.")
     root.write(0, 1, "FPS = {0}".format(fps))
     root.write(0, 2, "Current event = {0}.".format(self.current_event))
     root.draw_string(0,
                      3,
                      "This is {blue}blue{/}.",
                      bg_color=tcod.light_flame)
     if issubclass(type(self.current_event), tcod.events.KeyReleaseEvent
                   ) and self.current_event.vk == tcod.KEY_ESCAPE:
         root.end_game = True
Example #6
0
 def _render_fps_counter(console):
     console.default_fg = tcod.grey
     console.print_(
         x=1, y=3,
         string='fps: %3d fps' % (tcod.sys_get_fps()),
         bg_blend=tcod.BKGND_NONE,
     )
     console.print_(
         x=1, y=4,
         string='last frame: %2d ms' % (
             tcod.sys_get_last_frame_length() * 1000.0,
         ),
         bg_blend=tcod.BKGND_NONE,
     )
     console.print_(
         x=1, y=5,
         string='elapsed: %4.2fs' % (tcod.sys_elapsed_seconds()),
         bg_blend=tcod.BKGND_NONE,
     )
Example #7
0
def main():
    """Example program for tcod.event"""
    TITLE = None

    tcod.console_set_custom_font(
        "potash_10x10.png",
        tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_ASCII_INROW)

    generate_quadrants()

    with tcod.console_init_root(
            WIDTH,
            HEIGHT,
            TITLE,
            order="F",
            renderer=tcod.RENDERER_SDL2,
            vsync=True,
    ) as console:
        # tcod.sys_set_fps(30)
        pad = np.zeros((HEIGHT * 2, WIDTH * 2, 3), np.uint8)
        dots = [Dot() for _ in range(200)]
        while True:
            pad[...] //= 2
            for dot in dots:
                dot.draw(pad)
                dot.step()

            console.draw_semigraphics(pad)
            console.print(0,
                          HEIGHT - 1,
                          str(tcod.sys_get_fps()),
                          fg=(255, 255, 255),
                          bg=(0, 0, 0))
            tcod.console_flush()
            for event in tcod.event.get():
                if event.type == "QUIT" or (event.type == "KEYDOWN" and
                                            event.sym == tcod.event.K_ESCAPE):
                    raise SystemExit()
Example #8
0
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 render_all(root_console: tcod.console.Console,
               offscreen_console: tcod.console.Console,
               viewport_console: tcod.console.Console,
               status_console: tcod.console.Console,
               log_console: tcod.console.Console,
               entity_console: tcod.console.Console, player: Entity,
               game_map: GameMap, mouse_tx: int, mouse_ty: int,
               fov_recompute: bool, game_messages: MessageLog, box_text: str,
               game_state: GameState, camera: "Camera") -> None:

    screen_height = const.SCREEN_HEIGHT
    screen_width = const.SCREEN_WIDTH
    bar_width = const.BAR_WIDTH

    status_console.clear()
    log_console.clear()
    entity_console.clear()

    if fov_recompute:

        # Show nothing by default
        viewport_console.ch[:] = 0
        viewport_console.fg[:] = (0, 0, 0)
        viewport_console.bg[:] = (0, 0, 0)

        # Move camera to follow the player
        camera.move_camera(player.x, player.y, game_map.width, game_map.height)
        cam_x, cam_y = camera.x, camera.y
        cam_x2, cam_y2 = camera.x2, camera.y2

        # Translate map coordinates to camera coordinates
        cam_fov = game_map.fov_map.fov[cam_x:cam_x2 + 1, cam_y:cam_y2 + 1]
        cam_explored = game_map.explored[cam_x:cam_x2 + 1, cam_y:cam_y2 + 1]
        cam_glyph = game_map.tile_map.glyph[cam_x:cam_x2 + 1, cam_y:cam_y2 + 1]
        cam_fg = game_map.tile_map.fg[cam_x:cam_x2 + 1, cam_y:cam_y2 + 1]
        cam_bg = game_map.tile_map.bg[cam_x:cam_x2 + 1, cam_y:cam_y2 + 1]

        # If a tile is explored but not visible, render it in dark colors.
        viewport_console.fg[cam_explored == True] = np.multiply(
            cam_fg[cam_explored == True], 0.50).astype(np.int)
        viewport_console.bg[cam_explored == True] = np.multiply(
            cam_bg[cam_explored == True], 0.50).astype(np.int)
        viewport_console.ch[cam_explored == True] = cam_glyph[cam_explored ==
                                                              True]

        # If a tile is visible then render it in light colors.
        viewport_console.fg[cam_fov == True] = cam_fg[cam_fov == True]
        viewport_console.bg[cam_fov == True] = cam_bg[cam_fov == True]
        viewport_console.ch[cam_fov == True] = cam_glyph[cam_fov == True]
        # viewport_console.ch[cam_transparent == False] = 178

        # If a tile is visible, then it is now explored.
        game_map.explored[game_map.fov_map.fov == True] = True

    # Draw all entities in the list
    entities_in_render_order = sorted(game_map.entities,
                                      key=lambda x: x.entity_type.value)

    for entity in entities_in_render_order:
        draw_entity(viewport_console, entity, game_map, camera)

    render_bar(status_console, 1, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, tcod.light_red, tcod.darker_red)
    status_console.print(1, 3, f"Dungeon Level: {game_map.dungeon_level}")

    status_console.print(1,
                         0,
                         get_names_under_mouse(mouse_tx, mouse_ty,
                                               game_map.entities, game_map),
                         fg=(128, 128, 128))

    y = 0
    for message in game_messages.messages:
        log_console.print(game_messages.x, y, message.text, fg=message.color)
        y += 1

    entity_console.print(5, 0, "Visible:", (128, 128, 128))

    visible_entities = [
        entity for entity in entities_in_render_order
        if tcod.map_is_in_fov(game_map.fov_map, entity.x, entity.y)
    ]

    for index, entity in enumerate(visible_entities, start=1):
        if entity.entity_type not in [EntityType.PLAYER, EntityType.CORPSE]:
            entity_str = f"{chr(entity.glyph)}: {entity.name.capitalize()}"
            entity_console.print(1, index, entity_str, entity.fg)

    draw_frames(offscreen_console)

    # offscreen_console.print(0, screen_height - 1, f"{mouse_tx}, {mouse_ty}")

    viewport_console.blit(offscreen_console, 1, 1)
    status_console.blit(offscreen_console, const.VIEWPORT_WIDTH + 2, 1)
    log_console.blit(offscreen_console, 1, const.VIEWPORT_HEIGHT + 2)
    entity_console.blit(offscreen_console, const.VIEWPORT_WIDTH + 2,
                        const.STATUS_HEIGHT + 2)
    offscreen_console.blit(root_console)

    if game_state in [GameState.SHOW_INVENTORY, GameState.DROP_INVENTORY]:
        if game_state == GameState.SHOW_INVENTORY:
            inventory_title = "Press the key next to an item to use it, ESC to cancel.\n"
        else:
            inventory_title = "Press the key next to an item to drop it, ESC to cancel.\n"

        inventory_menu(root_console, inventory_title, player, 50, screen_width,
                       screen_height)

    elif game_state == GameState.LEVEL_UP:
        level_up_menu(root_console, "Level up! Choose a stat to raise:",
                      player, 40, screen_width, screen_height)

    elif game_state == GameState.CHARACTER_SCREEN:
        character_screen(root_console, player, 30, 10, screen_width,
                         screen_height)

    elif game_state == GameState.MESSAGE_BOX:
        message_box(root_console, box_text, len(box_text),
                    const.VIEWPORT_WIDTH, const.VIEWPORT_HEIGHT)

    if SHOW_STATS:
        fps = tcod.sys_get_fps()
        if fps > 0:
            fps_str = f"FPS: {fps} ({1000 / fps:.2f} ms/frame)"
            root_console.print(0,
                               const.SCREEN_HEIGHT - 1,
                               fps_str,
                               fg=(255, 255, 255))

    tcod.console_flush()
Example #10
0
 def print_debug_info(self):
     fps = tcod.sys_get_fps()
     root = self.window_manager.rootc
     root.write(0, 0, "Time elapsed = {0}".format(tcod.sys_elapsed_milli()))
     root.write(0, 1, "FPS = {0}".format(fps))
     root.write(0, 2, "Current event = {0}.".format(self.current_event))
Example #11
0
 def draw(self):
     self.write(1, 2, "No draw method defined, using default method.")
     self.write(1, 3, "Time elapsed = {0}".format(tcod.sys_elapsed_milli()))
     self.write(1, 4, "FPS = {0}".format(tcod.sys_get_fps()))
Example #12
0
 def render(self):
     self.board.render(self.editor.cursor)
     self.editor.render()
     base.root_console.print(5, 0, "fps: "+str(tcod.sys_get_fps()))
Example #13
0
 def print_debug_info(self):
     fps = tcod.sys_get_fps()
     root = self.window_manager.rootc
     root.write(0, 0, "Time elapsed = {0}".format(tcod.sys_elapsed_milli()))
     root.write(0, 1, "FPS = {0}".format(fps))
     root.write(0, 2, "Current event = {0}.".format(self.current_event))
Example #14
0
 def draw(self):
     self.write(1, 2, "No draw method defined, using default method.")
     self.write(1, 3, "Time elapsed = {0}".format(tcod.sys_elapsed_milli()))
     self.write(1, 4, "FPS = {0}".format(tcod.sys_get_fps()))