diff options
author | kdx <kikoodx@paranoici.org> | 2023-03-04 21:04:29 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-03-04 21:04:29 +0100 |
commit | 02388bd54e91491e0e357d889209ed67eafb57fc (patch) | |
tree | b5d65ace08fc44710b5cf6e706e9fac3785bfcc7 | |
parent | 5a9826a6fbfdda92e653c43a32f24ba87d40cf48 (diff) | |
download | 7drl2023-02388bd54e91491e0e357d889209ed67eafb57fc.tar.gz |
clearly a roguelike
-rw-r--r-- | dialog.c | 28 | ||||
-rw-r--r-- | dialog.h | 5 | ||||
-rw-r--r-- | font.c | 33 | ||||
-rw-r--r-- | font.h | 2 | ||||
-rw-r--r-- | main.c | 13 |
5 files changed, 69 insertions, 12 deletions
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 <stdio.h> + +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); @@ -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); } @@ -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); @@ -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; |