aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKikooDX <kikoodx@paranoici.org>2022-03-01 15:29:34 +0100
committerKikooDX <kikoodx@paranoici.org>2022-03-01 15:29:34 +0100
commit898e738e3e8b0672ea1bc227cc6fdc57decda01e (patch)
tree4f9d448579443c53f023f42841feedf502102507
parent7054e477300a012d0e0dd6a0b8dfb7c20699559e (diff)
downloadlzy-898e738e3e8b0672ea1bc227cc6fdc57decda01e.tar.gz
font string draw
-rw-r--r--inc/lzy.h41
-rw-r--r--src/main.c3
2 files changed, 43 insertions, 1 deletions
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());
}