diff --git a/fap/laser_tag.fap b/fap/laser_tag.fap index 359cd22456b..ae9ae88c45e 100644 Binary files a/fap/laser_tag.fap and b/fap/laser_tag.fap differ diff --git a/game_state.h b/game_state.h index 5cf2e00bf8f..0ab5b2b42eb 100644 --- a/game_state.h +++ b/game_state.h @@ -12,6 +12,7 @@ typedef enum { LaserTagStateSplashScreen, LaserTagStateTeamSelect, LaserTagStateGame, + LaserTagStateGameOver, } LaserTagState; typedef struct GameState GameState; diff --git a/laser_tag_app.c b/laser_tag_app.c index 430a93b1692..12659ef1f27 100644 --- a/laser_tag_app.c +++ b/laser_tag_app.c @@ -116,6 +116,27 @@ static void laser_tag_app_draw_callback(Canvas* canvas, void* context) { canvas_draw_circle(canvas, 60, 32, 5); canvas_draw_circle(canvas, 60, 32, 2); + } else if(app->state == LaserTagStateGameOver) { + canvas_clear(canvas); + + canvas_set_font(canvas, FontPrimary); + + // Display "GAME OVER!" centered on the screen + canvas_draw_str_aligned(canvas, 64, 25, AlignCenter, AlignCenter, "GAME OVER!"); + + // Add a solid block border around the screen + for(int x = 0; x < 128; x += 8) { + canvas_draw_box(canvas, x, 0, 8, 8); + canvas_draw_box(canvas, x, 56, 8, 8); + } + for(int y = 8; y < 56; y += 8) { + canvas_draw_box(canvas, 0, y, 8, 8); + canvas_draw_box(canvas, 120, y, 8, 8); + } + + canvas_set_font(canvas, FontSecondary); + canvas_draw_str_aligned(canvas, 64, 50, AlignCenter, AlignCenter, "Press OK to Restart"); + } else if(app->view) { FURI_LOG_D(TAG, "Drawing game view"); laser_tag_view_draw(laser_tag_view_get_view(app->view), canvas); @@ -222,10 +243,11 @@ void laser_tag_app_handle_hit(LaserTagApp* app) { FURI_LOG_I(TAG, "Notifying user with vibration"); if(game_state_is_game_over(app->game_state)) { - FURI_LOG_I(TAG, "Game over, playing game over sound"); + FURI_LOG_I(TAG, "Game over, switching to Game Over screen"); notification_message(app->notifications, &sequence_error); + app->state = LaserTagStateGameOver; app->need_redraw = true; } } @@ -298,18 +320,34 @@ int32_t laser_tag_app(void* p) { default: break; } - } else { - switch(event.key) { - case InputKeyBack: - FURI_LOG_I(TAG, "Back key pressed, exiting"); - running = false; - break; - case InputKeyOk: - FURI_LOG_I(TAG, "OK key pressed, firing laser"); - laser_tag_app_fire(app); - break; - default: - break; + } else if(app->state == LaserTagStateGameOver) { + if(event.key == InputKeyOk) { + FURI_LOG_I(TAG, "OK key pressed, restarting game"); + + // Restart game by resetting game state and transitioning to splash screen + game_state_reset(app->game_state); + app->state = LaserTagStateSplashScreen; + app->need_redraw = true; + } + } else if(app->state == LaserTagStateGame) { + if(event.key == InputKeyDown && game_state_get_ammo(app->game_state) == 0) { + // Reload ammo when Down button is pressed and ammo is depleted + FURI_LOG_I(TAG, "Down key pressed, reloading ammo"); + game_state_increase_ammo(app->game_state, INITIAL_AMMO); + app->need_redraw = true; + } else { + switch(event.key) { + case InputKeyBack: + FURI_LOG_I(TAG, "Back key pressed, exiting"); + running = false; + break; + case InputKeyOk: + FURI_LOG_I(TAG, "OK key pressed, firing laser"); + laser_tag_app_fire(app); + break; + default: + break; + } } } } @@ -328,7 +366,16 @@ int32_t laser_tag_app(void* p) { if(game_state_is_game_over(app->game_state)) { FURI_LOG_I(TAG, "Game over, notifying user with error sequence"); notification_message(app->notifications, &sequence_error); - running = false; + // Stop game logic after game over + app->state = LaserTagStateGameOver; + app->need_redraw = true; + } + } else if(app->state == LaserTagStateGameOver) { + if(event.key == InputKeyOk) { + FURI_LOG_I(TAG, "OK key pressed, restarting game"); + game_state_reset(app->game_state); + app->state = LaserTagStateSplashScreen; + app->need_redraw = true; } } diff --git a/laser_tag_view.c b/laser_tag_view.c index 286f7b742e5..37a278ca0f0 100644 --- a/laser_tag_view.c +++ b/laser_tag_view.c @@ -34,7 +34,7 @@ static void laser_tag_view_draw_callback(Canvas* canvas, void* model) { canvas_draw_box(canvas, 56, 36, (58 * m->ammo) / 100, 8); if(m->ammo == 0) { - canvas_draw_str_aligned(canvas, 5, 55, AlignLeft, AlignBottom, "Press 'X' to Reload"); + canvas_draw_str_aligned(canvas, 5, 55, AlignLeft, AlignBottom, "Press 'Down' to Reload"); } uint32_t minutes = m->game_time / 60;