From 02388bd54e91491e0e357d889209ed67eafb57fc Mon Sep 17 00:00:00 2001 From: kdx Date: Sat, 4 Mar 2023 21:04:29 +0100 Subject: clearly a roguelike --- dialog.c | 28 ++++++++++++++++++++++++++++ dialog.h | 5 +++++ font.c | 33 +++++++++++++++++++++++++++++---- font.h | 2 +- main.c | 13 ++++++------- 5 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 dialog.c create mode 100644 dialog.h diff --git a/dialog.c b/dialog.c new file mode 100644 index 0000000..814bbc1 --- /dev/null +++ b/dialog.c @@ -0,0 +1,28 @@ +#include "dialog.h" +#include "font.h" +#include "TZR.h" +#include + +static const char *___dialog; +static int ___cursor; + +void dialog_set(const char *s) +{ + ___dialog = s; +} + +void dialog_update(void) +{ + if (TZR_GetTick() % 8) + return; + if (___dialog[___cursor] == '\0') + return; + ___cursor += 1; + if (___dialog[___cursor] >= 'A' && ___dialog[___cursor] <= 'Z') + return dialog_update(); +} + +void dialog_draw(void) +{ + font_draw(0, 0, ___dialog, ___cursor); +} diff --git a/dialog.h b/dialog.h new file mode 100644 index 0000000..531b7f0 --- /dev/null +++ b/dialog.h @@ -0,0 +1,5 @@ +#pragma once + +void dialog_set(const char *s); +void dialog_update(void); +void dialog_draw(void); diff --git a/font.c b/font.c index 7c4abd4..1f6d7e5 100644 --- a/font.c +++ b/font.c @@ -11,12 +11,37 @@ int font_init(const char *path) return 0; } -void font_draw(int x, int y, const char *s) +void font_draw(int x, int y, const char *s, int size) { - for (; *s != '\0'; s++) { + const int ox = x; + TZR_DrawSetColor(1, 1, 1, 1); + for (; *s != '\0' && size > 0; s++, size--) { const int ix = *s % 16 * 8; const int iy = *s / 16 * 16; - TZR_DrawImage(___font_spr, x*8, y*16, ix, iy, 8, 16); - x += 1; + switch (*s) { + case '\n': + y += 1; + x = ox; + break; + case 'R': + TZR_DrawSetColor(1, 0, 0); + break; + case 'G': + TZR_DrawSetColor(0, 1, 0); + break; + case 'B': + TZR_DrawSetColor(0, 0, 1); + break; + case 'W': + TZR_DrawSetColor(1, 1, 1); + break; + default: + TZR_DrawImage(___font_spr, x*8, y*16, ix, iy, 8, 16); + x += 1; + break; + } } + TZR_DrawSetColor(1, 1, 1); + if (TZR_GetTick() / 30 % 2) + TZR_DrawRectangle(true, x*8, y*16+1, 1, 14); } diff --git a/font.h b/font.h index 8dfe4b0..52de1aa 100644 --- a/font.h +++ b/font.h @@ -1,4 +1,4 @@ #pragma once int font_init(const char *path); -void font_draw(int x, int y, const char *s); +void font_draw(int x, int y, const char *s, int size); diff --git a/main.c b/main.c index fe90511..5af031d 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,6 @@ #include "TZR.h" #include "font.h" +#include "dialog.h" static int init(void); static void deinit(void); @@ -19,18 +20,16 @@ int main(int argc, char **argv) return 1; } + dialog_set("yo Rboi\nByou WcoolR!"); + while (!TZR_ShouldQuit()) { TZR_CycleEvents(); + dialog_update(); TZR_DrawBegin(); TZR_DrawSetColor(0, 0, 0, 1); TZR_DrawClear(); - TZR_DrawSetColor(1, 1, 1); - font_draw(2, 3, "coucou"); - TZR_DrawSetColor(1, 0, 1); - font_draw(3, 4, "69"); - TZR_DrawSetColor(0, 0, 1); - font_draw(4, 5, "( n i c e )"); + dialog_draw(); TZR_DrawEnd(); } return 0; @@ -38,7 +37,7 @@ int main(int argc, char **argv) static int init(void) { - if (TZR_Init(.target_fps=30, .pixel_perfect=false, .title="7DRL 2023")) + if (TZR_Init(.pixel_perfect=false, .title="7DRL 2023")) return 1; if (font_init("res/font.png")) return 1; -- cgit v1.2.3