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
|
#include <time.h>
#include "player.h"
static int _main_loop(void *udata);
static float
randf(void)
{
return 10000. / (float)(rand() % 10000);
}
int
main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
{
srand(time(nullptr));
defer(wdeinit);
config_init();
defer(config_deinit);
world_init("res/world/world.csv", "res/world/%d.csv");
defer(world_deinit);
g_world.x = world_find_cell(2).x;
g_world.y = world_find_cell(2).y;
player_init();
assert(TZR_Init(.interlace=true,
.width=640,
.height=640,
.ratio=4/3.,
.basepath=argv[1],
.pixel_perfect=true,
.target_fps=60) == 0);
defer(TZR_Quit);
input_new_action("action");
input_bind_action_mb("action", SDL_BUTTON_LEFT);
input_bind_action_mb("action", SDL_BUTTON_RIGHT);
input_bind_action_mb("action", SDL_BUTTON_MIDDLE);
input_bind_action_sc("action", SDL_SCANCODE_SPACE);
input_bind_action_sc("action", SDL_SCANCODE_J);
input_bind_action_cb("action", SDL_CONTROLLER_BUTTON_A);
input_bind_action_cb("action", SDL_CONTROLLER_BUTTON_B);
input_bind_action_cb("action", SDL_CONTROLLER_BUTTON_X);
input_bind_action_cb("action", SDL_CONTROLLER_BUTTON_Y);
TZR_MainLoop(_main_loop, nullptr);
return 0;
}
static int
_main_loop([[maybe_unused]] void *udata)
{
player_update();
assert(TZR_DrawBegin() == 0);
if (rand() % 10 == 0) {
int r; do r = rand(); while ((r & 7) == 0);
TZR_DrawSetColor(r & 1, (r & 2) != 0, (r & 4) != 0);
TZR_DrawClear();
TZR_PlaySound(TZR_RES("res/rain.wav"));
TZR_DrawSetColor(0, 0, 0);
if (rand() % 128) {
TZR_DrawImage(TZR_RES("res/title.bmp"),
___tzr_config.width / 2 + 255 - rand() % 512,
___tzr_config.height / 2 + 255 - rand() % 512,
.center=true,
.sx=randf() * 2,
.sy=randf() * 2,
.r=randf(),
.flip_x=(rand()%3)==0,
.flip_y=(rand()%3)==0);
} else {
TZR_DrawImage(TZR_RES("res/death.bmp"),
___tzr_config.width / 2,
___tzr_config.height / 2,
.center=true,
.sx=1.0+randf()*.1,
.sy=1.0+randf()*.1);
}
world_draw();
player_draw();
} else {
TZR_DrawSetColor(0, 0, 0);
TZR_DrawClear();
}
assert(TZR_DrawEnd() == 0);
return 0;
}
|