replaced confusing u64 joinded colors with struct TimStyle

This commit is contained in:
2026-01-09 09:45:00 +05:00
parent 161f655492
commit 1ce7090bd6
13 changed files with 285 additions and 181 deletions

View File

@@ -6,7 +6,6 @@
#define FG 0x10
#define BG 0xdd
#define BTN (FG << 16 | BG << 8 | FG)
#define NEW 0
#define RUN 1
@@ -81,7 +80,7 @@ static void game(void) {
}
// user input
if (tim->event.type == KEY_EVENT) {
if (tim->event.type == TimEvent_Key) {
i32 key = tim->event.key;
if ((key == TimKey_Right || key == 'd') && snek.look.x != -1) {
snek.look = (point){{1, 0}};
@@ -99,17 +98,18 @@ static void game(void) {
}
static void menu(void) {
TimStyle style_button = (TimStyle){ .brd= FG, .bg = BG, .fg = FG };
tim_scope(A, A, 20, 13) {
char* lbl = snek.state == OVER ? "GAME OVER" : "SNEK - THE GAME";
char* btn = snek.state == PAUSE ? "Resume" : "Play";
tim_label(lbl, A, 0, A, A, BTN);
if (tim_button(btn, A, 2, 20, 5, BTN) || tim_is_key_press(TimKey_Enter)) {
tim_label(lbl, A, 0, A, A, style_button);
if (tim_button(btn, A, 2, 20, 5, style_button) || tim_is_key_press(TimKey_Enter)) {
if (snek.state != PAUSE) {
start();
}
snek.state = RUN;
}
if (tim_button("Exit", A, 8, 20, 5, BTN) || tim_is_key_press('q') || tim_is_key_press(TimKey_Escape)) {
if (tim_button("Exit", A, 8, 20, 5, style_button) || tim_is_key_press('q') || tim_is_key_press(TimKey_Escape)) {
exit(0);
}
}
@@ -126,6 +126,6 @@ i32 main(void) {
} else {
menu();
}
}
return 0;
}