private void PauseGame() { this.IsMouseVisible = true; Mouse.SetPosition(450, 450); UpdateApp = UpdatePauseMenu; DrawApp = DrawPauseMenu; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { UpdateApp = UpdateMainMenu; DrawApp = DrawMainMenu; if (File.Exists(saveFileName)) { FileStream stream = File.Open(saveFileName, FileMode.OpenOrCreate, FileAccess.Read); try { XmlSerializer serializer = new XmlSerializer(typeof(SaveData)); SaveData data = (SaveData)serializer.Deserialize(stream); SoundEffect.MasterVolume = data.soundLevel; } finally { stream.Close(); } } else { SoundEffect.MasterVolume = 1; } base.Initialize(); }
public void EndGame() { GraphicsDevice.Clear(Color.CornflowerBlue); endGameSound.Play(); endRainLoop.Volume = 0; endRainLoop.Play(); fadeTimer = 0; fadeRatio = 0; restartButton.ButtonAlpha = 0; mainMenuButton.ButtonAlpha = 0; textFadeDone = false; blackFadeDone = false; DrawApp = DrawGameOver; UpdateApp = UpdateGameOver; }
private void RestartGame() { endRainLoop.Stop(); this.IsMouseVisible = false; fadeTimer = 0; fadeRatio = 0; KeyControls controls = new KeyControls(Keys.W, Keys.S, Keys.A, Keys.D, Keys.Up, Keys.Down, Keys.Left, Keys.Right, Keys.F); player = new Player(400, 400, controls, Content.Load <Texture2D>("player"), Content.Load <SoundEffect>("grunt"), this); RangedStats rangedStats = BasicWeapon.BASE_RANGED_STATS; MeleeStats meleeStats = new MeleeStats(ZombieWeapon.BASE_M_KNOCK_BACK_AMOUNT, ZombieWeapon.BASE_M_KNOCK_BACK_SPEED, ZombieWeapon.BASE_M_RELOAD_TIME_MS, ZombieWeapon.BASE_M_RANGE + 25); player.Weapon = new BasicWeapon(player, rangedStats, meleeStats, Content.Load <Texture2D>("bullet"), whiteTexture, Content.Load <SoundEffect>("BasicGunshot")); //player.Weapon = new Shotgun(player, rangedStats, meleeStats, Content.Load<Texture2D>("bullet"), whiteTexture, Content.Load<SoundEffect>("BasicGunshot")); shotgun = new Shotgun(player, Shotgun.BASE_RANGED_STATS, null, Content.Load <Texture2D>("bullet"), whiteTexture, Content.Load <SoundEffect>("shotgun")); Arena_Bounds = new Rectangle(50, 50, 800, 800); projectiles = new List <Projectile>(); monsters = new List <Monster>(); projectileRemoveList = new List <Projectile>(); monsterRemoveList = new List <Monster>(); meleeAttacks = new List <MeleeAttack>(); powerups = new List <Powerup>(); powerupRemoveList = new List <Powerup>(); spawner = new Spawner(player, Content.ServiceProvider); spawner.AddSpawners(new Vector2(Arena_Bounds.X + Arena_Bounds.Width / 4, Arena_Bounds.Y), new Vector2(Arena_Bounds.X + (3 * Arena_Bounds.Width) / 4, Arena_Bounds.Y), new Vector2(Arena_Bounds.X + Arena_Bounds.Width / 4, Arena_Bounds.Y + Arena_Bounds.Height), new Vector2(Arena_Bounds.X + (3 * Arena_Bounds.Width) / 4, Arena_Bounds.Y + Arena_Bounds.Height) ); if (firstTime) { UpdateApp = UpdateTutorial; DrawApp = DrawTutorial; IsMouseVisible = true; firstTime = false; } else { UpdateApp = UpdateGame; DrawApp = DrawGame; spawner.StartWave(); } }
private void ResumeGame() { this.IsMouseVisible = false; UpdateApp = UpdateGame; DrawApp = DrawGame; }
private void TriggerMainMenu() { endRainLoop.Play(); UpdateApp = UpdateMainMenu; DrawApp = DrawMainMenu; }
/// <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. spriteBatch = new SpriteBatch(GraphicsDevice); gameFont = Content.Load <SpriteFont>("gameFont"); whiteTexture = Content.Load <Texture2D>("white"); Powerup.Powerup_Sprites = Content.Load <Texture2D>("powerups"); hearts = Content.Load <Texture2D>("heart"); arenaTexture = Content.Load <Texture2D>("arena_background"); gameOverFont = Content.Load <SpriteFont>("GameOverFont"); killCountFont = Content.Load <SpriteFont>("KillCountFont"); gameOverButtonFont = Content.Load <SpriteFont>("GameOverButtonFont"); mainMenuButtonFont = Content.Load <SpriteFont>("MainMenuButtonFont"); mainMenuTitleFont = Content.Load <SpriteFont>("MainMenuTitleFont"); pauseMenuTitleFont = Content.Load <SpriteFont>("PauseMenuFont"); pauseMenuButtonFont = Content.Load <SpriteFont>("PauseMenuButtonFont"); endGameSound = Content.Load <SoundEffect>("endsound"); endGameRain = Content.Load <SoundEffect>("rain"); mainMenuSliderFont = Content.Load <SpriteFont>("MainMenuSliderFont"); tutorialOkayButtonFont = Content.Load <SpriteFont>("TutorialOkayButtonFont"); tutPicture = Content.Load <Texture2D>("tutpic"); endRainLoop = endGameRain.CreateInstance(); mainMenuButton = new Button(85, 700, 300, 100, "Main Menu", gameOverButtonFont, Color.Black, whiteTexture, Color.Gray); mainMenuButton.ClickSound = Content.Load <SoundEffect>("click"); restartButton = new Button(500, 700, 300, 100, "Restart Game", gameOverButtonFont, Color.Black, whiteTexture, Color.Gray); restartButton.ClickSound = Content.Load <SoundEffect>("click"); mainMenuButton.ButtonAlpha = 0; restartButton.ButtonAlpha = 0; mainMenuPlayButton = new Button(237, 350, 425, 200, "Play Game", mainMenuButtonFont, Color.Black, whiteTexture, Color.Gray); mainMenuPlayButton.ClickSound = Content.Load <SoundEffect>("click"); mainMenuExitButton = new Button(237, 625, 425, 200, "Exit Game", mainMenuButtonFont, Color.Black, whiteTexture, Color.Gray); mainMenuExitButton.ClickSound = Content.Load <SoundEffect>("click"); pResumeButton = new Button(300, 375, 300, 125, "Resume", pauseMenuButtonFont, Color.Black, whiteTexture, Color.Gray); pResumeButton.ClickSound = Content.Load <SoundEffect>("click"); pMainMenuButton = new Button(300, 525, 300, 125, "Main Menu", pauseMenuButtonFont, Color.Black, whiteTexture, Color.Gray); pMainMenuButton.ClickSound = Content.Load <SoundEffect>("click"); pExitButton = new Button(300, 675, 300, 125, "Exit", pauseMenuButtonFont, Color.Black, whiteTexture, Color.Gray); pExitButton.ClickSound = Content.Load <SoundEffect>("click"); mainMenuSoundSlider = new Slider(775, 450, 40, 20, 10, 300, whiteTexture, Color.Gray, Orientation.Vertical, SoundEffect.MasterVolume); mainMenuSoundSlider.SliderReleased += ChangeSoundLevel; mainMenuSoundSlider.ReleaseSound = Content.Load <SoundEffect>("click"); pauseMenuSoundSlider = new Slider(750, 450, 40, 20, 10, 300, whiteTexture, Color.Gray, Orientation.Vertical, SoundEffect.MasterVolume); pauseMenuSoundSlider.SliderReleased += ChangeSoundLevel; pauseMenuSoundSlider.ReleaseSound = Content.Load <SoundEffect>("click"); restartButton.ButtonClicked += RestartGame; mainMenuButton.ButtonClicked += TriggerMainMenu; mainMenuPlayButton.ButtonClicked += RestartGame; mainMenuExitButton.ButtonClicked += () => this.QuitGame(); pExitButton.ButtonClicked += () => this.QuitGame(); pMainMenuButton.ButtonClicked += TriggerMainMenu; pResumeButton.ButtonClicked += ResumeGame; mainMenuTitleLoc = (-mainMenuTitleFont.MeasureString("Gladiator") + new Vector2(graphics.PreferredBackBufferWidth, 400)) / 2; pauseMenuTitleLoc = (-pauseMenuTitleFont.MeasureString("Paused") + new Vector2(graphics.PreferredBackBufferWidth, 400)) / 2; endRainLoop.IsLooped = true; endRainLoop.Play(); endRainLoop.Volume = .6f; Vector2 dim = mainMenuSliderFont.MeasureString("Volume"); menuSoundSliderLoc = new Vector2(mainMenuSoundSlider.X - dim.X / 2 + mainMenuSoundSlider.Width / 2, mainMenuSoundSlider.Y - dim.Y * 1.1f); dim = pauseMenuButtonFont.MeasureString("Volume"); pauseMenuSliderLoc = new Vector2(pauseMenuSoundSlider.X - dim.X / 2 + pauseMenuSoundSlider.Width / 2, pauseMenuSoundSlider.Y - dim.Y * 1.1f); tutorialOkayButton = new Button(300, 700, 300, 100, "Got it!", tutorialOkayButtonFont, Color.Black, whiteTexture, Color.Gray); tutorialOkayButton.ClickSound = Content.Load <SoundEffect>("click"); tutorialOkayButton.ButtonClicked += () => { UpdateApp = UpdateGame; DrawApp = DrawGame; this.IsMouseVisible = false; }; //RangedStats skelerange = new RangedStats(SkeleWeapon.BASE_R_KNOCK_BACK_AMOUNT, SkeleWeapon.BASE_R_KNOCK_BACK_SPEED, SkeleWeapon.BASE_R_RELOAD_TIME_MS, SkeleWeapon.BASE_R_RANGE, SkeleWeapon.BASE_BULLET_SPEED, SkeleWeapon.BASE_BULLET_WIDTH, SkeleWeapon.BASE_BULLET_HEIGHT); //Skelebro skeleBro = new Skelebro(400, 400, player, Content.Load<Texture2D>("skeleton")); //skeleBro.Weapon = new SkeleWeapon(skeleBro, skelerange, null, Content.Load<Texture2D>("white"), Content.Load<Texture2D>("white")); //monsters.Add(skeleBro); //MeleeStats meleeStats = new MeleeStats(ZombieWeapon.BASE_M_KNOCK_BACK_AMOUNT, ZombieWeapon.BASE_M_KNOCK_BACK_SPEED, ZombieWeapon.BASE_M_RELOAD_TIME_MS, ZombieWeapon.BASE_M_RANGE); //Zombie debug_Zombie = new Zombie(100, 100, player, Content.Load<Texture2D>("white")); //debug_Zombie.Weapon = new ZombieWeapon(debug_Zombie, null, meleeStats, Content.Load<Texture2D>("white"), Content.Load<Texture2D>("white")); //mobs.Add(debug_Zombie); //Zombie debug_Zombie2 = new Zombie(300, 100, player, Content.Load<Texture2D>("white")); //debug_Zombie2.Weapon = new ZombieWeapon(debug_Zombie, null, meleeStats, Content.Load<Texture2D>("white"), Content.Load<Texture2D>("white")); //mobs.Add(debug_Zombie2); //Zombie debug_Zombie3 = new Zombie(300, 300, player, Content.Load<Texture2D>("white")); //debug_Zombie3.Weapon = new ZombieWeapon(debug_Zombie, null, meleeStats, Content.Load<Texture2D>("white"), Content.Load<Texture2D>("white")); //mobs.Add(debug_Zombie3); }