Added sound effects and music.

This commit is contained in:
2025-12-22 21:55:46 -05:00
parent 42608a16e3
commit 874c263910
36 changed files with 566 additions and 76 deletions

View File

@@ -2,10 +2,12 @@
using AlienAttack.MonoGame.Things.Items;
using AlienAttack.MonoGame.Things.Weapons;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace AlienAttack.MonoGame.Things.Enemies;
@@ -43,7 +45,7 @@ internal class GreenEnemy : EnemyShip
if (Health <= 0)
{
IsDead = true;
context.SpawnSprite(new Explosion((int)XPosition, (int)YPosition, XVelocity, YVelocity));
SpawnExplosion(context);
switch (context.Random.Next(0, 5))
{
@@ -94,6 +96,16 @@ internal class GreenEnemy : EnemyShip
base.Update(context);
}
private void SpawnExplosion(SpriteUpdateContext context)
{
context.SpawnSprite(new Explosion((int)XPosition, (int)YPosition, XVelocity, YVelocity));
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);
}
private void CheckFire(SpriteUpdateContext context)
{
//foreach (IWeapon weapon in ActiveWeapons)

View File

@@ -1,5 +1,6 @@
using AlienAttack.MonoGame.Things.Bullets;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
namespace AlienAttack.MonoGame.Things.Enemies;
@@ -53,7 +54,7 @@ internal class RedEnemy : EnemyShip
if (Health <= 0)
{
IsDead = true;
context.SpawnSprite(new Explosion((int)XPosition, (int)YPosition, XVelocity, YVelocity));
SpawnExplosion(context);
return;
}
@@ -68,6 +69,16 @@ internal class RedEnemy : EnemyShip
base.Update(context);
}
private void SpawnExplosion(SpriteUpdateContext context)
{
context.SpawnSprite(new Explosion((int)XPosition, (int)YPosition, XVelocity, YVelocity));
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);
}
private void TryFire(SpriteUpdateContext context)
{
if (CurrentFireThreshold > 0)

View File

@@ -1,5 +1,6 @@
using AlienAttack.MonoGame.Things.Bullets;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
namespace AlienAttack.MonoGame.Things.Enemies;
@@ -45,7 +46,7 @@ internal class TealEnemy : EnemyShip
if (Health <= 0)
{
IsDead = true;
context.SpawnSprite(new Explosion((int)XPosition, (int)YPosition, XVelocity, YVelocity));
SpawnExplosion(context);
return;
}
@@ -61,6 +62,16 @@ internal class TealEnemy : EnemyShip
base.Update(context);
}
private void SpawnExplosion(SpriteUpdateContext context)
{
context.SpawnSprite(new Explosion((int)XPosition, (int)YPosition, XVelocity, YVelocity));
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);
}
private void TryFire(SpriteUpdateContext context)
{
if (CurrentFireThreshold > 0)

View File

@@ -3,6 +3,7 @@ using AlienAttack.MonoGame.Things.Enemies;
using AlienAttack.MonoGame.Things.Items;
using AlienAttack.MonoGame.Things.Weapons;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
@@ -331,6 +332,13 @@ internal class Player : MoveableSprite
if (context.Sprite is Shields)
{
//SCIEnrg_Shield Activate_01_SFRMS_SCIWPNS
int number = context.Random.Next(1, 6);
SoundEffect soundEffect = context.Content.Load<SoundEffect>(@$"Sfx\Shield\SCIEnrg_Shield Activate_0{number}_SFRMS_SCIWPNS");
soundEffect.Play(0.85f, (float)(context.Random.NextDouble() * 0.1 - 0.05), 0);
GiveShield(20);
}

View File

@@ -1,5 +1,6 @@
using AlienAttack.MonoGame.View;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using System;
namespace AlienAttack.MonoGame.Things;
@@ -10,6 +11,7 @@ public class SpriteUpdateContext(AlienAttackGame game)
public required Action<Sprite> SpawnSprite { get; init; }
public required Random Random { get; init; }
public required GameTime GameTime { get; init; }
public required ContentManager Content { get; init; }
}
public class SpriteCollisionContext(AlienAttackGame game)
@@ -17,4 +19,6 @@ public class SpriteCollisionContext(AlienAttackGame game)
public ViewTransform ViewTransform => game.ViewTransform;
public required Sprite Sprite { get; init; }
public required Action<Sprite> SpawnSprite { get; init; }
public required Random Random { get; init; }
public required ContentManager Content { get; init; }
}

View File

@@ -1,4 +1,5 @@
using AlienAttack.MonoGame.Things.Bullets;
using Microsoft.Xna.Framework.Audio;
namespace AlienAttack.MonoGame.Things.Weapons;
@@ -20,6 +21,11 @@ public class Minigun : Weapon
// Queue the bullets for spawning
context.SpawnSprite(bullet1);
context.SpawnSprite(bullet2);
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);
}
}