lzy/src/main.c

64 lines
1.2 KiB
C
Raw Normal View History

2022-02-28 15:38:08 +01:00
#define LZY_IMPLEMENTATION
2022-03-01 01:54:20 +01:00
#define LZY_GINT_TILESET bimg_tset
2022-03-01 15:13:35 +01:00
#define LZY_GINT_FONT bimg_font
#define LZY_CHR_WIDTH 16
#define LZY_CHR_HEIGHT 16
#define LZY_FIRST_CHR ' '
2022-02-28 15:38:08 +01:00
#include "lzy.h"
2022-03-10 21:14:59 +01:00
static const int speed = 4;
2022-02-28 21:47:26 +01:00
2022-03-07 14:56:34 +01:00
int main(int argc, const char **argv) {
2022-02-28 21:47:26 +01:00
int x = 0;
int y = 0;
2022-02-28 18:01:06 +01:00
2022-03-07 14:56:34 +01:00
if (LZY_Init(argc, argv, "lzy example", 30, "res/tset.png",
"res/font.png")) {
2022-04-12 11:58:12 +02:00
LZY_Log("LZY_Init failed: %s", LZY_GetError());
2022-02-28 16:26:59 +01:00
LZY_Quit();
2022-02-28 15:38:08 +01:00
return 1;
2022-02-28 16:26:59 +01:00
}
2022-03-10 21:14:59 +01:00
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;
2022-02-28 18:01:06 +01:00
2022-02-28 21:47:26 +01:00
/* draw */
2022-02-28 18:01:06 +01:00
LZY_DrawBegin();
2022-02-28 21:47:26 +01:00
{
2022-03-10 21:14:59 +01:00
/* clear screen */
LZY_DrawSetColor(0, 0, 0);
2022-02-28 21:47:26 +01:00
LZY_DrawClear();
2022-03-10 21:14:59 +01:00
/* draw yellow line between player and topleft corner */
LZY_DrawSetColor(255, 255, 0);
LZY_DrawLine(x, y, 0, 0);
/* draw player */
2022-03-27 14:56:31 +02:00
if (LZY_DrawTileEx(1, x, y, 3, 2))
LZY_Log(LZY_GetError());
if (LZY_DrawTile(1, x, y))
LZY_Log(LZY_GetError());
2022-04-12 11:58:12 +02:00
LZY_DrawTextF(0, 0, "%d ; %d", x, y);
2022-02-28 21:47:26 +01:00
}
2022-02-28 18:01:06 +01:00
LZY_DrawEnd();
2022-03-10 21:14:59 +01:00
}
2022-03-02 00:16:38 +01:00
2022-02-28 16:26:59 +01:00
LZY_Log("cya");
LZY_Quit();
2022-02-28 21:47:26 +01:00
2022-03-10 21:14:59 +01:00
return 0;
2022-02-28 21:47:26 +01:00
}