using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Audio; namespace SnakeRPG { public static class Audio { static Dictionary sounds = new Dictionary(); static Dictionary musics = new Dictionary(); static SoundEffectInstance currentMusic = null; static string[] soundEffects = new string[] { "coin", "death", "gethit", "hitenemy", "levelup", "powerup", "heal", "pay", "select", "cursor" }; static string[] musicFiles = new string[] { "EnterTheDungeon", "Fields", "GrandVictory", "Nature", "Preparations", "StartOfALegend", "TheSlimeKing", "Welcome" }; public static void LoadContent(ContentManager content) { for (int i = 0; i < soundEffects.Length; i++) { sounds.Add(soundEffects[i], content.Load("Audio/" + soundEffects[i])); } for (int i = 0; i < musicFiles.Length; i++) { musics.Add(musicFiles[i].ToLower(), content.Load("Music/" + musicFiles[i])); } } public static void Play(string sound) { if (sounds.ContainsKey(sound)) { sounds[sound].Play(); } } public static void Start(string music, bool loop = true) { Stop(); if (musics.ContainsKey(music)) { currentMusic = musics[music].CreateInstance(); currentMusic.IsLooped = loop; currentMusic.Play(); } } public static void Stop() { if (currentMusic != null) { currentMusic.Stop(); currentMusic = null; } } } }