summaryrefslogtreecommitdiff
path: root/src/main.c
blob: ff51bb36c74fc2d5858cbfe8435d18176c27d284 (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
#include "lzr.h"
#include "cfg.h"
#include "game.h"
#include <stdio.h>
#include <stdlib.h>

static Game *game = NULL;

static void deinit(void);

int
main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
{
	if (LZR_Init(cfg)) {
		LZR_Quit();
		return 1;
	}

	if (atexit(deinit)) {
		perror("main:atexit");
		deinit();
		return 1;
	}

	if ((game = malloc(sizeof(*game))) == NULL) {
		perror("main:malloc");
		return 1;
	}
	game_init(game);

	while (!LZR_ShouldQuit()) {
		LZR_CycleEvents();
		game_update(game);

		LZR_DrawBegin();
		LZR_DrawSetColor(0, 0, 0, 0);
		LZR_DrawClear();
		game_draw(game);
		LZR_DrawEnd();
	}
	return 0;
}

static void
deinit(void)
{
	if (game != NULL)
		free(game);
	LZR_Quit();
}