diff --git a/inc/lzy.h b/inc/lzy.h index 560ad8c..3b7ae59 100644 --- a/inc/lzy.h +++ b/inc/lzy.h @@ -246,6 +246,29 @@ int LZY_DrawChar(unsigned char chr, int x, int y) { #endif } +int LZY_DrawText(const char *text, int x, int y) { +#ifndef LZY_GINT_FONT + LZY_UNUSED(text); + LZY_UNUSED(x); + LZY_UNUSED(y); + return -1; +#else + int err = 0; + + if (text == NULL) + return -1; + + for (; *text != '\0'; text++) { + const int rc = LZY_DrawChar(*text, x, y); + if (rc) + err = rc - 1; + x += LZY_CHR_WIDTH; + } + + return err; +#endif +} + void LZY_CycleEvents(void) { clearevents(); should_quit = should_quit || keydown(KEY_EXIT); @@ -535,6 +558,24 @@ int LZY_DrawChar(unsigned char chr, int x, int y) { return 0; } +int LZY_DrawText(const char *text, int x, int y) { + int err = 0; + + if (text == NULL) { + error = "text is NULL"; + return -1; + } + + for (; *text != '\0'; text++) { + const int rc = LZY_DrawChar(*text, x, y); + if (rc) + err = rc - 1; + x += LZY_CHR_WIDTH; + } + + return err; +} + void LZY_CycleEvents(void) { static const SDL_Scancode sc[LZYK_COUNT] = { SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_UP, diff --git a/src/main.c b/src/main.c index 9ed25a7..5bb42f1 100644 --- a/src/main.c +++ b/src/main.c @@ -36,6 +36,7 @@ int main(void) { { LZY_DrawSetColor(0x20, 0x20, 0x00); LZY_DrawClear(); + LZY_DrawText("HELLOWO!", 0, 0); draw_player(x, y); } LZY_DrawEnd(); @@ -47,6 +48,6 @@ int main(void) { } static void draw_player(int x, int y) { - if (LZY_DrawTile(4, x, y)) + if (LZY_DrawTile(14, x, y)) LZY_Log(LZY_GetError()); }