Game-Design / Sprint3_actual / SoundManagement / SoundEngine.cs
SoundEngine.cs
Raw
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Media;

namespace Sprint3_actual.SoundManagement
{
    class SoundEngine
    {
        private Song DungeonMusic;
        private Song BossMusic;
        private Song TriforceGet;
        private SoundEffect ItemPickup;
        private SoundEffect HeartOrKeyGet;
        private SoundEffect EnemyDeath;
        private SoundEffect BossRoar;
        private SoundEffect BossDeath;
        private SoundEffect FlameShot;
        private SoundEffect PlayerDamage;
        private SoundEffect BoomerangThrow;
        private SoundEffect SwordSlash;
        private SoundEffect ArrowShot;
        private SoundEffect BombSounds;
        private SoundEffect SwordBeam;
        private SoundEffect Damage;
        private SoundEffect TextVoice;
        private Song trap;
        private SoundEffect WitchLaugh;
        private SoundEffect MetalSound;
        private SoundEffect LightningBlast;
        private SoundEffect VineBoom;

        private static SoundEngine instance = new SoundEngine();
        public static SoundEngine Instance
        {
            get
            {
                return instance;
            }
        }

        private SoundEngine()
        {
        }

        public void LoadSounds(ContentManager content)
        {
            DungeonMusic = content.Load<Song>("Dungeon Music");
            BossMusic = content.Load<Song>("Rude Buster");
            ItemPickup = content.Load<SoundEffect>("Item Pickup");
            HeartOrKeyGet = content.Load<SoundEffect>("Heart or Key Get");
            EnemyDeath = content.Load<SoundEffect>("Enemy Death");
            BossRoar = content.Load<SoundEffect>("Boss Roar");
            BossDeath = content.Load<SoundEffect>("Boss Defeated");
            TriforceGet = content.Load<Song>("Triforce Piece Get");
            FlameShot = content.Load<SoundEffect>("Flame Shot");
            PlayerDamage = content.Load<SoundEffect>("PlayerDamaged");
            BoomerangThrow = content.Load<SoundEffect>("Boomerang Thrown");
            SwordSlash = content.Load<SoundEffect>("Sword Slash");
            ArrowShot = content.Load<SoundEffect>("Arrow Shot");
            BombSounds = content.Load<SoundEffect>("Bomb Sounds");
            SwordBeam = content.Load<SoundEffect>("Sword Beam");
            Damage = content.Load<SoundEffect>("damageNew");
            TextVoice = content.Load<SoundEffect>("voice_sans");
            trap = content.Load<Song>("zeldaTrap");
            WitchLaugh = content.Load<SoundEffect>("Witchlaugh");
            MetalSound = content.Load<SoundEffect>("Metal effect");
            LightningBlast = content.Load<SoundEffect>("Lightningblast");
            trap = content.Load<Song>("zeldaTrap");
            VineBoom = content.Load<SoundEffect>("Vine Boom Edit");
        }

        public void startDungeonMusic()
        {
            MediaPlayer.Play(DungeonMusic);
            MediaPlayer.IsRepeating = true;
        }

        public void startBossMusic()
        {
            MediaPlayer.Play(BossMusic);
        }

        //TO DO: Try to pause background music when you pick up the triforce piece
        public void playTriforceGet()
        {
            MediaPlayer.IsRepeating = false;
            MediaPlayer.Play(TriforceGet);
            float currentTime = 0f;
            //This loop runs too fast, need a different workaround
            while (currentTime < (float)TriforceGet.Duration.TotalSeconds)
            {
                currentTime += (float)GlobalVars.gameTime.ElapsedGameTime.TotalSeconds;
            }
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Play(DungeonMusic);
        }

        public void playTrap()
        {
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Play(trap);
        }

        public void toggleMute()
        {
            MediaPlayer.IsMuted = !MediaPlayer.IsMuted;
        }

        public void playItemPickup()
        {
            ItemPickup.Play(0.7f, 0.0f, 0.0f);
        }

        public void playDamage()
        {
            Damage.Play(0.7f, 0.0f, 0.0f);
        }

        public void playHeartOrKeyGet()
        {
            HeartOrKeyGet.Play();
        }

        public void playEnemyDeath()
        {
            EnemyDeath.Play();
        }

        public void playBossRoar()
        {
            BossRoar.Play();
        }

        public void playBossDeath()
        {
            BossDeath.Play();
        }

        public void playLinkDamage()
        {
            PlayerDamage.Play(0.2f, 0.0f, 0.0f);
        }

        public void playFlameShot()
        {
            FlameShot.Play();
        }

        public void playBoomerang()
        {
            BoomerangThrow.Play();
        }

        public void playSwordSlash()
        {
            SwordSlash.Play();
        }

        public void playArrowShot()
        {
            ArrowShot.Play();
        }

        public void playBombSounds()
        {
            BombSounds.Play();
        }

        public void playSwordBeam()
        {
            SwordBeam.Play(0.3f, 0.0f, 0.0f);
        }

        public void playTextVoice()
        {
            TextVoice.Play();
        }

        public void playWitchLaugh()
        {
            WitchLaugh.Play();
        }

        public void playMetalSound()
        {
            MetalSound.Play();
        }

        public void playLightningBlast()
        {
            LightningBlast.Play();
        }

        public void playVineBoom()
        {
            VineBoom.Play();
        }

        public void stopMusic()
        {
            MediaPlayer.Stop();
        }
    }
}