lzy/src/main.c

75 lines
1.5 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 void draw_player(int x, int y);
int main(void) {
LZY_Music *music;
LZY_Sound *sound;
int x = 0;
int y = 0;
if (LZY_Init("lzy example", 30, "res/tset.png", "res/font.png")) {
LZY_Log(LZY_GetError());
LZY_Quit();
return 1;
}
LZY_Log("init was great success!");
sound = LZY_SoundLoad("res/sound.wav");
music = LZY_MusicLoad("res/music.ogg");
LZY_SoundPlay(sound, 0);
LZY_MusicPlay(music, 0);
do {
const int speed = 2;
/* update */
LZY_CycleEvents();
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();
{
LZY_DrawSetColor(0x20, 0x20, 0x00);
LZY_DrawClear();
LZY_DrawText("HELLOWO!", 0, 0);
draw_player(x, y);
}
LZY_DrawEnd();
} while (!LZY_ShouldQuit());
LZY_MusicDestroy(music);
LZY_SoundDestroy(sound);
LZY_Log("cya");
LZY_Quit();
return 0;
}
static void draw_player(int x, int y) {
const int cx = x + 8;
const int cy = y + 8;
if (LZY_DrawTile(14, x, y))
LZY_Log(LZY_GetError());
LZY_DrawSetColor(0x00, 0xff, 0xff);
LZY_DrawLine(0, 0, cx - 1, cy - 1);
LZY_DrawLine(395, 0, cx, cy - 1);
LZY_DrawLine(0, 223, cx - 1, cy);
LZY_DrawLine(395, 223, cx, cy);
}