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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
static void _setup_input();
static int _main_loop(void *udata);
#define map(X) extern const Tiled2cMap m##X##_tmj; g_push_map(&m##X##_tmj);
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv) {
defer(wdeinit);
defer(input_deinit);
_setup_input();
assert(TZR_Init(.width=cfg.display_width,
.height=cfg.display_height,
.scale=3,
.target_fps=cfg.fps,
.mixer=0,
.basepath=argv[1]) == 0);
defer(TZR_Quit);
TZR_ToggleFullscreen();
g_init();
map(0);
map(1);
map(2);
map(3);
map(upndown);
map(worldmap);
//map(beat);
//map(game);
//map(somewhere);
g_spawn_entities();
TZR_MainLoop(_main_loop, nullptr);
return 0;
}
static void _setup_input() {
input_new_action("left");
input_bind_action_sc("left", SDL_SCANCODE_A);
input_bind_action_sc("left", SDL_SCANCODE_LEFT);
input_bind_action_cb("left", SDL_CONTROLLER_BUTTON_DPAD_LEFT);
input_new_action("right");
input_bind_action_sc("right", SDL_SCANCODE_D);
input_bind_action_sc("right", SDL_SCANCODE_RIGHT);
input_bind_action_cb("right", SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
input_new_action("up");
input_bind_action_sc("up", SDL_SCANCODE_W);
input_bind_action_sc("up", SDL_SCANCODE_UP);
input_bind_action_cb("up", SDL_CONTROLLER_BUTTON_DPAD_UP);
input_new_action("down");
input_bind_action_sc("down", SDL_SCANCODE_S);
input_bind_action_sc("down", SDL_SCANCODE_DOWN);
input_bind_action_cb("down", SDL_CONTROLLER_BUTTON_DPAD_DOWN);
input_new_action("jump");
input_bind_action_sc("jump", SDL_SCANCODE_J);
input_bind_action_sc("jump", SDL_SCANCODE_SPACE);
input_bind_action_cb("jump", SDL_CONTROLLER_BUTTON_A);
input_bind_action_cb("jump", SDL_CONTROLLER_BUTTON_B);
input_new_action("reset");
input_bind_action_sc("reset", SDL_SCANCODE_R);
input_bind_action_cb("reset", SDL_CONTROLLER_BUTTON_LEFTSHOULDER);
input_bind_action_cb("reset", SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
input_new_axis("move x");
input_bind_axis_act("move x", "left", "right");
input_bind_axis_gc("move x", SDL_CONTROLLER_AXIS_LEFTX);
input_new_axis("move y");
input_bind_axis_act("move y", "up", "down");
input_bind_axis_gc("move y", SDL_CONTROLLER_AXIS_LEFTY);
}
static int _main_loop([[maybe_unused]] void *udata) {
g_update();
if (TZR_IsKeyPressed(SDL_SCANCODE_ESCAPE) ||
TZR_IsKeyPressed(SDL_SCANCODE_CAPSLOCK))
return 1;
assert(TZR_DrawBegin() == 0);
TZR_DrawSetColor(1, 1, 1);
TZR_DrawClear();
vec2 v = v2(cfg.tile_width, 0);
const f32 r = (float)(TZR_GetTick() % 768) / 256;
TZR_BlendMode(SDL_BLENDMODE_MUL);
{
setbgcolor(1, 1, 1);
setfgcolor(0, 0, 0);
g_draw(0, 0);
}
{
vec2 c = v2_round(v2_transform(v, m3_rotating(r / 0.1592)));
setbgcolor(1, 1, 1);
setfgcolor(0, 1, 1);
g_draw(c.x, c.y);
}
{
vec2 c = v2_round(v2_transform(v, m3_rotating((r + 0.333) / 0.1592)));
setbgcolor(1, 1, 1);
setfgcolor(1, 0, 1);
g_draw(c.x, c.y);
}
{
vec2 c = v2_round(v2_transform(v, m3_rotating((r + 0.666) / 0.1592)));
setbgcolor(1, 1, 1);
setfgcolor(1, 1, 0);
g_draw(c.x, c.y);
}
TZR_BlendMode(SDL_BLENDMODE_BLEND);
assert(TZR_DrawEnd() == 0);
return 0;
}
|