From 65f1c203a799fe2de73a2edccd156c9f3136f8b6 Mon Sep 17 00:00:00 2001 From: dvorakmortonxd Date: Sun, 30 Aug 2026 13:24:24 +0200 Subject: [PATCH] added a second message to the intro etc etc, I need to start commiting after every change, fuck --- src/main.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/main.c b/src/main.c index 350ddf4..9d0edb8 100644 --- a/src/main.c +++ b/src/main.c @@ -30,7 +30,6 @@ typedef struct { */ typedef struct { bool is_running; // Controls the main game loop - float escape_timer; // Tracks how long the Escape key has been held (in ms) // Message 1: "Hello, human." const char* message1; int visible_chars1; // Number of characters revealed in message1 @@ -41,6 +40,8 @@ typedef struct { uint32_t last_char_time2; // Timestamp of last character revealed in message2 int message_stage; // 0: showing message1, 1: showing message2 uint32_t message1_finish_time; // Timestamp when message1 finished revealing (0 if not finished) + // Escape key handling + uint32_t escape_press_time; // Timestamp when Escape was first pressed (0 if not pressed) // Fonts TTF_Font* font_large; // Font for message1 (120pt) TTF_Font* font_small; // Font for message2 (24pt) @@ -99,7 +100,7 @@ bool init_game(Game *game) { // Setup initial state game->is_running = true; - game->escape_timer = 0.0f; + game->escape_press_time = 0; // Not pressing escape initially game->message1 = "Hello, human."; game->visible_chars1 = 0; game->last_char_time1 = SDL_GetTicks(); @@ -132,17 +133,19 @@ void handle_input(Game *game, float delta_time) { } const uint8_t *state = SDL_GetKeyboardState(NULL); - + // ESCAPE KEY LOGIC: - // If Escape is held, we add the actual time passed (delta_time) to the timer. if (state[SDL_SCANCODE_ESCAPE]) { - game->escape_timer += delta_time; - if (game->escape_timer >= 1000.0f) { // Exactly 1000ms = 1 second + if (game->escape_press_time == 0) { + // Just pressed + game->escape_press_time = SDL_GetTicks(); + } else if (SDL_GetTicks() - game->escape_press_time >= 1000) { + // Held for 1 second game->is_running = false; } } else { - // Reset timer immediately if key is released - game->escape_timer = 0.0f; + // Released + game->escape_press_time = 0; } // Player Movement (Invisible for now) @@ -186,23 +189,15 @@ void update(Game *game) { } game->last_char_time1 = current_time; } - // Check if we just finished message1 - if (game->visible_chars1 == (int)strlen(game->message1)) { + // Check if we just finished message1 (transition from not finished to finished) + if (game->visible_chars1 == (int)strlen(game->message1) && + game->message1_finish_time == 0) { game->message1_finish_time = current_time; } } - - // Check if we should switch to message2 (after 3.5 seconds of finishing message1) - if (game->message1_finish_time != 0 && - (current_time - game->message1_finish_time >= 3500)) { - game->message_stage = 1; - game->visible_chars2 = 0; - game->last_char_time2 = current_time; - game->current_font = game->font_small; // Switch to small font - } } else if (game->message_stage == 1) { // Handling message2: "It is a known fact that C, is superior to every other programming language." - if (current_time - game->last_char_time2 >= 333) { // Adjusted timing + if (current_time - game->last_char_time2 >= 60) { // 2.5x faster timing for second message if (game->visible_chars2 < (int)strlen(game->message2)) { char current_char = game->message2[game->visible_chars2]; game->visible_chars2++; @@ -218,6 +213,16 @@ void update(Game *game) { } } + // Check if we should switch to message2 (after 3.5 seconds of finishing message1) + // This check happens regardless of which message we're currently displaying + if (game->message_stage == 0 && game->message1_finish_time != 0 && + (current_time - game->message1_finish_time >= 3500)) { + game->message_stage = 1; + game->visible_chars2 = 0; + game->last_char_time2 = current_time; + game->current_font = game->font_small; // Switch to small font + } + // Keep player within screen bounds if (game->player.x < 0) game->player.x = 0; if (game->player.x > SCREEN_WIDTH - game->player.size) game->player.x = SCREEN_WIDTH - game->player.size;