Added more sound effeects. Added audio manager.

This commit is contained in:
2025-12-28 21:23:23 -05:00
parent 874c263910
commit c4a98ce03d
32 changed files with 550 additions and 37 deletions

View File

@@ -47,5 +47,7 @@ internal class Bullet(float x, float y, float xVel, float yVel, Sprite owner) :
}
context.SpawnSprite(new MiniExplosion((int)XPosition, (int)YPosition, xVel, yVel));
context.AudioManager.PlayImpact();
}
}

View File

@@ -88,6 +88,8 @@ internal class GreenEnemy : EnemyShip
context.SpawnSprite(new MinigunBulletSmall(originX + 14, YPosition + BoundBox.Height - 12, 0, 2 + YVelocity, this));
CurrentFireThreshold = FireThreshold;
context.AudioManager.PlayEnemyFire();
}
//CheckMove(context);
@@ -100,10 +102,12 @@ internal class GreenEnemy : EnemyShip
{
context.SpawnSprite(new Explosion((int)XPosition, (int)YPosition, XVelocity, YVelocity));
int number = context.Random.Next(1, 7);
//int number = context.Random.Next(1, 7);
SoundEffect soundEffect = context.Content.Load<SoundEffect>(@$"Sfx\Explosions\EXPLDsgn_Explosion Impact_0{number}_SFRMS_SCIWPNS");
soundEffect.Play(0.95f, (float)(context.Random.NextDouble() * 0.1 - 0.05), 0);
//SoundEffect soundEffect = context.Content.Load<SoundEffect>(@$"Sfx\Explosions\EXPLDsgn_Explosion Impact_0{number}_SFRMS_SCIWPNS");
//soundEffect.Play(0.95f, (float)(context.Random.NextDouble() * 0.1 - 0.05), 0);
context.AudioManager.PlayExplosion();
}
private void CheckFire(SpriteUpdateContext context)

View File

@@ -73,10 +73,12 @@ internal class RedEnemy : EnemyShip
{
context.SpawnSprite(new Explosion((int)XPosition, (int)YPosition, XVelocity, YVelocity));
int number = context.Random.Next(1, 7);
//int number = context.Random.Next(1, 7);
SoundEffect soundEffect = context.Content.Load<SoundEffect>(@$"Sfx\Explosions\EXPLDsgn_Explosion Impact_0{number}_SFRMS_SCIWPNS");
soundEffect.Play(0.95f, (float)(context.Random.NextDouble() * 0.1 - 0.05), 0);
//SoundEffect soundEffect = context.Content.Load<SoundEffect>(@$"Sfx\Explosions\EXPLDsgn_Explosion Impact_0{number}_SFRMS_SCIWPNS");
//soundEffect.Play(0.95f, (float)(context.Random.NextDouble() * 0.1 - 0.05), 0);
context.AudioManager.PlayExplosion();
}
private void TryFire(SpriteUpdateContext context)
@@ -94,6 +96,8 @@ internal class RedEnemy : EnemyShip
context.SpawnSprite(new MinigunBulletSmall(originX + 14, YPosition + BoundBox.Height - 12, 0, 2 + YVelocity, this));
CurrentFireThreshold = FireThreshold;
context.AudioManager.PlayEnemyFire();
}
}

View File

@@ -66,10 +66,12 @@ internal class TealEnemy : EnemyShip
{
context.SpawnSprite(new Explosion((int)XPosition, (int)YPosition, XVelocity, YVelocity));
int number = context.Random.Next(1, 7);
//int number = context.Random.Next(1, 7);
SoundEffect soundEffect = context.Content.Load<SoundEffect>(@$"Sfx\Explosions\EXPLDsgn_Explosion Impact_0{number}_SFRMS_SCIWPNS");
soundEffect.Play(0.95f, (float)(context.Random.NextDouble() * 0.1 - 0.05), 0);
//SoundEffect soundEffect = context.Content.Load<SoundEffect>(@$"Sfx\Explosions\EXPLDsgn_Explosion Impact_0{number}_SFRMS_SCIWPNS");
//soundEffect.Play(0.95f, (float)(context.Random.NextDouble() * 0.1 - 0.05), 0);
context.AudioManager.PlayExplosion();
}
private void TryFire(SpriteUpdateContext context)
@@ -87,6 +89,8 @@ internal class TealEnemy : EnemyShip
context.SpawnSprite(new MinigunBulletSmall(originX + 14, YPosition + BoundBox.Height - 12, 0, 2 + YVelocity, this));
CurrentFireThreshold = FireThreshold;
context.AudioManager.PlayEnemyFire();
}
}

View File

@@ -97,11 +97,13 @@ internal class Player : MoveableSprite
public override void Update(SpriteUpdateContext context)
{
base.Update(context);
//UpdateExhaustAnimationThreshold();
CheckMove(context);
CheckFire(context);
base.Update(context);
//base.Update(context);
}
private void UpdateExhaustAnimationThreshold()

View File

@@ -1,4 +1,5 @@
using AlienAttack.MonoGame.View;
using AlienAttack.MonoGame.Audio;
using AlienAttack.MonoGame.View;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using System;
@@ -12,6 +13,7 @@ public class SpriteUpdateContext(AlienAttackGame game)
public required Random Random { get; init; }
public required GameTime GameTime { get; init; }
public required ContentManager Content { get; init; }
public AudioManager AudioManager => game.Audio;
}
public class SpriteCollisionContext(AlienAttackGame game)
@@ -21,4 +23,5 @@ public class SpriteCollisionContext(AlienAttackGame game)
public required Action<Sprite> SpawnSprite { get; init; }
public required Random Random { get; init; }
public required ContentManager Content { get; init; }
public AudioManager AudioManager => game.Audio;
}

View File

@@ -22,10 +22,12 @@ public class Minigun : Weapon
context.SpawnSprite(bullet1);
context.SpawnSprite(bullet2);
int number = context.Random.Next(1, 7);
//int number = context.Random.Next(1, 7);
SoundEffect soundEffect = context.Content.Load<SoundEffect>(@$"Sfx\GUNAuto_Assault Rifle A Fire_0{number}_SFRMS_SCIWPNS");
soundEffect.Play(0.25f, (float)(context.Random.NextDouble() * 0.1 - 0.05), 0);
//SoundEffect soundEffect = context.Content.Load<SoundEffect>(@$"Sfx\GUNAuto_Assault Rifle A Fire_0{number}_SFRMS_SCIWPNS");
//soundEffect.Play(0.25f, (float)(context.Random.NextDouble() * 0.1 - 0.05), 0);
context.AudioManager.PlayPlayerFire();
}
}