lzy/src/main.c

96 lines
1.8 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-02-28 21:47:26 +01:00
static void draw_player(int x, int y);
2022-03-07 14:56:34 +01:00
int main(int argc, const char **argv) {
2022-03-02 00:16:38 +01:00
LZY_Music *music;
LZY_Sound *sound;
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-02-28 16:26:59 +01:00
LZY_Log(LZY_GetError());
LZY_Quit();
2022-02-28 15:38:08 +01:00
return 1;
2022-02-28 16:26:59 +01:00
}
LZY_Log("init was great success!");
2022-02-28 15:38:08 +01:00
2022-03-02 00:16:38 +01:00
sound = LZY_SoundLoad("res/sound.wav");
music = LZY_MusicLoad("res/music.ogg");
LZY_SoundPlay(sound, 0);
LZY_MusicPlay(music, 0);
2022-02-28 15:38:08 +01:00
do {
2022-03-06 02:58:07 +01:00
static const int speed = 16;
LZY_Event e;
2022-03-02 23:32:07 +01:00
2022-03-06 02:58:07 +01:00
while (LZY_PollEvent(&e)) {
switch (e.type) {
case LZY_QUIT:
LZY_Log("get back");
break;
case LZY_KEYDOWN:
LZY_Log("under pressure");
switch (e.u.key.scancode) {
case LZYK_LEFT:
x -= speed;
break;
case LZYK_RIGHT:
x += speed;
break;
case LZYK_UP:
y -= speed;
break;
case LZYK_DOWN:
y += speed;
break;
};
break;
case LZY_KEYUP:
LZY_Log("let it be");
break;
}
}
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
{
LZY_DrawSetColor(0x20, 0x20, 0x00);
LZY_DrawClear();
2022-03-01 15:29:34 +01:00
LZY_DrawText("HELLOWO!", 0, 0);
2022-02-28 21:47:26 +01:00
draw_player(x, y);
}
2022-02-28 18:01:06 +01:00
LZY_DrawEnd();
2022-02-28 16:26:59 +01:00
} while (!LZY_ShouldQuit());
2022-02-28 15:38:08 +01:00
2022-03-02 00:16:38 +01:00
LZY_MusicDestroy(music);
LZY_SoundDestroy(sound);
2022-02-28 16:26:59 +01:00
LZY_Log("cya");
LZY_Quit();
return 0;
2022-02-28 15:38:08 +01:00
}
2022-02-28 21:47:26 +01:00
static void draw_player(int x, int y) {
2022-03-02 23:32:07 +01:00
const int cx = x + 8;
const int cy = y + 8;
2022-03-06 02:58:07 +01:00
int i;
2022-03-02 23:32:07 +01:00
2022-03-01 15:29:34 +01:00
if (LZY_DrawTile(14, x, y))
2022-03-01 01:54:20 +01:00
LZY_Log(LZY_GetError());
2022-03-02 23:32:07 +01:00
LZY_DrawSetColor(0x00, 0xff, 0xff);
2022-03-06 02:58:07 +01:00
for (i = 0; i < 128; i++) {
LZY_DrawSetColor(0x00, i * 2, i * 2);
LZY_DrawLine(i + 140, 0, cx, cy);
LZY_DrawLine(i + 140, 223, cx, cy);
}
2022-02-28 21:47:26 +01:00
}