From 118c9e7168dc92052321e32d9435588cd010e40f Mon Sep 17 00:00:00 2001 From: _N3m0 Date: Thu, 14 Mar 2024 08:48:58 +0100 Subject: [PATCH] menu: mode clickable --- main.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/main.c b/main.c index 0cad1f9..c0f1525 100644 --- a/main.c +++ b/main.c @@ -27,10 +27,12 @@ char game[16][30] = {0}; char discover[16][30] = {0}; char zero[16][30] = {0}; +// I confused myself with game type, mode and diff, but it all mean the same typedef enum GameType { BEGINNER, INTERMEDIATE, EXPERT, + GAME_TYPE_NB, } GameType; GameType current_game_type = BEGINNER; @@ -240,6 +242,25 @@ void reload_game(void) screen_resize_handle(); } +void switch_mode(GameType gt) +{ + current_game_type = gt; + switch (gt) { + case BEGINNER: + current_game_name = "beginner"; + current_game_color = GREEN; + break; + case INTERMEDIATE: + current_game_name = "intermediate"; + current_game_color = ORANGE; + break; + case EXPERT: + current_game_name = "expert"; + current_game_color = RED; + break; + } +} + int main(void) { srand(time(NULL)); @@ -304,21 +325,15 @@ int main(void) int resize = 0; if (IsKeyPressed(KEY_I)) { - current_game_type = INTERMEDIATE; - current_game_name = "intermediate"; - current_game_color = ORANGE; + switch_mode(INTERMEDIATE); resize = 1; } if (IsKeyPressed(KEY_B)) { - current_game_type = BEGINNER; - current_game_name = "beginner"; - current_game_color = GREEN; + switch_mode(BEGINNER); resize = 1; } if (IsKeyPressed(KEY_E)) { - current_game_type = EXPERT; - current_game_name = "expert"; - current_game_color = RED; + switch_mode(EXPERT); resize = 1; } if (resize || IsKeyPressed(KEY_R)) { @@ -490,6 +505,12 @@ int main(void) { take_screenshot = 1; } + if (collision((Vec2i) {0, 0}, triple_tile_texture, + mouse_x, mouse_y)) + { + switch_mode((current_game_type + 1) % GAME_TYPE_NB); + reload_game(); + } // if (collision(diff_button[0], triple_tile_texture, // mouse_x, mouse_y)) // {