Exemplo n.º 1
0
def print_line(dest, x, y, text, f_color=None): # bottom-right for BEARLIB
    # LIBTCOD
    # libtcod.console_print_ex(dest, x, y, flag, alignment, text)

    # BERALIB

    if f_color:
        set_foreground(dest, f_color)

    terminal.layer(dest)

    terminal.puts(x, y, text)
Exemplo n.º 2
0
def render_all(game_map, camera, player, mouse,
               entities, items, corpses, fov_cells):
    terrain = game_map.terrain
    water = game_map.water
    camera.move_camera(player.x, player.y, game_map)
    # print('Camera x: ' + str(camera.x))
    # print('Camera y: ' + str(camera.y))
    # start = time.time()
    decor = get_names_under_mouse(mouse, fov_cells, camera, terrain)
    creatures = get_names_under_mouse(mouse, fov_cells, camera, entities)
    itms = get_names_under_mouse(mouse, fov_cells, camera, items)
    remains = get_names_under_mouse(mouse, fov_cells, camera, corpses)
    layers = []
    if creatures:
        layers.append(creatures)
    if itms:
        layers.append(itms)
    if remains:
        layers.append(remains)
    if decor:
        layers.append(decor)
    screen_width = blt.state(blt.TK_WIDTH)
    screen_height = blt.state(blt.TK_HEIGHT)
    sidebar_width = screen_width - camera.width - 2
    sidebar_x = camera.width + 2
    panel_height = screen_height - camera.height - 3
    panel_y = camera.height + 2

    create_window(0, 0, camera.width + 2, camera.height + 1)
    create_window(0, panel_y, camera.width + 2,
                  panel_height, 'MESSAGE LOG')
    create_window(sidebar_x, 0, sidebar_width, screen_height - 1,
                  'PLAYER STATS')
    render_bar(sidebar_x + 1, 1, sidebar_width - 2, 'HP', player.fighter.hp,
               player.fighter.max_hp,
               'dark red', 'darkest red')
    # print(items)
    for x in range(1, camera.width):
        for y in range(1, camera.height):
            map_x, map_y = camera.to_map_coordinates(x, y)
            if (map_x, map_y) in fov_cells:
                if (map_x, map_y) in water:
                    render_obj((map_x, map_y), water, camera, 'blue')
                    water.get((map_x, map_y)).explored = True
                elif (map_x, map_y) in terrain:
                    render_obj((map_x, map_y), terrain, camera, 'gray')
                    terrain.get((map_x, map_y)).explored = True
                else:
                    blt.puts(x, y, '[color=dark yellow][U+4055]')

                if (map_x, map_y) in corpses:
                    obj = corpses.get((map_x, map_y))
                    render_obj((map_x, map_y), corpses, camera, obj.color)

                if (map_x, map_y) in items:
                    print("found item", map_x, map_y)
                    obj = items.get((map_x, map_y))
                    render_obj((map_x, map_y), items, camera, obj.color)

                if (map_x, map_y) in entities:
                    obj = entities.get((map_x, map_y))
                    # blt.puts(x, y, '[color=yellow][U+2146]')
                    render_obj((map_x, map_y), entities, camera, obj.color)
            elif ((map_x, map_y) in terrain and
                  terrain.get((map_x, map_y)).explored):
                render_obj((map_x, map_y), terrain, camera, 'darker orange')
            elif ((map_x, map_y) in water and
                  water.get((map_x, map_y)).explored):
                render_obj((map_x, map_y), water, camera, 'darker blue')


    names = ''
    for i in layers:
        if i == layers[0]:
            names = i
        elif i:
            names = names + ', ' + i

    blt.clear_area(mouse[0] + 1, mouse[1], len(names), 1)
    blt.puts(mouse[0] + 1, mouse[1], names)
Exemplo n.º 3
0
def test_mouse():
    blt.set("window.title='Omni: mouse input'")
    blt.set("input.filter={keyboard, mouse+}")
    blt.composition(True)

    precise_mouse = False
    cursor_visible = True
    mlx = -1
    mly = -1
    mrx = -1
    mry = -1
    scroll = 0
    plate = False

    # Flush input
    while blt.has_input():
        blt.read()

    counter = 0

    proceed = True
    while proceed:
        blt.clear()

        blt.color("white")
        blt.puts(
            1, 1, "Received [color=orange]%d[/color] %s" %
            (counter, "event" if counter == 1 else "events"))

        blt.color("white")
        blt.puts(
            1, 3, "Buttons: "
            "[color=%s]left "
            "[color=%s]middle "
            "[color=%s]right "
            "[color=%s]x1 "
            "[color=%s]x2 " %
            ("orange" if blt.state(blt.TK_MOUSE_LEFT) else "dark gray",
             "orange" if blt.state(blt.TK_MOUSE_MIDDLE) else "dark gray",
             "orange" if blt.state(blt.TK_MOUSE_RIGHT) else "dark gray",
             "orange" if blt.state(blt.TK_MOUSE_X1) else "dark gray",
             "orange" if blt.state(blt.TK_MOUSE_X2) else "dark gray"))

        blt.puts(
            1, 4,
            "Cursor: [color=orange]%d:%d[/color] [color=dark gray]cells[/color]"
            ", [color=orange]%d:%d[/color] [color=dark gray]pixels[/color]" %
            (blt.state(blt.TK_MOUSE_X), blt.state(blt.TK_MOUSE_Y),
             blt.state(blt.TK_MOUSE_PIXEL_X), blt.state(blt.TK_MOUSE_PIXEL_Y)))

        blt.puts(
            1, 5,
            "Wheel: [color=orange]%d[/color] [color=dark gray]delta[/color]"
            ", [color=orange]%d[/color] [color=dark gray]cumulative" %
            (blt.state(blt.TK_MOUSE_WHEEL), scroll))

        blt.puts(
            1, 7, "[color=%s][U+25CF][/color] Precise mouse movement" %
            ("orange" if precise_mouse else "black"))

        blt.put(1, 7, 0x25CB)

        blt.puts(
            1, 8, "[color=%s][U+25CF][/color] Mouse cursor is visible" %
            ("orange" if cursor_visible else "black"))

        blt.put(1, 8, 0x25CB)

        blt.puts(double_click_area.x, double_click_area.y - 1,
                 "Double-click here:")
        blt.color("darker orange" if plate else "darker gray")
        double_click_area.fill()

        mx = blt.state(blt.TK_MOUSE_X)
        my = blt.state(blt.TK_MOUSE_Y)
        blt.color(0x60FFFFFF)
        for x in range(blt.state(blt.TK_WIDTH)):
            blt.put(x, my, 0x2588)
        for y in range(blt.state(blt.TK_HEIGHT)):
            blt.put(mx, y, 0x2588)

        blt.color(0x8000FF00)
        blt.put(mlx, mly, 0x2588)

        blt.color(0x80FF00FF)
        blt.put(mrx, mry, 0x2588)

        blt.refresh()

        while True:
            code = blt.read()
            counter += 1

            if code in (blt.TK_ESCAPE, blt.TK_CLOSE):
                proceed = False

            elif code == blt.TK_MOUSE_LEFT:
                x = blt.state(blt.TK_MOUSE_X)
                y = blt.state(blt.TK_MOUSE_Y)

                if x == 1 and (y == 7 or y == 8):
                    if y == 7:
                        precise_mouse = not precise_mouse
                        blt.set("input.precise-mouse=%s" %
                                ("true" if precise_mouse else "false"))
                    else:
                        cursor_visible = not cursor_visible
                        blt.set("input.mouse-cursor=%s" %
                                ("true" if cursor_visible else "false"))
                elif (x, y) in double_click_area:
                    clicks = blt.state(blt.TK_MOUSE_CLICKS)
                    if clicks > 0 and clicks % 2 == 0:
                        plate = not plate
                else:
                    mlx = x
                    mly = y

            elif code == blt.TK_MOUSE_RIGHT:
                mrx = blt.state(blt.TK_MOUSE_X)
                mry = blt.state(blt.TK_MOUSE_Y)

            elif code == blt.TK_MOUSE_SCROLL:
                scroll += blt.state(blt.TK_MOUSE_WHEEL)

            elif code == blt.TK_SPACE:
                cursor_visible = not cursor_visible
                blt.set("input.mouse-cursor=%s" %
                        ("true" if cursor_visible else "false"))

            if not (proceed and blt.has_input()): break

    blt.color("white")
    blt.composition(False)
    blt.set("input: precise-mouse=false, mouse-cursor=true, filter={keyboard}")
