Initial workings for simple transitions between scenes.

This commit is contained in:
2026-10-13 07:11:21 +02:00
parent 79d9ba147c
commit a7ada07466
2 changed files with 26 additions and 4 deletions
+2 -1
View File
@@ -66,13 +66,13 @@ process_events :: proc(game: ^Game) {
intensity := 0.5 + (speed_factor * 4.5) intensity := 0.5 + (speed_factor * 4.5)
game_trigger_shake(game, intensity, duration = 0.15) game_trigger_shake(game, intensity, duration = 0.15)
audio_play_sfx(&game.audio, .Ball_Collision) audio_play_sfx(&game.audio, .Ball_Collision)
case Simple_Event: case Simple_Event:
#partial switch e { #partial switch e {
case .Game_Start: case .Game_Start:
set_root_scene(game, make_gameplay_scene()) set_root_scene(game, make_gameplay_scene())
game.transition = {true, 0, 0.2}
audio_fade_in(&game.audio, duration = 1.5) audio_fade_in(&game.audio, duration = 1.5)
case .Game_Pause: case .Game_Pause:
@@ -92,6 +92,7 @@ process_events :: proc(game: ^Game) {
case .Game_Main_Menu: case .Game_Main_Menu:
set_root_scene(game, make_main_menu()) set_root_scene(game, make_main_menu())
game.transition = {true, 0, 0.3}
audio_fade_out(&game.audio, duration = 1.0) audio_fade_out(&game.audio, duration = 1.0)
case .Game_Back: case .Game_Back:
+24 -3
View File
@@ -22,10 +22,17 @@ RESOLUTIONS := [?]Resolution{
{3840, 2160, "3840x2160"}, {3840, 2160, "3840x2160"},
} }
Transition :: struct {
active: bool,
elapsed: f32,
duration: f32,
}
Game :: struct { Game :: struct {
viewport: rl.RenderTexture2D, viewport: rl.RenderTexture2D,
bg_texture: rl.Texture2D, bg_texture: rl.Texture2D,
crt_shader: rl.Shader, crt_shader: rl.Shader,
transition: Transition,
scene_stack: [dynamic]Scene, scene_stack: [dynamic]Scene,
should_close: bool, should_close: bool,
audio: Audio_Manager, audio: Audio_Manager,
@@ -90,6 +97,7 @@ game_init :: proc(game: ^Game) {
zoom = 1.0, zoom = 1.0,
} }
game.transition = {true, 0, 0.2}
game.should_close = false game.should_close = false
set_root_scene(game, make_main_menu()) set_root_scene(game, make_main_menu())
} }
@@ -121,10 +129,15 @@ game_update :: proc(game: ^Game) {
} }
active_scene := get_active_scene(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) scene_update(active_scene, game, input, dt)
} }
// background music buffer streaming // background music buffer streaming
audio_update(&game.audio, dt) audio_update(&game.audio, dt)
@@ -146,13 +159,21 @@ game_render :: proc(game: ^Game) {
for &scene in game.scene_stack { for &scene in game.scene_stack {
scene_render(&scene) 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.EndMode2D()
rl.EndTextureMode() rl.EndTextureMode()
render_game_to_window(game) render_game_to_window(game)
rl.DrawFPS(10, game.window_h - 20)
when DEBUG do rl.DrawFPS(10, game.window_h - 20)
rl.EndDrawing() rl.EndDrawing()
} }
@@ -212,4 +233,4 @@ render_game_to_window :: proc(game: ^Game) {
rl.WHITE, rl.WHITE,
) )
rl.EndShaderMode() rl.EndShaderMode()
} }