From a82f702665b7dd299ae2b3ee03dba246029d0c58 Mon Sep 17 00:00:00 2001 From: Menase Teshale Date: Tue, 29 Sep 2026 03:11:31 +0300 Subject: Finally enabled cascading falls - The ability to pick the time for timed mode also added - TODO: Massive refactor --- src/menu.c | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) (limited to 'src/menu.c') diff --git a/src/menu.c b/src/menu.c index 74e91ef..fa3b588 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1,10 +1,13 @@ #include "app.h" #include "font.h" +#include #define MENU_ITEM_TOP_YPOS_RELATIVE 0.3 -#define MENU_ITEM_YOFFSET_RELATIVE 0.03 -#define UNSELECTED_ITEM_SCALE 1 -#define SELECTED_ITEM_SCALE 1.2 +#define MENU_ITEM_YOFFSET_RELATIVE 0.05 +#define UNSELECTED_ITEM_SCALE 2 +#define SELECTED_ITEM_SCALE 2.4 +#define MINIMUM_TIMED_MODE_TIME 5 +#define TIMED_MODE_STEP 3 typedef enum { timed_mode_option = 0, @@ -12,6 +15,7 @@ typedef enum { } menu_option; menu_option selected_option; +int timed_mode_time; sprite_font text_font; extern SDL_Window* window; @@ -25,27 +29,37 @@ void init_menu(SDL_Renderer* renderer) { } selected_option = timed_mode_option; + timed_mode_time = MINIMUM_TIMED_MODE_TIME + 2*TIMED_MODE_STEP; } void draw_menu(SDL_Renderer* renderer) { SDL_RenderClear(renderer); - const char* labels[] = { - "Timed Mode", - "Exit", - }; - float yp = MENU_ITEM_TOP_YPOS_RELATIVE; for (menu_option i = timed_mode_option; i <= exit_option; i++) { float scale = i == selected_option ? SELECTED_ITEM_SCALE : UNSELECTED_ITEM_SCALE; - draw_text_with_spritefont_extended(renderer, - &text_font, - (unsigned char*)labels[i], - get_window_relative_xpos(0.5), - get_window_relative_ypos(yp), - scale - ); + if (i == timed_mode_option) { + char timed_mode_label[100]; + snprintf(timed_mode_label, 100, "Timed Mode <%d>", timed_mode_time); + + draw_text_with_spritefont_extended(renderer, + &text_font, + (unsigned char*)timed_mode_label, + get_window_relative_xpos(0.5), + get_window_relative_ypos(yp), + scale + ); + } else if (i == exit_option) { + draw_text_with_spritefont_extended(renderer, + &text_font, + (unsigned char*)"Exit", + get_window_relative_xpos(0.5), + get_window_relative_ypos(yp), + scale + ); + } + yp += MENU_ITEM_YOFFSET_RELATIVE; } @@ -66,7 +80,7 @@ SDL_AppResult menu_execute_action() { if (selected_option == exit_option) { return SDL_APP_SUCCESS; } if (selected_option == timed_mode_option) { - init_timed_game(NULL, NULL, 5); + init_timed_game(NULL, NULL, timed_mode_time); app_state = game_state; } @@ -77,7 +91,11 @@ SDL_AppResult menu_event(SDL_Event* e) { if (e->type == SDL_EVENT_KEY_DOWN) { SDL_Scancode pressed_button = e->key.scancode; - if (pressed_button == SDL_SCANCODE_RETURN) { + if (pressed_button == SDL_SCANCODE_RIGHT && selected_option == timed_mode_option) { + timed_mode_time += TIMED_MODE_STEP; + } else if (pressed_button == SDL_SCANCODE_LEFT && selected_option == timed_mode_option) { + timed_mode_time = SDL_max(MINIMUM_TIMED_MODE_TIME, timed_mode_time-TIMED_MODE_STEP); + } else if (pressed_button == SDL_SCANCODE_RETURN) { return menu_execute_action(); } else if (pressed_button == SDL_SCANCODE_DOWN) { select_next_option(); -- cgit v1.2.3