From a7ada0746621b1992905dfbf4bc87b2d2550c4a7 Mon Sep 17 00:00:00 2001 From: Jason Hilder Date: Tue, 13 Oct 2026 07:11:21 +0200 Subject: [PATCH] Initial workings for simple transitions between scenes. --- src/event_manager.odin | 3 ++- src/game.odin | 27 ++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/event_manager.odin b/src/event_manager.odin index d7fd829..3df83c0 100644 --- a/src/event_manager.odin +++ b/src/event_manager.odin @@ -66,13 +66,13 @@ process_events :: proc(game: ^Game) { intensity := 0.5 + (speed_factor * 4.5) game_trigger_shake(game, intensity, duration = 0.15) - audio_play_sfx(&game.audio, .Ball_Collision) case Simple_Event: #partial switch e { case .Game_Start: set_root_scene(game, make_gameplay_scene()) + game.transition = {true, 0, 0.2} audio_fade_in(&game.audio, duration = 1.5) case .Game_Pause: @@ -92,6 +92,7 @@ process_events :: proc(game: ^Game) { case .Game_Main_Menu: set_root_scene(game, make_main_menu()) + game.transition = {true, 0, 0.3} audio_fade_out(&game.audio, duration = 1.0) case .Game_Back: diff --git a/src/game.odin b/src/game.odin index 790392a..e38ed59 100644 --- a/src/game.odin +++ b/src/game.odin @@ -22,10 +22,17 @@ RESOLUTIONS := [?]Resolution{ {3840, 2160, "3840x2160"}, } +Transition :: struct { + active: bool, + elapsed: f32, + duration: f32, +} + Game :: struct { viewport: rl.RenderTexture2D, bg_texture: rl.Texture2D, crt_shader: rl.Shader, + transition: Transition, scene_stack: [dynamic]Scene, should_close: bool, audio: Audio_Manager, @@ -90,6 +97,7 @@ game_init :: proc(game: ^Game) { zoom = 1.0, } + game.transition = {true, 0, 0.2} game.should_close = false set_root_scene(game, make_main_menu()) } @@ -121,10 +129,15 @@ game_update :: proc(game: ^Game) { } active_scene := get_active_scene(game) - if active_scene != nil { + + if game.transition.active { + game.transition.elapsed += dt + if game.transition.elapsed >= game.transition.duration do game.transition.active = false + } else if active_scene != nil { scene_update(active_scene, game, input, dt) } + // background music buffer streaming audio_update(&game.audio, dt) @@ -146,13 +159,21 @@ game_render :: proc(game: ^Game) { for &scene in game.scene_stack { scene_render(&scene) } + + // when game transition active increment its elapsed time + // render will check and display accordingly + if game.transition.active { + a := u8(255 * (1 - clamp(game.transition.elapsed / game.transition.duration, 0, 1))) + rl.DrawRectangle(0, 0, VIEWPORT_W, VIEWPORT_H, {0, 0, 0, a}) + } rl.EndMode2D() rl.EndTextureMode() render_game_to_window(game) - rl.DrawFPS(10, game.window_h - 20) + + when DEBUG do rl.DrawFPS(10, game.window_h - 20) rl.EndDrawing() } @@ -212,4 +233,4 @@ render_game_to_window :: proc(game: ^Game) { rl.WHITE, ) rl.EndShaderMode() -} \ No newline at end of file +}