Updated collision event for screenshake.
This commit is contained in:
+14
-3
@@ -1,6 +1,7 @@
|
||||
package game
|
||||
|
||||
Change_Resolution_Data :: struct { res_dir: int }
|
||||
Ball_Collision_Data :: struct { speed: f32, }
|
||||
Game_Over_Data :: struct { winner_is_player: bool }
|
||||
|
||||
Simple_Event :: enum {
|
||||
@@ -14,13 +15,13 @@ Simple_Event :: enum {
|
||||
Game_Quit,
|
||||
UI_Select,
|
||||
Score_Change,
|
||||
Ball_Collision,
|
||||
}
|
||||
|
||||
Event :: union {
|
||||
Simple_Event,
|
||||
Change_Resolution_Data,
|
||||
Game_Over_Data,
|
||||
Ball_Collision_Data,
|
||||
}
|
||||
|
||||
// global event storage
|
||||
@@ -56,6 +57,18 @@ process_events :: proc(game: ^Game) {
|
||||
case Game_Over_Data:
|
||||
push_scene(game, make_game_over_overlay(e.winner_is_player))
|
||||
|
||||
case Ball_Collision_Data:
|
||||
// normalize the speed between 0.0 -> 1.0
|
||||
// map that value to the camera displacement
|
||||
min_speed: f32 = 200.0
|
||||
max_speed: f32 = 550.0
|
||||
speed_factor := clamp((e.speed - min_speed) / (max_speed - min_speed), 0, 1.0)
|
||||
|
||||
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:
|
||||
@@ -81,8 +94,6 @@ process_events :: proc(game: ^Game) {
|
||||
case .UI_Select:
|
||||
audio_play_sfx(&game.audio, .UI_Select)
|
||||
|
||||
case .Ball_Collision:
|
||||
audio_play_sfx(&game.audio, .Ball_Collision)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user