aboutsummaryrefslogtreecommitdiff
path: root/dc/dc.c
blob: 942174b8c551b08807683aad8c4737001cf4b617 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <stdio.h>

#include <teensy.h>
#include <math.h>
#include <time.h>

#define QOI_IMPLEMENTATION
#include "third/qoi.h"

#define SCREEN_WIDTH 256
#define SCREEN_HEIGHT 256

#define TILE_SIZE 16

int main(void)
{
    struct ty_hints hints = {
        .scr_width = SCREEN_WIDTH,
        .scr_height = SCREEN_HEIGHT,
        .game_title = "Demonchime",
        .ticrate = 30,
    };
    ty_init(hints);

    qoi_desc desc;
    void *data = qoi_read("test_img.qoi", &desc, 3);
    if (!data)
        ty_log_fatal(TY_ERR_IO, "Failed to read image");
    struct ty_image img = ty_create_image(desc.width, desc.height, data);
    free(data);

    while (ty_is_game_running()) {
        clock_t start = clock();

        ty_draw_clear(TY_COLOR_BLACK);

        for (int y = 0; y < SCREEN_HEIGHT; y += 16) {
            for (int x = 0; x < SCREEN_WIDTH; x += 16) {
                ty_draw_image(img, ty_vec2i(x, y));
            }
        }

        ty_draw_rect(
            (struct ty_recti){
                SCREEN_WIDTH*0.5 + sin(ty_get_time() * 10) * 50 - 25,
                SCREEN_HEIGHT*0.5-25,
                50, 50,
            },
            TY_COLOR_RED
        );

        ty_draw_line(
            ty_vec2i(0, 0),
            ty_vec2i(100, 100),
            ty_color(0xFF, 0xF0, 0x80)
        );

        ty_draw_line(
            ty_vec2i(100, 0),
            ty_vec2i(0, 100),
            ty_color(0x80, 0xF0, 0xFF)
        );

        ty_draw_line(
            ty_vec2i(150, 0),
            ty_vec2i(150, 100),
            ty_color(0x80, 0xF0, 0xFF)
        );

        ty_draw_line(
            ty_vec2i(100, 50),
            ty_vec2i(200, 50),
            ty_color(0xFF, 0xF0, 0x80)
        );

        ty_draw_end();
        ty_tick();

        ty_sleep(1000 / hints.ticrate);

        ty_log_debug("%g ms", (float)(clock() - start) / CLOCKS_PER_SEC);
    }

    ty_free_image(img);

    ty_deinit();
    return 0;
}