Added sound effects and music.
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using AlienAttack.MonoGame.GameLoops;
|
||||
using AlienAttack.MonoGame.View;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Audio;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using Microsoft.Xna.Framework.Media;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
@@ -44,6 +46,28 @@ public class AlienAttackGame : Game
|
||||
base.Initialize();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private void ConfigureWindow()
|
||||
@@ -86,7 +110,7 @@ public class AlienAttackGame : Game
|
||||
GraphicsDevice.Clear(Color.Black);
|
||||
|
||||
// TODO: Add your drawing code here
|
||||
_gameLoop.Draw();
|
||||
_gameLoop.Draw(gameTime);
|
||||
|
||||
base.Draw(gameTime);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user