diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-06-21 22:42:28 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-06-21 22:42:28 +0100 |
commit | b4c2ff850930cb29da1a331b17fcc8a9e561b5ff (patch) | |
tree | e3b5a6c0d4a4454cc13afc8cc72bdc1e476e8569 /src | |
parent | d3c44c1472ab23a8ea37cc63f3f9f8678b0a6af5 (diff) | |
download | gold-mine-run-b4c2ff850930cb29da1a331b17fcc8a9e561b5ff.tar.gz gold-mine-run-b4c2ff850930cb29da1a331b17fcc8a9e561b5ff.zip |
Add color text
Diffstat (limited to 'src')
-rw-r--r-- | src/game.c | 12 | ||||
-rw-r--r-- | src/menu.c | 10 | ||||
-rw-r--r-- | src/text.c | 4 | ||||
-rw-r--r-- | src/text.h | 2 | ||||
-rw-r--r-- | src/vga.c | 19 | ||||
-rw-r--r-- | src/vga.h | 2 |
6 files changed, 35 insertions, 14 deletions
@@ -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; @@ -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(); @@ -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; } } @@ -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 */ @@ -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) @@ -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); |