aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
blob: 008bb840f6afdee4692ca7feb5e20d9124803e6d (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
#define LZY_IMPLEMENTATION
#define LZY_GINT_TILESET bimg_tset
#define LZY_GINT_FONT    bimg_font
#define LZY_CHR_WIDTH    16
#define LZY_CHR_HEIGHT   16
#define LZY_FIRST_CHR    ' '
#include "lzy.h"

static const int speed = 4;

int main(int argc, const char **argv) {
	int x = 0;
	int y = 0;

	if (LZY_Init(argc, argv, "lzy example", 30, "res/tset.png",
	             "res/font.png")) {
		LZY_Log("LZY_Init failed: %s", LZY_GetError());
		LZY_Quit();
		return 1;
	}
	LZY_Log("initialisation was a success!");

	while (!LZY_ShouldQuit()) {
		/* update */
		LZY_CycleEvents();

		/* move player */
		if (LZY_KeyDown(LZYK_LEFT))
			x -= speed;
		if (LZY_KeyDown(LZYK_RIGHT))
			x += speed;
		if (LZY_KeyDown(LZYK_UP))
			y -= speed;
		if (LZY_KeyDown(LZYK_DOWN))
			y += speed;

		/* draw */
		LZY_DrawBegin();
		{
			/* clear screen */
			LZY_DrawSetColor(0, 0, 0);
			LZY_DrawClear();

			/* draw yellow line between player and topleft corner */
			LZY_DrawSetColor(255, 255, 0);
			LZY_DrawLine(x, y, 0, 0);

			/* draw player */
			if (LZY_DrawTileEx(1, x, y, 3, 2))
				LZY_Log(LZY_GetError());
			if (LZY_DrawTile(1, x, y))
				LZY_Log(LZY_GetError());

			LZY_DrawTextF(0, 0, "%d ; %d", x, y);
		}
		LZY_DrawEnd();
	}

	LZY_Log("cya");
	LZY_Quit();

	return 0;
}