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

@@ -1,4 +1,5 @@
using AlienAttack.MonoGame.GameLoops;
using AlienAttack.MonoGame.Audio;
using AlienAttack.MonoGame.GameLoops;
using AlienAttack.MonoGame.View;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
@@ -20,6 +21,7 @@ public class AlienAttackGame : Game
public SpriteBatch SpriteBatch => _spriteBatch;
public ViewTransform ViewTransform => _viewTransform;
public AudioManager Audio { get; private set; } = new();
private const string SDL = "SDL2.dll";
@@ -47,27 +49,7 @@ public class AlienAttackGame : Game
MaximizeWindow();
PlayBackgroundMusic();
}
private void PlayBackgroundMusic()
{
Song song = Content.Load<Song>($@"Music\Untitled");
// Set whether the song should repeat when finished
MediaPlayer.IsRepeating = true;
// Adjust the volume (0.0f to 1.0f)
MediaPlayer.Volume = 0.5f;
// Check if the media player is already playing, if so, stop it
if (MediaPlayer.State == MediaState.Playing)
{
MediaPlayer.Stop();
}
// Start playing the background music
MediaPlayer.Play(song);
//Audio.PlayMusic(Content, @"Music\Untitled");
}
private void ConfigureWindow()
@@ -91,11 +73,16 @@ public class AlienAttackGame : Game
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
_gameLoop = new GameLoop(this);
// TODO: use this.Content to load your game content here
Audio.LoadContent(Content);
}
protected override void Update(GameTime gameTime)
{
if (IsActive == false)
return;
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();