Skip to content

Commit

Permalink
Wire up sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanlangston committed Jan 5, 2024
1 parent 1a6162b commit 7d85725
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Models/Alien.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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] };
}
Expand Down
4 changes: 0 additions & 4 deletions src/Models/Meteor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ pub const Meteor = struct {

self.color = Shared.Color.Red.Base;

Shared.Sound.Play(.Explosion);

return MeteorStatus{ .shot = shoots[i] };
}
}
Expand All @@ -233,8 +231,6 @@ pub const Meteor = struct {

self.color = Shared.Color.Red.Base;

Shared.Sound.Play(.Explosion);

return MeteorStatus{ .shot = alien_shoots[i] };
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Models/Player.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/Shared.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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.?)) {
Expand Down
14 changes: 14 additions & 0 deletions src/ViewModels/AsteroidsViewModel.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand All @@ -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));
Expand Down

0 comments on commit 7d85725

Please sign in to comment.