81 lines
1.6 KiB
C
81 lines
1.6 KiB
C
#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, char **argv) {
|
|
int x = 0;
|
|
int y = 0;
|
|
int w = 4;
|
|
int h = 4;
|
|
|
|
(void)argc;
|
|
(void)argv;
|
|
|
|
if (LZY_Init("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_X)) {
|
|
if (LZY_KeyDown(LZYK_LEFT))
|
|
w -= speed;
|
|
if (LZY_KeyDown(LZYK_RIGHT))
|
|
w += speed;
|
|
if (LZY_KeyDown(LZYK_UP))
|
|
h -= speed;
|
|
if (LZY_KeyDown(LZYK_DOWN))
|
|
h += speed;
|
|
} else {
|
|
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());
|
|
if (LZY_DrawRect(x, y, w, h))
|
|
LZY_Log(LZY_GetError());
|
|
|
|
LZY_DrawTextF(0, 0, "%d ; %d", x, y);
|
|
}
|
|
LZY_DrawEnd();
|
|
}
|
|
|
|
LZY_Log("cya");
|
|
LZY_Quit();
|
|
|
|
return 0;
|
|
}
|