/// <summary> /// Adds a GameObject reference to the Objects dictionary /// If a CollidableObject is passed, it is also added to the CollidableObjects List /// </summary> /// <param name="name">GameObject name</param> /// <param name="g">GameObject reference</param> public static void Add(string name, GameObject g) { Objects.Add(name, g); if (g is CollidableObject) { CollidableObject c = (CollidableObject)g; CollidableObjects.Add(c); NonUIObjects.Add(g); } else if (g is Background) { Background b = (Background)g; Backgrounds.Add(b); } else if (g is UIObject) { UIObject ui = (UIObject)g; UIObjects.Add(ui); } else if (g is SFXWrapper) { SFXWrapper wrap = (SFXWrapper)g; SoundEffects.Add(wrap); } else { NonUIObjects.Add(g); } }
/// <summary> /// Plays the sound effect. /// </summary> /// <param name="clipName">Name of the clip as instaniated.</param> public static void PlaySFX(string clipName) { SFXWrapper clip = (SFXWrapper)(Get(clipName)); clip.Play(); }
/// <summary> /// Stop the sound effect. /// </summary> /// <param name="clipName"></param> public static void StopSFX(string clipName) { SFXWrapper clip = (SFXWrapper)(Get(clipName)); clip.Stop(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatchGameplay = new SpriteBatch(GraphicsDevice); spriteBatchUI = new SpriteBatch(GraphicsDevice); spriteBatchBG = new SpriteBatch(GraphicsDevice); //Load textures Textures = new Dictionary <string, Texture2D> { { "CurrentSwim", Content.Load <Texture2D>("Textures/Current/CurrentSwim") }, { "CurrentWalk", Content.Load <Texture2D>("Textures/Current/CurrentWalk") }, { "CurrentIdle", Content.Load <Texture2D>("Textures/Current/CurrentIdle") }, { "WhiteBlock", Content.Load <Texture2D>("Textures/WhiteBlock") }, { "Background", Content.Load <Texture2D>("Textures/Backgrounds/Sunset") }, { "Crossbone", Content.Load <Texture2D>("Textures/HUD/Crossbone") }, { "catfish", Content.Load <Texture2D>("Textures/Enemies/catfish") }, { "deep water tile", Content.Load <Texture2D>("Textures/Tiles/deep water tile") }, { "grass tile", Content.Load <Texture2D>("Textures/Tiles/grass tile") }, { "grass to sand tile", Content.Load <Texture2D>("Textures/Tiles/grass to sand tile") }, { "sand tile", Content.Load <Texture2D>("Textures/Tiles/sand tile") }, { "shore tile", Content.Load <Texture2D>("Textures/Tiles/shore tile") }, { "upper water tile", Content.Load <Texture2D>("Textures/Tiles/upper water tile") }, { "Button", Content.Load <Texture2D>("Textures/HUD/Button") }, { "Laser", Content.Load <Texture2D>("Textures/Items/Laser") } }; //Load Background Music songBg = Content.Load <Song>("Audio/Current"); //Load Sound Effects SoundEffects = new Dictionary <string, SoundEffect> { { "Hover", Content.Load <SoundEffect>("Audio/Hover") }, { "Hurt", Content.Load <SoundEffect>("Audio/Hurt") }, { "Jump", Content.Load <SoundEffect>("Audio/Jump") }, { "Land", Content.Load <SoundEffect>("Audio/Land") }, { "Pickup", Content.Load <SoundEffect>("Audio/Pickup") }, { "Select", Content.Load <SoundEffect>("Audio/Select") }, { "WaterLoop", Content.Load <SoundEffect>("Audio/WaterLoop") }, { "Win", Content.Load <SoundEffect>("Audio/Win") }, { "Laser", Content.Load <SoundEffect>("Audio/Laser") } }; //Load fonts font = Content.Load <SpriteFont>("Fonts/Font"); titleFont = Content.Load <SpriteFont>("Fonts/TitleFont"); hudFont = Content.Load <SpriteFont>("Fonts/HudFont"); //Construct audio holders so we can reference soundeffects through GameManager foreach (string clipName in SoundEffects.Keys) { SFXWrapper wrapper = new SFXWrapper(clipName, SoundEffects[clipName]); } //Play background music //MediaPlayer.Play(songBg); //MediaPlayer.IsRepeating = true; Color buttonBackColor = new Color(50, 80, 130); int bWidth = 400, bHeight = 100; //Create the Main Menu UIImage bMainMenu = new UIImage("bgMainMenu", Textures["Background"], new Point(TargetWidth, TargetHeight), Anchor.UpperLeft, SortingMode.None, GameState.MainMenu, Point.Zero, Color.White); //Main Menu Substate UIText title = new UIText("Title", "Current", titleFont, Anchor.UpperMiddle, SortingMode.None, GameState.MainMenu, Point.Zero, Color.White); UIButton play = new UIButton("PlayB", "Play", font, Textures["Button"], Anchor.CenterMiddle, SortingMode.Below, GameState.MainMenu, Point.Zero, Color.Black, Color.White, bWidth, bHeight); UIButton quit = new UIButton("QuitB", "Quit", font, Textures["Button"], Anchor.CenterMiddle, SortingMode.Below, GameState.MainMenu, new Point(0, 50), Color.Black, Color.White, bWidth, bHeight); //Setup button delegates play.Click += LoadCurrentLevel; quit.Click += () => { Exit(); }; //Setup HUD HealthBar bar = new HealthBar("HealthBar", Textures["Crossbone"], new Point(100, 66)); Score score = new Score("Score", hudFont, Anchor.UpperRight, SortingMode.Below, GameState.Game, Point.Zero, Color.White); LevelDisplay curlevel = new LevelDisplay("LevelDisplay", hudFont, Anchor.UpperRight, SortingMode.Below, GameState.Game, Point.Zero, Color.White); //Setup the pause menu UIImage bgPause = new UIImage("bgPause", Textures["Background"], new Point(TargetWidth, TargetHeight), Anchor.UpperLeft, SortingMode.None, GameState.Game, Point.Zero, Color.White); bgPause.ActiveGameplayState = GameplayState.Paused; UIText pauseText = new UIText("pauseText", "PAUSED", font, Anchor.UpperMiddle, SortingMode.Below, GameState.Game, Point.Zero, Color.White); pauseText.ActiveGameplayState = GameplayState.Paused; UIButton pauseResumeButton = new UIButton("pauseResumeButton", "Resume", font, Textures["Button"], Anchor.CenterMiddle, SortingMode.Below, GameState.Game, new Point(0, 0), Color.Black, Color.White); pauseResumeButton.ActiveGameplayState = GameplayState.Paused; UIButton pauseMainMenuButton = new UIButton("pauseMainMenuButton", "Main Menu", font, Textures["Button"], Anchor.CenterMiddle, SortingMode.Below, GameState.Game, new Point(0, 50), Color.Black, Color.White); pauseMainMenuButton.ActiveGameplayState = GameplayState.Paused; //Pause menu delegates pauseResumeButton.Click += () => { GameManager.gameplayState = GameplayState.Normal; }; pauseMainMenuButton.Click += LoadMainMenu; //Setup the gameover menu UIText gameoverText = new UIText("GameoverText", "You have died.", titleFont, Anchor.CenterMiddle, SortingMode.Below, GameState.Game, Point.Zero, Color.White); gameoverText.ActiveState = GameState.Game; gameoverText.Deactivate(); UIText gameoverInstr = new UIText("GameoverInstr", "Press the jump button to respawn.", font, Anchor.LowerMiddle, SortingMode.Below, GameState.Game, Point.Zero, Color.White); gameoverInstr.ActiveState = GameState.Game; gameoverInstr.Deactivate(); //Setup win level message UIText winText = new UIText("WinText", "Current completed the level!", titleFont, Anchor.CenterMiddle, SortingMode.None, GameState.Game, Point.Zero, Color.White); winText.ActiveState = GameState.Game; winText.Deactivate(); //Setup win game message UIText winGameText = new UIText("WinGameText", "Current was victorious!", titleFont, Anchor.CenterMiddle, SortingMode.None, GameState.Game, Point.Zero, Color.White); winGameText.ActiveState = GameState.Game; winGameText.Deactivate(); //Setup win level buttons UIButton winMainMenuButton = new UIButton("WinMainMenuButton", "Back to Main Menu", font, Textures["Button"], Anchor.LowerLeft, SortingMode.None, GameState.Game, Point.Zero, Color.Black, Color.White); winMainMenuButton.ActiveState = GameState.Game; winMainMenuButton.Deactivate(); //Next level button (part of win menu) UIButton winNextButton = new UIButton("WinNextButton", "Next Level", font, Textures["Button"], Anchor.LowerRight, SortingMode.None, GameState.Game, Point.Zero, Color.Black, Color.White); winNextButton.ActiveState = GameState.Game; winNextButton.Deactivate(); //Back to main menu logic winMainMenuButton.Click += () => { LoadMainMenu(); winMainMenuButton.Deactivate(); winNextButton.Deactivate(); winText.Deactivate(); winGameText.Deactivate(); if (GameManager.CompletedAllLevels) { GameManager.CurrentLevel = 0; } }; winNextButton.Click += () => { winMainMenuButton.Deactivate(); winNextButton.Deactivate(); winText.Deactivate(); winGameText.Deactivate(); LoadCurrentLevel(); }; UIManager.OrganizeObjects(); }