Exemplo n.º 4
0
 def draw_player(self):
     terminal.color(terminal.color_from_name('white'))
     terminal.puts(SCREEN.size.x // 2, SCREEN.size.y // 2, '@')
Exemplo n.º 5
0
def test_speed():
    blt.set("window.title='Omni: syncronous rendering'")
    blt.composition(True)

    shift_b = shift_ff = 0

    shifted_b = [
        get_highlighted_color(get_shifted_color(i)) for i in range(80)
    ]
    shifted_f = [color_from_another(100, shifted_b[i]) for i in range(80)]

    fps_update_time = time()
    fps_counter = fps_value = 0
    vsync = True

    random.seed()
    r0 = [random.randrange(256) for _ in range(2000)]

    proceed = True
    d = 128
    while proceed:
        r1 = random.randrange(256)
        alpha = blt.color_from_argb(d, 255, 255, 255)
        shift_f = int(shift_ff)
        blt.clear()
        for y in range(25):
            s1 = shift_b + y
            s2 = shift_f + y
            yy = y * 80
            for x in range(80):
                blt.color(shifted_b[(s1 + x) % 80])
                blt.put(x, y, 0x2588)
                blt.color(shifted_f[(s2 - x) % 80])
                blt.put(x, y, 0x2588)
                blt.color(alpha)
                blt.put(x, y, ord('0') + (r1 + r0[yy + x]) % 10)

        blt.puts(
            2, 1, "[color=black]vsync: %s\nFPS: %d" %
            ("yes" if vsync else "no", fps_value))
        blt.puts(2, 4, "[color=black]Press TAB to switch vsync on an off")
        blt.refresh()

        fps_counter += 1
        tm = time()
        if tm > fps_update_time + 1:
            fps_value = fps_counter
            fps_counter = 0
            fps_update_time = tm

        while proceed and blt.has_input():
            code = blt.read()
            if code in (blt.TK_ESCAPE, blt.TK_CLOSE):
                proceed = False
            elif code == blt.TK_TAB:
                vsync = not vsync
                blt.set("output.vsync=%s" % ("true" if vsync else "false"))

        shift_b += 1
        d = abs(-40 + shift_b % 80) * 128 // 40
        shift_ff -= 1.25

    blt.set("output.vsync=true")
    blt.composition(False)
Exemplo n.º 6
0
def test_extended_basics():
    # Setup
    blt.set("window.title='Omni: extended output / basics'")
    blt.set("0xE000: ../Media/Tiles.png, size=32x32, align=top-left")
    blt.composition(True)

    cx, cy = 10, 5
    n_symbols = 10
    radius = 5
    angle = 0.0
    fps = 25
    transparent, opaque = 0x00FFFFFF, 0xFFFFFFFF

    m00 = [0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFFFF00]
    m01 = [opaque, opaque, transparent, transparent]

    m11 = [transparent, transparent, opaque, transparent]
    m12 = [transparent, opaque, transparent, transparent]
    m21 = [transparent, transparent, transparent, opaque]
    m22 = [opaque, transparent, transparent, transparent]

    while True:
        blt.clear()
        blt.color("white")

        blt.puts(
            2, 1,
            "[color=orange]1.[/color] put_ext(x, y, [color=orange]dx[/color], [color=orange]dy[/color], code)"
        )
        for i in range(n_symbols):
            angle_delta = 2 * pi / n_symbols
            dx = cos(angle + i * angle_delta) * radius * blt.state(
                blt.TK_CELL_WIDTH)
            dy = sin(angle + i * angle_delta) * radius * blt.state(
                blt.TK_CELL_WIDTH) - 4
            blt.color("white" if i > 0 else "orange")
            blt.put_ext(cx, cy, int(dx), int(dy), ord('a') + i)

        angle += 2 * pi / (2 * fps)

        blt.puts(
            2, 9,
            "[color=orange]2.[/color] put_ext(x, y, dx, dy, code, [color=orange]corners[/color])"
        )
        blt.put_ext(5, 11, 0, 0, 0xE000 + 19, m00)
        blt.put_ext(10, 11, 0, 0, 0xE000 + 19, m01)

        blt.puts(2, 14, "[color=orange]3.[/color] put_ext + composition")
        x1 = 5
        y1 = 16
        blt.put(x1 + 0, y1 + 0, 0xE000 + 19)
        blt.put(x1 + 0, y1 + 2, 0xE000 + 8)
        blt.put(x1 + 5, y1 + 0, 0xE000 + 19)
        blt.put(x1 + 9, y1 + 0, 0xE000 + 19)
        blt.put(x1 + 5, y1 + 2, 0xE000 + 19)
        blt.put(x1 + 9, y1 + 2, 0xE000 + 19)
        blt.put_ext(x1 + 5, y1 + 0, 0, 0, 0xE000 + 8, m11)
        blt.put_ext(x1 + 9, y1 + 0, 0, 0, 0xE000 + 8, m12)
        blt.put_ext(x1 + 5, y1 + 2, 0, 0, 0xE000 + 8, m21)
        blt.put_ext(x1 + 9, y1 + 2, 0, 0, 0xE000 + 8, m22)

        blt.refresh()

        if blt.has_input():
            key = blt.read()
            if key in (blt.TK_CLOSE, blt.TK_ESCAPE):
                break

        blt.delay(1000 // fps)

    # Clean up
    blt.composition(False)
    blt.set("0xE000: none")
Exemplo n.º 7
0
def DrawReticle():
    if Aiming:
        blt.layer(250)
        blt.puts(TargetX, TargetY, "[color=red]X[/color]")
Exemplo n.º 8
0
def draw_item(item):
    if player.CanSeeColor:
        blt.puts(item.x, item.y,
                 "[color=%s]%s[/color]" % (item.color, item.char))
    else:
        blt.puts(item.x, item.y, "[color=%s]%s[/color]" % ("grey", item.char))
Exemplo n.º 9
0
def render_all(entities, player, game_map, camera,
               fov_map, fov_recompute,
               message_log,
               sidebar_x, sidebar_width,
               panel_y, panel_height,
               screen_width, screen_height,
               game_state, mouse):
    camera.move_camera(player.x, player.y, game_map)
    if fov_recompute:
        create_window(0, 0, camera.width + 2, camera.height + 1)
        create_window(0, panel_y, camera.width + 2,
                      panel_height, 'MESSAGE LOG')
        create_window(sidebar_x, 0, sidebar_width, screen_height - 1,
                      'PLAYER STATS')
        names = get_names_under_mouse(mouse, entities, fov_map, camera)

        for y in range(camera.height):
            for x in range(camera.width):
                map_x = camera.x + x
                map_y = camera.y + y
                visible = tcod.map_is_in_fov(fov_map, map_x, map_y)
                wall = game_map.tiles[map_x][map_y].block_sight
                # print("map coord " + str(map_x) + ' ' + str(map_y))
                #
                if visible:
                    if wall:
                        blt.puts(x + 1, y + 1,
                                 '[font][color=light_wall][U+0023]')
                    else:
                        blt.puts(x + 1, y + 1,
                                 '[font][color=light_ground][U+002E]')
                    game_map.tiles[map_x][map_y].explored = True
                elif game_map.tiles[map_x][map_y].explored:
                    if wall:
                        blt.puts(x + 1, y + 1,
                                 '[font][color=dark_wall][U+0023]')
                    else:
                        blt.puts(x + 1, y + 1,
                                 '[font][color=dark_ground][U+002E]')

    # entities.append(entities.pop(0))

    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    for entity in entities_in_render_order:
        draw_entity(entity, camera, fov_map)
    # for y in range(camera.height):
    #     blt.puts(camera.width, y, '[color=white][U+2551]')
    # for x in range(camera.width):
    #     blt.puts(x, camera.height, '[color=white][U+2550]')
    # blt.puts(camera.width, camera.height, '[color=white][U+2569]')
    render_bar(sidebar_x + 1, 1, sidebar_width - 2, 'HP', player.fighter.hp,
               player.fighter.max_hp,
               'dark red', 'darkest red')
    y = 1
    for message in message_log.messages:
        # print(message.text)
        blt.color(message.color)
        blt.puts(message_log.x, panel_y + y, '[font=small]' + message.text)
        y += 1
    blt.color('white')
    if names:
        blt.clear_area(mouse[0] + 1, mouse[1], len(names), 1)
        blt.puts(mouse[0] + 1, mouse[1], names)

    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'
        else:
            inventory_title = 'Press the key next to an item to drop it'

        inventory_menu(inventory_title,
                       player.inventory,
                       50, screen_width, screen_height)
Exemplo n.º 10
0
def display_menu(options):
    terminal_set_color(255, colors.white)
    for o in options:
        terminal.puts(o[0], o[1], "[font=huge]" + o[2] + "[/font]")
    terminal.refresh()
Exemplo n.º 11
0
    def render(self):
        # No need to render endlessly
        # EDIT: Actually now I need it
        # if not self.re_render:
        #     return

        blt.clear()

        self.render_frames()
        # Gameboard related stuff
        blt.layer(0)

        # Coloring the different panels
        if DEBUG:
            for y in range(MESSAGE_PANEL.y, MESSAGE_PANEL.y + MESSAGE_PANEL.h):
                for x in range(MESSAGE_PANEL.x, MESSAGE_PANEL.x + MESSAGE_PANEL.w):
                    blt.bkcolor('green')
                    blt.put(x, y, ' ')

            for y in range(STATS_PANEL.y, STATS_PANEL.y + STATS_PANEL.h):
                for x in range(STATS_PANEL.x, STATS_PANEL.x + STATS_PANEL.w):
                    blt.bkcolor('blue')
                    blt.put(x, y, ' ')

            for y in range(STATS_ENEMY_PANEL.y, STATS_ENEMY_PANEL.y + STATS_ENEMY_PANEL.h):
                for x in range(STATS_ENEMY_PANEL.x, STATS_ENEMY_PANEL.x + STATS_ENEMY_PANEL.w):
                    blt.bkcolor('red')
                    blt.put(x, y, ' ')

            for y in range(BUTTONS_PANEL.y, BUTTONS_PANEL.y + BUTTONS_PANEL.h):
                for x in range(BUTTONS_PANEL.x, BUTTONS_PANEL.x + BUTTONS_PANEL.w):
                    blt.bkcolor('violet')
                    blt.put(x, y, ' ')


        # Board drawing
        for y, row in enumerate(self.gamemap.terrain):
            for x, tile in enumerate(row):
                blt.bkcolor(tile.color)
                blt.puts((x + self.map_offset.x) * TERRAIN_SCALE_X, (y + self.map_offset.y) * TERRAIN_SCALE_Y, '[font=terrain] [/font]')

        blt.layer(0)
        # Legal moves for current actors
        self.highlighted_cases = self.get_possible_movement(self.unit_turn)
        for highlight in self.highlighted_cases:
            color = 'turquoise'
            if highlight['valid'] == 'enemy':
                color = 'red'
            if highlight['valid'] == 'false':
                color = 'amber'
            blt.bkcolor(color)
            blt.puts((highlight['mov'].x + self.map_offset.x) * TERRAIN_SCALE_X,
                     (highlight['mov'].y + self.map_offset.y) * TERRAIN_SCALE_Y, '[font=terrain] [/font]')

        # Coordinates
        blt.bkcolor('black')

        # for y in range(10):
        #     blt.puts(0, (y + offset.y) * TERRAIN_SCALE_Y, f'[font=terrain]{str(y)}[/font]')
        #     blt.puts((self.gamemap.h + 1) * TERRAIN_SCALE_X, (y + offset.y) * TERRAIN_SCALE_Y, f'[font=terrain]{str(y)}[/font]')
        #     blt.puts((y + 1) * TERRAIN_SCALE_X, (offset.y - 1) * TERRAIN_SCALE_Y, f'[font=terrain]{chr(65 + y)}[/font]')
        #     blt.puts((y + 1) * TERRAIN_SCALE_X, (offset.y + self.gamemap.h) * TERRAIN_SCALE_Y, f'[font=terrain]{chr(65 + y)}[/font]')

        # actors
        blt.layer(2)
        # First, the daed actors, so that they are below the living ones
        # for actor in [a for a in self.actors if a.dead]:
        #     blt.color(actor.color)
        #     blt.puts((actor.x + self.map_offset.x) * TERRAIN_SCALE_X,
        #              (actor.y + self.map_offset.y) * TERRAIN_SCALE_Y, actor.charac)

        # Then the living ones
        for actor in [a for a in self.actors if not a.dead]:
            if actor.sprite:
                blt.put_ext((actor.x + self.map_offset.x) * TERRAIN_SCALE_X,
                            (actor.y + self.map_offset.y) * TERRAIN_SCALE_Y, 0, 0, actor.sprite)
            else:
                blt.color(actor.color)
                blt.puts(((actor.x + self.map_offset.x) * TERRAIN_SCALE_X),
                          (actor.y + self.map_offset.y) * TERRAIN_SCALE_Y, f'[offset={TERMINAL_CELL_SIZE_X/2},0]{actor.charac}[/offset]')

        # Text
        blt.layer(3)
        off_x = (self.gamemap.w + self.map_offset.x) * TERRAIN_SCALE_X
        off_y = (self.gamemap.h + self.map_offset.y) * TERRAIN_SCALE_Y
        blt.color('white')
        blt.bkcolor('black')
        self.render_stats(STATS_PANEL.x, STATS_PANEL.y, self.unit_turn)

        if self.under_mouse:
            self.render_stats(STATS_ENEMY_PANEL.x, STATS_ENEMY_PANEL.y, self.under_mouse)


        blt.puts(BUTTONS_PANEL.top_right.x - 8, BUTTONS_PANEL.top_right.y, 'End turn')

        if self.message_queue:
            blt.puts(MESSAGE_PANEL.x, MESSAGE_PANEL.y,
                     self.message_queue[-1], MESSAGE_PANEL.w, MESSAGE_PANEL.h, blt.TK_ALIGN_LEFT)

        self.re_render = False
Exemplo n.º 12
0
    def render_stats(self, x_base, y_base, unit):
        blt.puts(x_base, y_base, f'[font=text]{unit.perma_color} {unit.name}[/font]')

        blt.puts(x_base, y_base + 2, f"[font=text]HP: {unit.stats.mod['hp']}/{unit.stats.base['max_hp']}[/font]")

        blt.puts(x_base, y_base + 4, f"[font=text]Str: {unit.stats.mod['strength']}[/font]")
        blt.puts(x_base, y_base + 5, f"[font=text]Agi: {unit.stats.mod['agility']}[/font]")
        blt.puts(x_base, y_base + 6, f"[font=text]Int: {unit.stats.mod['intel']}[/font]")
        blt.puts(x_base, y_base + 7, f"[font=text]Def: {unit.stats.mod['defence']}[/font]")
Exemplo n.º 13
0
def test_dynamic_sprites():
    blt.set("window.title='Omni: dynamic sprites'")
    blt.set("U+E000: ../Media/Tiles.png, size=32x32, align=top-left")

    map_width = len(map_[0])
    map_height = len(map_)

    x0 = y0 = 0
    view_height, view_width = 10, 14
    minimap_scale = 4
    panel_width = (blt.state(blt.TK_WIDTH) - view_width * 4 - 1) * blt.state(
        blt.TK_CELL_WIDTH)
    margin = (panel_width - map_width * minimap_scale) // 2

    def draw_map():
        blt.color("white")
        for y in range(y0, y0 + view_height):
            for x in range(x0, x0 + view_width):
                code = map_[y][x]
                if code in palette:
                    s = palette[code]
                    blt.put((x - x0) * 4, (y - y0) * 2, 0xE000 + s.tile)

    def argb_from_color(col):
        return (col & 0xFF000000) >> 24, (col & 0xFF0000) >> 16, (
            col & 0xFF00) >> 8, col & 0xFF

    def blend_colors(one, two):
        a1, r1, g1, b1 = argb_from_color(one)
        a2, r2, g2, b2 = argb_from_color(two)
        f = a2 / 255
        r = int(r1 * (1 - f) + r2 * f)
        g = int(g1 * (1 - f) + g2 * f)
        b = int(b1 * (1 - f) + b2 * f)
        return blt.color_from_argb(a1, r, g, b)

    def make_minimap():
        minimap = [
            palette[code].color if code in palette else 0xFF000000
            for row in map_ for code in row
        ]

        for y in range(y0, y0 + view_height):
            for x in range(x0, x0 + view_width):
                minimap[y * map_width + x] = blend_colors(
                    minimap[y * map_width + x], 0x60FFFFFF)

        minimap = (c_uint32 * len(minimap))(*minimap)
        blt.set(
            "U+E100: %d, raw-size=%dx%d, resize=%dx%d, resize-filter=nearest" %
            (addressof(minimap), map_width, map_height, map_width * 4,
             map_height * 4))

    while True:
        blt.clear()

        draw_map()
        blt.color("light gray")
        for x in range(80):
            blt.put(x, view_height * 2, 0x2580)
        for y in range(view_height * 2):
            blt.put(view_width * 4, y, 0x2588)

        make_minimap()
        blt.color("white")
        blt.put_ext(view_width * 4 + 1, 0, margin, margin, 0xE100)

        blt.puts(
            1, view_height * 2 + 1,
            "[color=orange]Tip:[/color] use arrow keys to move viewport over the map"
        )

        blt.refresh()

        key = blt.read()

        if key in (blt.TK_CLOSE, blt.TK_ESCAPE):
            break
        elif key == blt.TK_RIGHT and x0 < map_width - view_width:
            x0 += 1
        elif key == blt.TK_LEFT and x0 > 0:
            x0 -= 1
        elif key == blt.TK_DOWN and y0 < map_height - view_height:
            y0 += 1
        elif key == blt.TK_UP and y0 > 0:
            y0 -= 1

    blt.set("U+E000: none; U+E100: none;")
Exemplo n.º 14
0
def test_tilesets():
    blt.set("window.title='Omni: tilesets'")
    blt.composition(True)

    # Load tilesets
    blt.set("U+E100: ../Media/Runic.png, size=8x16")
    blt.set("U+E200: ../Media/Tiles.png, size=32x32, align=top-left")
    blt.set(
        "U+E300: ../Media/fontawesome-webfont.ttf, size=24x24, spacing=3x2, codepage=../Media/fontawesome-codepage.txt"
    )
    blt.set(
        "zodiac font: ../Media/Zodiac-S.ttf, size=24x36, spacing=3x3, codepage=437"
    )

    blt.clear()
    blt.color("white")

    blt.puts(
        2, 1,
        "[color=orange]1.[/color] Of course, there is default font tileset.")

    blt.puts(
        2, 3,
        "[color=orange]2.[/color] You can load some arbitrary tiles and use them as glyphs:"
    )
    blt.puts(
        2 + 3, 4, "Fire rune ([color=red][U+E102][/color]), "
        "water rune ([color=lighter blue][U+E103][/color]), "
        "earth rune ([color=darker green][U+E104][/color])")

    blt.puts(
        2, 6,
        "[color=orange]3.[/color] Tiles are not required to be of the same size as font symbols:"
    )
    blt.put(2 + 3 + 0, 7, 0xE200 + 7)
    blt.put(2 + 3 + 5, 7, 0xE200 + 8)
    blt.put(2 + 3 + 10, 7, 0xE200 + 9)

    blt.puts(
        2, 10,
        "[color=orange]4.[/color] Like font characters, tiles may be freely colored and combined:"
    )
    blt.put(2 + 3 + 0, 11, 0xE200 + 8)
    blt.color("lighter orange")
    blt.put(2 + 3 + 5, 11, 0xE200 + 8)
    blt.color("orange")
    blt.put(2 + 3 + 10, 11, 0xE200 + 8)
    blt.color("dark orange")
    blt.put(2 + 3 + 15, 11, 0xE200 + 8)

    blt.color("white")
    order = [11, 10, 14, 12, 13]
    for i in range(len(order)):
        blt.put(30 + i * 4, 11, 0xE200 + order[i])
        blt.put(30 + (len(order) + 1) * 4, 11, 0xE200 + order[i])

    blt.put(30 + len(order) * 4, 11, 0xE200 + 15)

    blt.puts(
        2, 14,
        "[color=orange]5.[/color] And tiles can even come from TrueType fonts like this:"
    )
    for i in range(6):
        blt.put(5 + i * 5, 15, 0xE300 + i)

    blt.puts(5, 18, "...or like this:\n[font=zodiac]D F G S C")

    blt.refresh()

    key = None
    while key not in (blt.TK_CLOSE, blt.TK_ESCAPE):
        key = blt.read()

    # Clean up
    blt.set("U+E100: none; U+E200: none; U+E300: none; zodiac font: none")
    blt.composition(False)
Exemplo n.º 15
0
def test_manual_cellsize():
    blt.set("window.title='Omni: manual cellsize'")

    font_name = "../Media/VeraMono.ttf"
    font_hintings = ["normal", "autohint", "none"]
    font_hinting = 0
    font_size = 12
    cell_width = 8
    cell_height = 16

    def setup_font():
        blt.set("font: %s, size=%d, hinting=%s" %
                (font_name, font_size, font_hintings[font_hinting]))

    def setup_cellsize():
        blt.set("window: cellsize=%dx%d" % (cell_width, cell_height))

    setup_cellsize()
    setup_font()

    while True:
        blt.clear()
        blt.color("white")

        blt.puts(2, 1, "Hello, world!")
        blt.puts(2, 3, "[color=orange]Font size:[/color] %d" % font_size)
        blt.puts(
            2, 4, "[color=orange]Font hinting:[/color] %s" %
            font_hintings[font_hinting])
        blt.puts(
            2, 5, "[color=orange]Cell size:[/color] %dx%d" %
            (cell_width, cell_height))
        blt.puts(
            2, 7,
            "[color=orange]TIP:[/color] Use arrow keys to change cell size")
        blt.puts(
            2, 8,
            "[color=orange]TIP:[/color] Use Shift+Up/Down arrow keys to change font size"
        )
        blt.puts(
            2, 9,
            "[color=orange]TIP:[/color] Use TAB to switch font hinting mode")

        blt.refresh()

        key = blt.read()

        if key in (blt.TK_CLOSE, blt.TK_ESCAPE):
            break
        elif key == blt.TK_LEFT and not blt.state(
                blt.TK_SHIFT) and cell_width > 4:
            cell_width -= 1
            setup_cellsize()
        elif key == blt.TK_RIGHT and not blt.state(
                blt.TK_SHIFT) and cell_width < 24:
            cell_width += 1
            setup_cellsize()
        elif key == blt.TK_DOWN and not blt.state(
                blt.TK_SHIFT) and cell_height < 24:
            cell_height += 1
            setup_cellsize()
        elif key == blt.TK_UP and not blt.state(
                blt.TK_SHIFT) and cell_height > 4:
            cell_height -= 1
            setup_cellsize()
        elif key == blt.TK_UP and blt.state(blt.TK_SHIFT) and font_size < 64:
            font_size += 1
            setup_font()
        elif key == blt.TK_DOWN and blt.state(blt.TK_SHIFT) and font_size > 4:
            font_size -= 1
            setup_font()
        elif key == blt.TK_TAB:
            font_hinting = (font_hinting + 1) % len(font_hintings)
            setup_font()

    blt.set("font: default; window.cellsize=auto")
Exemplo n.º 16
0
def main_menu():
    """Main main for this game"""

    t.layer(0)
    set_colour(colours.white, 100)
    t.put(0, 0, 0x5E)
    #show the game's title, and some credits!

    title = 'Death and Axes'
    center = (SCREEN_WIDTH - len(title)) // 2

    t.layer(UI_LAYER)
    set_colour(colours.dark_azure, 150)
    t.puts(center - 1, SCREEN_HEIGHT // 2 - 5,
           BLOCK_CHAR * (len(title) + 2) * 3,
           len(title) + 2, 3)

    t.layer(UI_TEXT_LAYER)
    set_colour(colours.light_yellow)
    t.puts(center, SCREEN_HEIGHT // 2 - 4, title)

    title = 'By Cerepol'
    center = (SCREEN_WIDTH - len(title)) // 2

    t.layer(UI_LAYER)
    set_colour(colours.dark_azure, 150)
    t.puts(center - 1, SCREEN_HEIGHT - 3,
           BLOCK_CHAR * (len(title) + 2) * 3,
           len(title) + 2, 3)

    t.layer(UI_TEXT_LAYER)
    set_colour(colours.light_yellow)
    t.puts(center, SCREEN_HEIGHT - 2, title)

    t.refresh()
    t.delay(2000)
    t.layer(0)

    while True:
        t.clear()
        set_colour(colours.white, 100)
        t.put(0, 0, 0x5E)
        t.refresh()

        choice = menu(
            '', ['Start a new Adventure', 'Continue Previous game', 'Quit'],
            22)

        if choice == 0:
            new_game()
            play_game()

        elif choice == 1:
            try:
                load_game()
            except:
                msgbox('\n No saved game to load.\n', 24)
                continue
            play_game()

        elif choice == 2:
            break

    t.close()
Exemplo n.º 17
0
def render_all():
    """Goes through object list and renders everything"""
    global fov_recompute
    global visible_tiles

    if fov_recompute:
        fov_recompute = False
        visible_tiles = quickFOV(player.x,
                                 player.y,
                                 gmap.is_visible_tile,
                                 fov=FOV_ALGO,
                                 radius=TORCH_RADIUS,
                                 lightWalls=FOV_LIGHT_WALLS,
                                 sphere=False)

        #Set to the background layer before drawing the area
        t.layer(BASE_LAYER)

        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                set_colour(colours.black, 255)
                visible = (x, y) in visible_tiles
                wall = gmap.Map[x][y].block_sight
                if not visible:
                    if gmap.Map[x][y].explored:
                        if wall:
                            set_colour(colours.darkest_gray, 255)
                        else:
                            set_colour(colours.darker_gray, 255)

                else:
                    if wall:
                        set_colour(colours.gray, 255)
                    else:
                        set_colour(colours.light_gray, 255)

                    #add visible tile as explored
                    gmap.Map[x][y].explored = True
                #Draw the character on the map
                t.put(x, y, BLOCK_CHAR)

    t.layer(OBJECT_LAYER)
    for obj in objects:
        if obj != player:
            obj.draw()
    for stair in stairs:
        stair.draw()
    player.draw()

    #GUI Panel cleared for redraw
    #panel.clear(fg=colours.white, bg=colours.black)

    #Print out all game messages
    t.layer(UI_TEXT_LAYER)
    t.clear_area(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)

    y = PANEL_Y
    for (line, colour) in game_msgs:
        set_colour(colour)
        t.puts(MSG_X, y, line)
        #panel.draw_str(MSG_X, y, line, bg=None, fg=colour)
        y += 1

    #Contents under mouse
    set_colour(colours.light_gray)
    t.puts(1, PANEL_Y - 1, get_names_under_mouse())

    #Statbar
    render_bar(1, PANEL_Y, BAR_WIDTH, 'HP', player.fighter.hp,
               player.fighter.max_hp, colours.dark_red, colours.darker_red)

    t.refresh()
Exemplo n.º 18
0
def draw_entity(entity, camera, fov_map):
    x, y = camera.to_camera_coordinates(entity.x, entity.y)
    blt.color(entity.color)
    if x in range(camera.width) and y in range(camera.height):
        if tcod.map_is_in_fov(fov_map, entity.x, entity.y):
            blt.puts(x + 1, y + 1, entity.char)
Exemplo n.º 19
0
def draw_UI():

    HeaderHeight = 4
    HeaderWidth = map_width
    HeaderFrameColor = "blue"
    #draw header frame
    for x in range(0, HeaderWidth + 1):
        for y in range(0, HeaderHeight):
            if x == 0 and y == 0:
                blt.puts(x, y, "[color=%s]╒[/color]" % HeaderFrameColor)
            elif x == 0 and y == HeaderHeight - 1:
                blt.puts(x, y, "[color=%s]╘[/color]" % HeaderFrameColor)
            elif x == HeaderWidth and y == 0:
                blt.puts(x, y, "[color=%s]╤[/color]" % HeaderFrameColor)
            elif x == HeaderWidth and y == HeaderHeight - 1:
                blt.puts(x, y, "[color=%s]╡[/color]" % HeaderFrameColor)
            elif x == 0 or x == HeaderWidth:
                blt.puts(x, y, "[color=%s]│[/color]" % HeaderFrameColor)
            elif y == 0 or y == HeaderHeight - 1:
                blt.puts(x, y, "[color=%s]═[/color]" % HeaderFrameColor)

    blt.puts(1, 1, "[color=%s]%s[/color]" % ("orange", player.name))
    blt.puts(1, 2, "[color=%s]%s[/color]" % ("darker orange", TurnCount))
    blt.puts(
        len(player.name) + 8, 1,
        "[color=%s]Health: %s[/color]" % ("green", player.Health))
    blt.puts(
        len(player.name) + 20, 1,
        "[color=%s]Life Support: %s[/color]" % ("yellow", player.LifeSupport))
    blt.puts(
        len(player.name) + 40, 1,
        "[color=%s]Aiming: %s[/color]" % ("red", Aiming))
    blt.puts(
        len(player.name) + 60, 1,
        "[color=%s]Angst: %s[/color]" % ("purple", player.angst))

    MsgFrameHeight = screen_height
    MsgFrameWidth = 20
    MsgFrameColor = "blue"
    #draw header frame
    for x in range(0, MsgFrameWidth):
        for y in range(0, MsgFrameHeight):
            if x == 0 and y == 0:
                blt.puts(x + HeaderWidth, y,
                         "[color=%s]╤[/color]" % MsgFrameColor)
            elif x == 0 and y == MsgFrameHeight - 1:
                blt.puts(x + HeaderWidth, y,
                         "[color=%s]╘[/color]" % MsgFrameColor)
            elif x == MsgFrameWidth - 1 and y == 0:
                blt.puts(x + HeaderWidth, y,
                         "[color=%s]╕[/color]" % HeaderFrameColor)
            elif x == MsgFrameWidth - 1 and y == MsgFrameHeight - 1:
                blt.puts(x + HeaderWidth, y,
                         "[color=%s]╛[/color]" % HeaderFrameColor)
            elif x == 0 and y == HeaderHeight - 1:
                blt.puts(x + HeaderWidth, y,
                         "[color=%s]╡[/color]" % HeaderFrameColor)
            elif x == 0 or x == MsgFrameWidth - 1:
                blt.puts(x + HeaderWidth, y,
                         "[color=%s]│[/color]" % HeaderFrameColor)
            elif y == 0 or y == MsgFrameHeight - 1:
                blt.puts(x + HeaderWidth, y,
                         "[color=%s]═[/color]" % HeaderFrameColor)

    #blt.puts(0, 0, "[color=%s]╒══════════════════════════════════════════════════════════════════════════════╕[/color]" % ("darker orange"))

    #can they see layers?
    #print(len(items_present))
    if player.CanSenseLayers or len(items_present) == 0:
        blt.puts(
            len(player.name) + 8, 2,
            "[color=%s]Here: %s[/color]" % ("blue", items_present_str))
    elif not player.CanSenseLayers:
        blt.puts(
            len(player.name) + 8, 2,
            "[color=%s]Here: %s[/color]" % ("blue", items_present[0].name))

    y = 1
    for message in message_log.messages:
        blt.puts(map_width + 1, y,
                 "[color=%s]%s[/color]" % (message.color, message.text))
        y += 1
Exemplo n.º 20
0
def render(player, gm):
    terminal.clear()
    p = player.avatar

    if player.camera.flash:
        if player.camera.flash_counter < player.camera.flash_frames:
            terminal.layer(3)
            for y in range(player.camera.height):
                for x in range(player.camera.width):
                    gui.terminal_set_color(player.camera.flash_alpha,
                                           colors.white)
                    terminal.put(x*4, y*2, 0xE500)
            player.camera.flash_counter += 1
            player.camera.flash_fade()
        else:
            player.camera.flash_deactivate()

    #calculate field of view for all rendering below
    #if map.fov_recompute:
        #map.fov_recompute = False

    ''' Set visible and maximum view distance '''
    visible_tiles = tdl.map.quickFOV(p.x, p.y, p.current_map.is_visible_tile,
                                     fov=player.fov_algo,
                                     radius=player.sight_radius,
                                     lightWalls=player.fov_light_walls)

    player.visible = visible_tiles

    max_visible = tdl.map.quickFOV(p.x, p.y, p.current_map.is_visible_tile,
                                   fov=player.fov_algo, radius=10,
                                   lightWalls=player.fov_light_walls)

    light_source_tiles = []
    lit_tiles = []

    ''' Render Object Layer '''
    terminal.layer(2)
    for o in p.current_map.objects:
        if o.light_source:
            for x, y in o.light_source.tiles_lit:
                # visible_tiles.add((x, y))
                lit_tiles.append((x, y))
                light_source_tiles.append((x, y, o.light_source.color))
            if (o.x, o.y) in max_visible:
                gui.terminal_set_color(255, o.light_source.color)
                o.draw(player.camera)

        else:
            if (o.x, o.y) in max_visible and (o.x, o.y) in lit_tiles:
                o.draw(player.camera)

            if (o.x, o.y) in visible_tiles:
                o.draw(player.camera)

    if p.inventory.weapon is not None:
        if not p.inventory.weapon.ranged:
            if p.attack is not None and p.fighter.power_meter < 20:
                if p.inventory.weapon.active:
                    for tgt_x, tgt_y in p.inventory.weapon.attack_tiles:
                        att_key = p.get_direction(tgt_x, tgt_y)
                        weapon_x, weapon_y = player.camera.to_camera_coordinates(tgt_x, tgt_y)
                        terminal.put(weapon_x*4, weapon_y*2,
                                     p.inventory.weapon.attack_icons[att_key])
        else:
            if p.attack is not None:
                pass

    for effect in p.current_map.effects:
        if effect.active:
            for ex, ey, hit in effect.aoe:
                ex2, ey2 = player.camera.to_camera_coordinates(ex, ey)
                if hit:
                    terminal.put(ex2*4, ey2*2, effect.icons['hit'])
                else:
                    terminal.put(ex2*4, ey2*2, effect.icons[p.attack])

    if p.inventory.weapon is not None:
        if p.fighter.power_meter >= 20:
            p.attack = None
            p.attack_direction = None
            p.inventory.weapon.active = False

    ''' Render Map Layer '''
    terminal.layer(1)
    camera_x = 1
    camera_y = 1

    gui.separator_box(0, 0, player.camera.width*4, player.camera.height*2,
                      colors.white)

    ''' Render Primary Vision '''
    gui.terminal_set_color(255, colors.light_blue)
    for y in range(camera_x, player.camera.height):
        for x in range(camera_y, player.camera.width):
            tx, ty = player.camera.offset(x, y)
            visible = (tx, ty) in visible_tiles
            if not p.current_map.out_of_bounds(tx, ty):
                tile = p.current_map.tiles[tx][ty]
                if not visible:
                    if p.current_map.tiles_explored[tx][ty] == 1:
                        terminal.put(x*4, y*2,
                                   maps.terrain_types[tile].icon_unseen)
                    else:
                        terminal.put(x*4, y*2, 0xE050)
                else:
                    terminal.put(x*4, y*2, maps.terrain_types[tile].icon_seen)
                    p.current_map.tiles_explored[tx][ty] = 1
            else:
                terminal.put(x*4, y*2, 0xE050)

    ''' Render Light Effects '''
    for y in range(player.camera.height):
        for x in range(player.camera.width):
            vx, vy = player.camera.offset(x, y)
            in_max_visible_range = (vx, vy) in max_visible
            #print(light_source_tiles)
            if in_max_visible_range:
                for lx, ly, lcolor in light_source_tiles:
                    tile = p.current_map.tiles[vx][vy]
                    if lx == vx and ly == vy:
                        d = int(round(p.distance_to_square(lx, ly)))
                        a = objects.distance_to_alpha[d]
                        terminal.layer(4)
                        gui.tile_dimmer(x, y, a)
                        terminal.layer(1)
                        gui.terminal_set_color(255, lcolor)
                        terminal.put(x*4, y*2,
                                     maps.terrain_types[tile].icon_seen)

    ''' Render GUI '''
    terminal.layer(0)
    terminal.color("white")

    right_panel_x = player.camera.width * 4
    right_panel_y = 1
    right_panel_width = (terminal.state(terminal.TK_WIDTH) -
                         player.camera.width*4)
    right_panel_height = (terminal.state(terminal.TK_HEIGHT) -
                         player.camera.height*2)

    bottom_panel_x = 1
    bottom_panel_y = (player.camera.height * 2) + 1
    bottom_panel_width = terminal.state(terminal.TK_WIDTH) - right_panel_width
    bottom_panel_height = terminal.state(terminal.TK_HEIGHT) - bottom_panel_y

    h = terminal.state(terminal.TK_HEIGHT)
    w = terminal.state(terminal.TK_WIDTH)

    # Player Name
    gui.separator_box(right_panel_x, 0, right_panel_width, 2, colors.white)

    terminal.puts(right_panel_x + 2, right_panel_y, player.name.capitalize(),
                  right_panel_width-4, 1, terminal.TK_ALIGN_TOP |
                  terminal.TK_ALIGN_CENTER)

    # HP Bar
    gui.separator_box(right_panel_x, right_panel_y+1, right_panel_width, 2,
                      colors.white)
    gui.render_bar(right_panel_x + 2, right_panel_y + 2, right_panel_width-4,
                   'HP', p.fighter.hp, p.fighter.max_hp, colors.red,
                   colors.darker_red, "Health: " + str(p.fighter.hp) + "/" +
                   str(p.fighter.max_hp))

    # Stamina Bar
    gui.separator_box(right_panel_x, right_panel_y + 3, right_panel_width, 2,
                      colors.white)
    gui.render_bar(right_panel_x + 2, right_panel_y + 4, right_panel_width-4,
                   'attack power', p.fighter.power_meter, 100,
                   colors.orange, colors.darker_orange, "Stamina")

    # Mana Bar
    gui.separator_box(right_panel_x, right_panel_y + 5, right_panel_width, 2,
                      colors.white)
    gui.render_bar(right_panel_x + 2, right_panel_y + 6, right_panel_width-4,
                   'mana', 30, 30, colors.dark_blue, colors.darker_blue, "Mana")


    # Weapon, Spell & Armor #
    gui.separator_box(right_panel_x, right_panel_y+7, right_panel_width, 15,
                      colors.white, title="Inventory")

    inventory_x = right_panel_x + 2
    inventory_y = right_panel_y + 10

    # Current Weapon
    if p.inventory.slots['w'].active:
        gui.highlight_box(inventory_x, inventory_y, p.inventory, 'w',
                          colors.yellow)
    else:
        gui.highlight_box(inventory_x, inventory_y, p.inventory, 'w',
                          colors.black)
    terminal.puts(inventory_x + 6, inventory_y + 1, "Strength: " +
                  str(p.fighter.power))

    # Equipped Spell
    if p.inventory.slots['s'].active:
        gui.highlight_box(inventory_x, inventory_y + 3, p.inventory, 's',
                          colors.yellow)
    else:
        gui.highlight_box(inventory_x, inventory_y + 3, p.inventory, 's',
                          colors.black)

    gui.terminal_reset_color()

    terminal.puts(inventory_x + 6, inventory_y + 4,
                  p.inventory.get_item_name('s'))

    # Defense Icon
    terminal.put(inventory_x + 2, inventory_y + 7, 0xE300)
    terminal.puts(inventory_x + 6, inventory_y + 7, "Defense: " +
                  str(p.fighter.defense))

    # Belt Slots #
    gui.separator_box(right_panel_x, right_panel_y+22, right_panel_width,
                      21, colors.white, title="Belt")

    terminal.puts(right_panel_x + 2, right_panel_y + 26, "1")
    gui.render_box(right_panel_x + 4, right_panel_y + 25,
                   p.inventory, 'a')

    terminal.puts(right_panel_x + 2, right_panel_y + 29, "2")
    gui.render_box(right_panel_x + 4, right_panel_y + 28,
                   p.inventory, 'b')

    terminal.puts(right_panel_x + 2, right_panel_y + 32, "3")
    gui.render_box(right_panel_x + 4, right_panel_y + 31,
                   p.inventory, 'c')

    terminal.puts(right_panel_x + 2, right_panel_y + 35, "4")
    gui.render_box(right_panel_x + 4, right_panel_y + 34,
                   p.inventory, 'd')

    terminal.puts(right_panel_x + 2, right_panel_y + 38, "5")
    gui.render_box(right_panel_x + 4, right_panel_y + 37,
                   p.inventory, 'e')

    gui.separator_box(0, bottom_panel_y-1, w-right_panel_width, 7, colors.white)
    msg_line = 1
    for line, msg_color in log.game_messages:
        gui.terminal_set_color(255, msg_color)
        terminal.puts(bottom_panel_x+1, bottom_panel_y+msg_line-1, line)
        msg_line += 1

    gui.terminal_set_color(255, colors.white)

    gui.separator_box(right_panel_x, bottom_panel_y-1, right_panel_width,
                      7, colors.white)

    terminal.puts(right_panel_x, bottom_panel_y+2, "Player Position: " +
                  p.current_position, right_panel_width, 1,
                  terminal.TK_ALIGN_MIDDLE | terminal.TK_ALIGN_CENTER)

    terminal.puts(right_panel_x, bottom_panel_y+3, "Cursor Position: (" +
                  str(player.mouse_x) + "," + str(player.mouse_y) + ')',
                  right_panel_width,
                  1, terminal.TK_ALIGN_TOP | terminal.TK_ALIGN_CENTER)

    terminal.refresh()
Exemplo n.º 21
0
def clear_entity(entity):
    # erase the character that represents this object
    blt.puts(entity.x, entity.y, " ")
Exemplo n.º 22
0
    def draw(self):
        #if self.dirty:
        mouse = Input.mouse

        if self.owner:
            layer = self.owner.layer
            x = self.owner.pos.x
            y = self.owner.pos.y
        else:
            layer = terminal.state(terminal.TK_LAYER)
            x = 0
            y = 0
        terminal.layer(layer)

        if self.hover:
            if self.pressed:
                terminal.color('darkest grey')
                terminal.puts(x + self.x, y + self.y, "[U+2584]" * self.length)
                terminal.puts(x + self.x, y + self.y + 1,
                              "[U+2588]" * self.length)
                terminal.puts(x + self.x, y + self.y + 2,
                              "[U+2580]" * self.length)
                terminal.color('darker grey')
                terminal.puts(x + self.x, y + self.y + 1,
                              str(self.text).center(self.length, " "))
                self.clicked = True
                #return self.function()
            terminal.color(self.back)
            terminal.puts(x + self.x, y + self.y, "[U+2584]" * self.length)
            terminal.puts(x + self.x, y + self.y + 1, "[U+2588]" * self.length)
            terminal.puts(x + self.x, y + self.y + 2, "[U+2580]" * self.length)
            terminal.color(self.fore)
            terminal.puts(x + self.x, y + self.y + 1,
                          str(self.text).center(self.length, " "))
        else:
            terminal.color(self.back_alt)
            terminal.puts(x + self.x, y + self.y, "[U+2584]" * self.length)
            terminal.puts(x + self.x, y + self.y + 1, "[U+2588]" * self.length)
            terminal.puts(x + self.x, y + self.y + 2, "[U+2580]" * self.length)
            terminal.color(self.fore_alt)
            terminal.puts(x + self.x, y + self.y + 1,
                          str(self.text).center(self.length, " "))
            self.dirty = False
Exemplo n.º 23
0
Arquivo: fps.py Projeto: dbaker84/RL2
        if Aiming:
            if (key == blt.TK_LEFT):
                TargetX -= 1
            elif (key == blt.TK_RIGHT):
                TargetX += 1
            elif (key == blt.TK_UP):
                TargetY -= 1
            elif (key == blt.TK_DOWN):
                TargetY += 1
            elif (key == blt.TK_F):
                Aiming = True
            elif (key == blt.TK_ESCAPE):
                Aiming = False
        else:
            if (key == blt.TK_LEFT):
                pass

    if IncrementTurn:
        TurnCount += 1
        # entities try to randomly move
        for ent in entities:
            pass

    #items_present = update_items_present()
    #items_present_str = update_items_present_str()
    blt.puts(0, 0, "%s" % fps_value)
    # render_all(entities, gamemap)
    blt.refresh()
    #TickCount += 1
Exemplo n.º 24
0
def draw_entity(entity):
    blt.puts(entity.x, entity.y,
             "[color=%s]%s[/color]" % (entity.color, entity.char))
Exemplo n.º 25
0
    def draw_game_over(self):
        terminal.clear()

        terminal.bkcolor(0xFF000000)
        terminal.color(0xFFFFFFFF)

        buffer = []

        for _, player in self.world.get_component(Player):
            if player.killer:
                buffer.extend([
                    "[color=#FFFF0000]Defeat[/color]",
                    "",
                    "",
                    f"You were killed by {player.killer} on level {player.level + 1} of the dungeon.",
                ])
            else:
                buffer.extend([
                    "[color=#FFFF0000]Victory![/color]",
                    "",
                    "",
                    ("[color=#FF999999]With the milita defeated, you can finally put your feet up and read your"
                     " newspaper. But you lost it somewhere in the dungeon...[/color]"
                     ),
                ])

            buffer.append("")

            if not player.kills:
                buffer.append("You didn[U+2019]t kill anyone.")
            else:
                buffer.extend([
                    f"You killed {sum(player.kills.values())} enemies:",
                    "",
                ])

                # Generate kill strings from Counter
                items = sorted(player.kills.items())

                kills = []
                for i, (key, value) in enumerate(items):
                    plural = "s" if value > 1 else ""
                    kills.append(f"{value} {key}{plural}")

                if len(kills) % 2:
                    kills.append("")

                for one, two in zip(kills[::2], kills[1::2]):
                    buffer.append(f"{one.ljust(24)}  {two.ljust(24)}")

        buffer.extend([
            "",
            "",
            "Press [color=#FFFF0000](z)[/color] and [color=#FF0000FF](x)[/color] to return.",
        ])

        terminal.puts(
            x=8,
            y=1,
            s="\n".join(buffer),
            width=68,
            height=19,
            align=terminal.TK_ALIGN_CENTER,
        )

        terminal.refresh()
Exemplo n.º 26
0
    def draw(self):
        if self.dirty and self.expanded:
            for i, item in enumerate(self.items):
                color = self.colors['COLOR']
                bkcolor = self.colors['BKCOLOR']
                if i == self.hover_index:
                    color = self.colors['HOVER']
                    bkcolor = self.colors['BKHOVER']
                if i == self.selected_index:
                    color = self.colors['SELECTED']
                    bkcolor = self.colors['BKSELECTED']

                if bkcolor is not None:
                    terminal.puts(
                        self.x + self.owner.pos.x,
                        self.y + self.owner.pos.y + i,
                        "[c={0}]".format(bkcolor) + str("[U+2588]" *
                                                        (self.length + 1)))
                terminal.puts(self.x + self.owner.pos.x,
                              self.y + self.owner.pos.y + i,
                              "[c={0}]{2}".format(color, bkcolor, item))

            if self.collapse:
                bkcolor = self.colors['SELECTED']
                terminal.puts(self.x + self.owner.pos.x + self.length,
                              self.y + self.owner.pos.y,
                              "[c={0}]".format(bkcolor) + str("[U+2588]"))
                terminal.puts(self.x + self.owner.pos.x + self.length,
                              self.y + self.owner.pos.y,
                              "[c={0}]".format(color) + str("[U+25BC]"))
            self.dirty = False
        if self.dirty and not self.expanded:

            color = self.colors['COLOR']
            bkcolor = self.colors['BKCOLOR']

            i = self.selected_index

            if bkcolor is not None:
                terminal.puts(
                    self.x + self.owner.pos.x, self.y + self.owner.pos.y,
                    "[c={0}]".format(bkcolor) + str("[U+2588]" * self.length))
            if self.selected_index is not None:
                item = self.items[i]
                terminal.puts(self.x + self.owner.pos.x,
                              self.y + self.owner.pos.y,
                              "[c={0}]{2}".format(color, bkcolor, item))

            if self.collapse:
                bkcolor = self.colors['BKCOLOR']
                terminal.puts(self.x + self.owner.pos.x + self.length,
                              self.y + self.owner.pos.y,
                              "[c={0}]".format(bkcolor) + str("[U+2588]"))
                terminal.puts(self.x + self.owner.pos.x + self.length,
                              self.y + self.owner.pos.y,
                              "[c={0}]".format(color) + str("[U+25B2]"))

            self.dirty = False
Exemplo n.º 27
0
def render_obj(coords, dic, camera, color):
    cam_x, cam_y = camera.to_camera_coordinates(coords[0], coords[1])
    map_x, map_y = coords
    blt.color(color)
    blt.puts(cam_x, cam_y, dic.get((map_x, map_y)).char)
    blt.color('white')
Exemplo n.º 28
0
def show_msg_history(message_log, name, viewport_w, viewport_h):
    messages = MessageList()
    frame = FrameWithScrollbar(messages)
    message_log.reverse()

    for message in message_log:
        messages.append(message.msg)

    # Initial update
    frame.update_geometry(padding_left + 1, padding_top,
                          viewport_w + 5 - (padding_left + padding_right),
                          viewport_h - (padding_top + padding_bottom))

    prompt = \
        "Message history: \n"

    if name == "Inventory":
        prompt = \
            "Inventory: \n"

    while True:

        frame.draw()
        blt.color("white")

        blt.layer(0)
        w = viewport_w
        h = viewport_h
        i = 0
        while i < 5:
            blt.layer(i)
            blt.clear_area(1, 1, w, h)
            i += 1
        current_line = 0
        blt.puts(padding_left, padding_top - frame.offset, prompt, frame.width)
        for text, height in messages:
            if current_line + height >= frame.offset:
                # stop when message is below frame
                if current_line - frame.offset > frame.height:
                    break
                # drawing message
                blt.puts(padding_left,
                         padding_top + current_line - frame.offset + 5, text,
                         frame.width)
            current_line += height + 1

        blt.crop(padding_left, padding_top, frame.width, frame.height)

        # Render
        blt.refresh()

        key = blt.read()

        if key in (blt.TK_CLOSE, blt.TK_ESCAPE, blt.TK_M):
            blt.clear()
            break

        elif key == blt.TK_I and name == "Inventory":
            blt.clear()
            break

        elif key == blt.TK_UP:
            frame.scroll(-1)

        elif key == blt.TK_DOWN:
            frame.scroll(1)

        elif key == blt.TK_RESIZED:
            frame.update_geometry(
                padding_left, padding_top,
                blt.state(blt.TK_WIDTH) - (padding_left + padding_right + 1),
                blt.state(blt.TK_HEIGHT) - (padding_top + padding_bottom))