simplify example
This commit is contained in:
parent
041e836873
commit
3ff9240636
87
src/main.c
87
src/main.c
|
@ -6,11 +6,9 @@
|
|||
#define LZY_FIRST_CHR ' '
|
||||
#include "lzy.h"
|
||||
|
||||
static void draw_player(int x, int y);
|
||||
static const int speed = 4;
|
||||
|
||||
int main(int argc, const char **argv) {
|
||||
LZY_Music *music;
|
||||
LZY_Sound *sound;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
|
@ -20,76 +18,41 @@ int main(int argc, const char **argv) {
|
|||
LZY_Quit();
|
||||
return 1;
|
||||
}
|
||||
LZY_Log("init was great success!");
|
||||
LZY_Log("initialisation was a success!");
|
||||
|
||||
sound = LZY_SoundLoad("res/sound.wav");
|
||||
music = LZY_MusicLoad("res/music.ogg");
|
||||
LZY_SoundPlay(sound, 0);
|
||||
LZY_MusicPlay(music, 0);
|
||||
while (!LZY_ShouldQuit()) {
|
||||
/* update */
|
||||
LZY_CycleEvents();
|
||||
|
||||
do {
|
||||
static const int speed = 16;
|
||||
LZY_Event e;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
/* 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();
|
||||
{
|
||||
LZY_DrawSetColor(0x20, 0x20, 0x00);
|
||||
/* clear screen */
|
||||
LZY_DrawSetColor(0, 0, 0);
|
||||
LZY_DrawClear();
|
||||
LZY_DrawText("HELLOWO!", 0, 0);
|
||||
draw_player(x, y);
|
||||
|
||||
/* draw yellow line between player and topleft corner */
|
||||
LZY_DrawSetColor(255, 255, 0);
|
||||
LZY_DrawLine(x, y, 0, 0);
|
||||
|
||||
/* draw player */
|
||||
LZY_DrawTile(1, 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;
|
||||
int i;
|
||||
|
||||
if (LZY_DrawTile(14, x, y))
|
||||
LZY_Log(LZY_GetError());
|
||||
|
||||
LZY_DrawSetColor(0x00, 0xff, 0xff);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue