aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-06-21 22:42:28 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-06-21 22:42:28 +0100
commitb4c2ff850930cb29da1a331b17fcc8a9e561b5ff (patch)
treee3b5a6c0d4a4454cc13afc8cc72bdc1e476e8569 /src
parentd3c44c1472ab23a8ea37cc63f3f9f8678b0a6af5 (diff)
downloadgold-mine-run-b4c2ff850930cb29da1a331b17fcc8a9e561b5ff.tar.gz
gold-mine-run-b4c2ff850930cb29da1a331b17fcc8a9e561b5ff.zip
Add color text
Diffstat (limited to 'src')
-rw-r--r--src/game.c12
-rw-r--r--src/menu.c10
-rw-r--r--src/text.c4
-rw-r--r--src/text.h2
-rw-r--r--src/vga.c19
-rw-r--r--src/vga.h2
6 files changed, 35 insertions, 14 deletions
diff --git a/src/game.c b/src/game.c
index b5968ce..80c5a42 100644
--- a/src/game.c
+++ b/src/game.c
@@ -36,32 +36,32 @@ static void hud_render()
/* lives */
blitrc(binary_sprites_start, &src, &dst);
- put_text(136, 4, "TIME");
- put_text(249, 4, "STAGE");
+ put_text(136, 4, "TIME", 1);
+ put_text(249, 4, "STAGE", 1);
}
if (hud & HUD_LIVES)
{
sprintf(b, "%d", lives);
- put_text(18, 4, b);
+ put_text(18, 4, b, 1);
}
if (hud & HUD_SCORE)
{
sprintf(b, "%06li", score);
- put_text(34, 4, b);
+ put_text(34, 4, b, 1);
}
if (hud & HUD_TIME)
{
sprintf(b, "%02d", time);
- put_text(176, 4, b);
+ put_text(176, 4, b, time > 10 ? 1 : 15);
}
if (hud & HUD_STAGE)
{
sprintf(b, "%02d", stage + 1);
- put_text(297, 4, b);
+ put_text(297, 4, b, 1);
}
hud = HUD_CLEAN;
diff --git a/src/menu.c b/src/menu.c
index c95416f..a74568e 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -9,17 +9,17 @@ uint8_t run_menu()
{
blit_erase(0);
- put_text(124, 10, "HI 000000");
+ put_text(124, 10, "HI 000000", 5);
Rect dst = { 80, 45, 160, 38 };
blit(binary_title_start, &dst);
- put_text(84, 110, "PRESS SPACE TO PLAY");
+ put_text(84, 110, "PRESS SPACE TO PLAY", 1);
- put_text(64, 140, "CODE, GRAPHICS AND SOUND");
- put_text(96, 150, "JUAN J. MARTINEZ");
+ put_text(64, 140, "CODE, GRAPHICS AND SOUND", 2);
+ put_text(96, 150, "JUAN J. MARTINEZ", 3);
- put_text(96, 180, "_2023 USEBOX.NET");
+ put_text(96, 180, "_2023 USEBOX.NET", 1);
wait_vsync();
blit_update();
diff --git a/src/text.c b/src/text.c
index c59b5e6..4ec4c54 100644
--- a/src/text.c
+++ b/src/text.c
@@ -3,13 +3,13 @@
#include "vga.h"
#include "data.h"
-void put_text(uint16_t x, uint16_t y, const char *text)
+void put_text(uint16_t x, uint16_t y, const char *text, uint8_t color)
{
Rect dst = { x, y, 8, 8};
while (*text)
{
- blit(binary_font_start + ((*text++ - ' ') << 6), &dst);
+ blit_c(binary_font_start + ((*text++ - ' ') << 6), &dst, color);
dst.x += 8;
}
}
diff --git a/src/text.h b/src/text.h
index c43b199..de9b567 100644
--- a/src/text.h
+++ b/src/text.h
@@ -1,6 +1,6 @@
#ifndef _TEXT_H
#define _TEXT_H
-void put_text(uint16_t x, uint16_t y, const char *text);
+void put_text(uint16_t x, uint16_t y, const char *text, uint8_t color);
#endif /* _TEXT_H */
diff --git a/src/vga.c b/src/vga.c
index cb2c5a8..83ee2c7 100644
--- a/src/vga.c
+++ b/src/vga.c
@@ -101,6 +101,25 @@ void blit(const uint8_t *sprite, const Rect *dst)
}
}
+void blit_c(const uint8_t *sprite, const Rect *dst, uint8_t c)
+{
+ for (int32_t j = dst->y * 320; j < (dst->y + dst->h) * 320; j += 320)
+ for (int16_t i = dst->x; i < dst->x + dst->w; i++)
+ {
+ uint8_t b = *sprite++;
+
+ /* transparent */
+ if (b == TRANSPARENT)
+ continue;
+
+ /* clipping */
+ if (i < 0 || i >= 320 || j < 0 || j >= 200 * 320)
+ continue;
+
+ buffer[i + j] = b ? c : b;
+ }
+}
+
void blitrc(const uint8_t *sprite, const Rect *src, const Rect *dst)
{
for (int32_t j = dst->y * 320, sy = src->y * src->w; j < (dst->y + dst->h) * 320; j += 320, sy += src->w)
diff --git a/src/vga.h b/src/vga.h
index e6642f7..7bd5779 100644
--- a/src/vga.h
+++ b/src/vga.h
@@ -21,6 +21,8 @@ void wait_vsync();
void set_palette(const uint8_t *palette);
void blit(const uint8_t *sprite, const Rect *dst);
+/* used for text: skip transparent, ignore 0, replace any other color by c */
+void blit_c(const uint8_t *sprite, const Rect *dst, uint8_t c);
/* in src w is sprite width, h is sprite height */
void blitrc(const uint8_t *sprite, const Rect *src, const Rect *dst);
void blit_erase(uint8_t c);