diff --git a/src/Models/Alien.zig b/src/Models/Alien.zig index 78e9fe4..cbff5eb 100644 --- a/src/Models/Alien.zig +++ b/src/Models/Alien.zig @@ -138,7 +138,7 @@ pub const Alien = struct { shoots[i].lifeSpawn = 0; self.active = false; - Shared.Sound.Play(.Explosion); + Shared.Sound.Play(.AlienExplosion); return AlienStatus{ .shot = shoots[i] }; } diff --git a/src/Models/Meteor.zig b/src/Models/Meteor.zig index 46c823c..c16da8e 100644 --- a/src/Models/Meteor.zig +++ b/src/Models/Meteor.zig @@ -213,8 +213,6 @@ pub const Meteor = struct { self.color = Shared.Color.Red.Base; - Shared.Sound.Play(.Explosion); - return MeteorStatus{ .shot = shoots[i] }; } } @@ -233,8 +231,6 @@ pub const Meteor = struct { self.color = Shared.Color.Red.Base; - Shared.Sound.Play(.Explosion); - return MeteorStatus{ .shot = alien_shoots[i] }; } } diff --git a/src/Models/Player.zig b/src/Models/Player.zig index f995cac..3f9e5c8 100644 --- a/src/Models/Player.zig +++ b/src/Models/Player.zig @@ -74,6 +74,7 @@ pub const Player = struct { // Player logic: acceleration if (Shared.Input.Up_Held()) { + Shared.Sound.PlaySingleVoice(.Acceleration); if (self.acceleration < 1) self.acceleration += 0.04; } else { if (self.acceleration > 0) { diff --git a/src/Shared.zig b/src/Shared.zig index 6c62bb1..ab93b81 100644 --- a/src/Shared.zig +++ b/src/Shared.zig @@ -180,6 +180,12 @@ pub const Shared = struct { raylib.playSound(s.?); } } + pub inline fn PlaySingleVoice(sound: AssetManager.Sounds) void { + const s = Get(sound); + if (s != null and !raylib.isSoundPlaying(s.?)) { + raylib.playSound(s.?); + } + } pub inline fn Pause(sound: AssetManager.Sounds) void { const s = Get(sound); if (s != null and raylib.isSoundPlaying(s.?)) { diff --git a/src/ViewModels/AsteroidsViewModel.zig b/src/ViewModels/AsteroidsViewModel.zig index 2b97a43..d6fe88f 100644 --- a/src/ViewModels/AsteroidsViewModel.zig +++ b/src/ViewModels/AsteroidsViewModel.zig @@ -161,6 +161,8 @@ pub const AsteroidsViewModel = Shared.View.ViewModel.Create( player.status = .collide; player.frame = 0; nextShieldLevel -= 1; + + Shared.Sound.Play(.HitWall); }, .shot => { player.status = .shot; @@ -223,6 +225,8 @@ pub const AsteroidsViewModel = Shared.View.ViewModel.Create( if (i == bigMeteorsCount) allBigChecked = true; }, .shot => |shot| { + Shared.Sound.Play(.Explosion); + bigMeteorsCount -= 1; score += 4; @@ -259,6 +263,8 @@ pub const AsteroidsViewModel = Shared.View.ViewModel.Create( }, .collide => { player.status = .collide; + Shared.Sound.Play(.Explosion); + Shared.Sound.Play(.HitWall); if (bigMeteors[i].position.x > player.collider.x - halfShipHeight) { player.rotation = std.math.radiansToDegrees(f32, std.math.pi * 2 - std.math.degreesToRadians(f32, player.rotation)); @@ -317,6 +323,8 @@ pub const AsteroidsViewModel = Shared.View.ViewModel.Create( if (i == midMeteorsCount) allMidChecked = true; }, .shot => |shot| { + Shared.Sound.Play(.MedExplosion); + midMeteorsCount -= 1; score += 2; @@ -353,6 +361,8 @@ pub const AsteroidsViewModel = Shared.View.ViewModel.Create( }, .collide => { player.status = .collide; + Shared.Sound.Play(.MedExplosion); + Shared.Sound.Play(.HitWall); if (mediumMeteors[i].position.x > player.collider.x) { player.rotation = std.math.radiansToDegrees(f32, std.math.pi * 2 - std.math.degreesToRadians(f32, player.rotation)); @@ -411,6 +421,8 @@ pub const AsteroidsViewModel = Shared.View.ViewModel.Create( if (i == smallMeteorsCount) allSmallChecked = true; }, .shot => { + Shared.Sound.Play(.SmallExplosion); + smallMeteorsCount -= 1; smallMeteorsDestroyedCount += 1; score += 1; @@ -437,6 +449,8 @@ pub const AsteroidsViewModel = Shared.View.ViewModel.Create( }, .collide => { player.status = .collide; + Shared.Sound.Play(.SmallExplosion); + Shared.Sound.Play(.HitWall); if (smallMeteors[i].position.x > player.collider.x) { player.rotation = std.math.radiansToDegrees(f32, std.math.pi * 2 - std.math.degreesToRadians(f32, player.rotation));