diff options
| author | WormHeamer | 2025-11-08 21:21:46 -0500 |
|---|---|---|
| committer | WormHeamer | 2025-11-08 21:21:46 -0500 |
| commit | 360e1faf8ce751d0a8b55744642546df730d1def (patch) | |
| tree | 7d976c40a54cd66b9ce77262a8532daf84c0a4a5 | |
| parent | abfc9d7655f0b52a0ffeebf456dddfc205c7349b (diff) | |
| -rw-r--r-- | main.c | 53 |
1 files changed, 35 insertions, 18 deletions
@@ -9,6 +9,8 @@ #include "vui.h" int alive, paused; +int flash = 0; +u32 frame, score; /* input buffer */ @@ -59,8 +61,8 @@ int poll_input(u32 ms) { /* program */ -#define WIDTH 32 -#define HEIGHT 32 +#define WIDTH 20 +#define HEIGHT 20 typedef enum { TILE_FLOOR, @@ -112,9 +114,7 @@ typedef struct { SnkSeg seg[SNK_SEG_MAX]; } Snake; -Snake snk = { - .len = 1 -}; +Snake snk = { 0 }; typedef struct { i16 x, y; @@ -253,23 +253,33 @@ void brd_draw(void) { u32 right = left + WIDTH * 2; u32 bottom = top + HEIGHT; + u32 lvl = score / 10; + VuiAttr bordatr = A_BOLD | ((FG_BLUE + lvl) & 7); for (u32 y = 0; y < HEIGHT; y++) { - vui_chr(left - 1, top + y, u'║'); - vui_chr(right + 1, top + y, u'║'); + vui_chra(left - 1, top + y, u'║', bordatr); + vui_chra(right + 1, top + y, u'║', bordatr); for (u32 x = 0; x < WIDTH; x++) { Tile t = board[y][x]; - vui_chra(left + 2 * x, top + y, tile_chr[t][0], tile_attr[t][0]); - vui_chra(left + 2 * x + 1, top + y, tile_chr[t][1], tile_attr[t][1]); - vui_puts(left + 2 * x, top - 1, "══"); - vui_puts(left + 2 * x, bottom, "══"); + VuiAttr a0 = tile_attr[t][0]; + VuiAttr a1 = tile_attr[t][1]; + a1 = ((a1 + lvl) & 7) | (a1 & 8); + a0 = ((a0 + lvl) & 7) | (a0 & 8); + if (t == TILE_FLOOR) { + if ((x + y + frame) & 8) a1 |= A_BOLD; + } + if (flash) a0 = (a1 = FG_BWHITE | BG_BLACK); + vui_chra(left + 2 * x, top + y, tile_chr[t][0], a0); + vui_chra(left + 2 * x + 1, top + y, tile_chr[t][1], a1); + vui_putsa(left + 2 * x, top - 1, "══", bordatr); + vui_putsa(left + 2 * x, bottom, "══", bordatr); } } - vui_chr(left - 1, top - 1, u'╔'); - vui_chr(right + 1, top - 1, u'╗'); - vui_chr(left - 1, bottom, u'╚'); - vui_chr(right + 1, bottom, u'╝'); - vui_chr(right, bottom, u'═'); - vui_chr(right, top - 1, u'═'); + vui_chra(left - 1, top - 1, u'╔', bordatr); + vui_chra(right + 1, top - 1, u'╗', bordatr); + vui_chra(left - 1, bottom, u'╚', bordatr); + vui_chra(right + 1, bottom, u'╝', bordatr); + vui_chra(right, bottom, u'═', bordatr); + vui_chra(right, top - 1, u'═', bordatr); /* u32 x = 0; u32 y = 1; @@ -288,6 +298,7 @@ void brd_draw(void) { } } */ + flash = 0; } void snk_draw(Snake *s) { @@ -317,7 +328,7 @@ void draw(void *ctx) { vui_printf(0, 0, "input polling iterations: %u", poll_input_iter); vui_printf(0, 1, "apples: %u", napple); vui_printf(0, 2, "last apple bitboard len: %u", last_apple_bb_len); - vui_printf(0, 3, "last apple position: %u", last_apple_pos % WIDTH, last_apple_pos / WIDTH); + vui_printf(0, 3, "last apple position: %u, %u", last_apple_pos % WIDTH, last_apple_pos / WIDTH); vui_printf(-1, 0, "snake pos: %hd, %hd", snk.seg->x, snk.seg->y); BitBoard bb; @@ -333,8 +344,10 @@ void draw(void *ctx) { void update(void) { for (u32 i = 0; i < napple; i++) { if (snk.seg[0].x == apple[i].x && snk.seg[0].y == apple[i].y) { + flash = 1; replace_apple(i); snk.len++; + score++; break; } } @@ -375,12 +388,16 @@ int main(void) { vui_init(); vui_redraw_fn(draw); snk.dir = DIR_RIGHT; + snk.len = 0; snk.seg[snk.len++] = (SnkSeg) { 0, 0 }; alive = 1; paused = 0; napple = APPLE_MAX; place_apple(); + frame = 0; + score = 0; while (alive) { + frame++; poll_input(33); draw(NULL); vui_blit(); |
