Exemplo n.º 1
0
def test_drawing_draw_box_negative_dim():
    buffer = Buffer(3, 3)
    draw_box(buffer, 1, 1, -1, 1, chars=_BOX_CHARS_TEST)
    assert_buffer_matches(
        buffer,
        "   ",
        "   ",
        "   "
    )
Exemplo n.º 2
0
def test_drawing_draw_box_one_tall():
    buffer = Buffer(5, 3)
    draw_box(buffer, 1, 1, 3, 1, chars=_BOX_CHARS_TEST)
    assert_buffer_matches(
        buffer,
        "     ",
        " ttt ",
        "     "
    )
Exemplo n.º 3
0
def test_drawing_draw_box_one_wide():
    buffer = Buffer(3, 5)
    draw_box(buffer, 1, 1, 1, 3, chars=_BOX_CHARS_TEST)
    assert_buffer_matches(
        buffer,
        "   ",
        " l ",
        " l ",
        " l ",
        "   "
    )
Exemplo n.º 4
0
def test_drawing_draw_box():
    buffer = Buffer(5, 5)
    draw_box(buffer, 1, 1, 3, 3, chars=_BOX_CHARS_TEST)
    assert_buffer_matches(
        buffer,
        "     ",
        " AtB ",
        " l r ",
        " CbD ",
        "     "
    )
Exemplo n.º 5
0
    def update():
        nonlocal inner_w, inner_h
        app.screen.clear()
        inner_buffer.clear()

        # compute inner dimensions of box
        inner_w = app.screen.w - outer_pad * 2 - 2
        inner_h = app.screen.h - outer_pad * 2 - 2
        inner_buffer.resize(inner_w, inner_h)

        # draw a box with a title
        draw_box(app.screen, outer_pad, outer_pad, inner_w + 2, inner_h + 2, chars=BOX_CHARS_LIGHT_DOUBLE_TOP)
        title = "Hello drawing"
        app.screen.print(title, app.screen.w // 2 - len(title) // 2, outer_pad)

        # draw spinners
        inner_buffer.print("Inner header ", 0, 0)
        draw_spinner(inner_buffer, *inner_buffer.print_pos, freq=2, fg=GREEN)
        inner_buffer.print(" ")
        draw_spinner(inner_buffer, *inner_buffer.print_pos, freq=2, fg=GREY, frames=SPINNER_PIPE)
        inner_buffer.print(" ")
        draw_spinner(inner_buffer, *inner_buffer.print_pos, freq=2, fg=GREY, frames=SPINNER_CLOCK)
        inner_buffer.print(" ")
        draw_spinner(inner_buffer, *inner_buffer.print_pos, freq=2, t=math.sin(time.perf_counter()), fg=YELLOW, frames=SPINNER_MOON)
        inner_buffer.print(" ")
        draw_spinner(inner_buffer, *inner_buffer.print_pos, freq=1, fg=WHITE, frames=SPINNER_DOTS)

        # draw a horizontal line along x=2 within the box
        draw_hline(inner_buffer, 2, fg=GREY)

        # print some word-wrapped text inside the box
        inner_buffer.print(wrap_text(LIPSUM, inner_w), 0, 3, fg=YELLOW)

        # progress bar
        draw_progress(inner_buffer, 0, inner_buffer.print_pos[1] + 2,
                      w=inner_buffer.w // 3,
                      progress=math.sin(time.perf_counter()) * 0.5 + 0.5,
                      fg=BRIGHT_YELLOW,
                      bg=GREY,
                      **PROGRESS_SMOOTH)

        # draw a color bitmap at 2x vertical resolution
        draw_colormap_2x(inner_buffer, SMILEY, 2, inner_buffer.h - 3 - 2, w=7, h=7)

        # copy box contents to screen
        app.screen.blit(inner_buffer, outer_pad + 1, outer_pad + 1)
        app.screen.update()
Exemplo n.º 6
0
    def frame_game():
        nonlocal control_x, control_y
        nonlocal score, hiscore
        nonlocal mode
        
        # handle input
        if control_x != 0 and not worm.intersecting(worm.x + control_x, worm.y):
            worm.vx = control_x
            worm.vy = 0
            control_x = 0
        if control_y != 0 and not worm.intersecting(worm.x, worm.y + control_y):
            worm.vy = control_y
            worm.vx = 0
            control_y = 0

        if worm.intersecting(food_x, food_y):
            score += 1
            worm.length += 1
            hiscore = max(hiscore, score)
            save_hiscore(hiscore)
            move_food()
        
        game_buffer.clear()
        game_buffer.print("░░", food_x * 2, food_y)

        try:
            worm.update(game_buffer)
        except GameOver:
            mode = MODE_GAMEOVER
            multiply_buffer(game_buffer, 0.4)
            return
        
        # draw
        app.screen.clear()
        app.screen.print("~TermWorm~", 0, 0)
        app.screen.print("Score: {}".format(score), 0, 1, fg=Color.rgb(.7,.7,.7))
        app.screen.print("  Hi: {}".format(hiscore), fg=Color.rgb(.7,.7,0))
        draw_box(app.screen, 0, 2, app.screen.w, 1, chars=BOX_CHARS_DOUBLE)
        app.screen.blit(game_buffer, 0, ui_height)
        app.screen.update()