/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } // TODO: Add your update logic here switch (gameState) { case GameStates.HomeScreen: HomeScreenTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (HomeScreenTimer >= HomeScreenDelayTime) { if ((Keyboard.GetState().IsKeyDown(Keys.Space)) || (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed)) { playerManager.LivesRemaining = playerStartingLives; playerManager.PlayerScore = 0; resetGame(); gameState = GameStates.Playing; } } break; case GameStates.Playing: starField.Update(gameTime); asteroidManager.Update(gameTime); playerManager.Update(gameTime); enemyManager.Update(gameTime); explosionManager.Update(gameTime); collisionManager.CheckCollisions(); if (playerManager.Destroyed) { playerDeathTimer = 0f; enemyManager.Active = false; playerManager.LivesRemaining--; if (playerManager.LivesRemaining < 0) { gameState = GameStates.GameOver; } else { gameState = GameStates.PlayerDead; } } break; case GameStates.PlayerDead: playerDeathTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; starField.Update(gameTime); asteroidManager.Update(gameTime); enemyManager.Update(gameTime); playerManager.PlayerShotManager.Update(gameTime); explosionManager.Update(gameTime); if (playerDeathTimer >= playerDeathDelayTime) { resetGame(); gameState = GameStates.Playing; } break; case GameStates.GameOver: playerDeathTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; starField.Update(gameTime); asteroidManager.Update(gameTime); enemyManager.Update(gameTime); playerManager.PlayerShotManager.Update(gameTime); explosionManager.Update(gameTime); if (playerDeathTimer >= playerDeathDelayTime) { gameState = GameStates.HomeScreen; } break; } base.Update(gameTime); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } EffectManager.Update(gameTime); // TODO: Add your update logic here KeyboardState kb = Keyboard.GetState(); switch (gameState) { case GameStates.TitleScreen: SoundManager.StopSong(); titleScreenTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (titleScreenTimer >= titleScreenDelayTime) { if ((Keyboard.GetState().IsKeyDown(Keys.Space)) || (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed)) { playerManager.LivesRemaining = playerStartingLives; playerManager.PlayerScore = 0; resetGame(); gameState = GameStates.DifficultySelect; } } break; case GameStates.CreditsScreen: if (kb.IsKeyDown(Keys.R)) { gameState = GameStates.TitleScreen; } break; case GameStates.Pause: if (kb.IsKeyDown(Keys.P)) { gameState = GameStates.Playing; } break; case GameStates.DifficultySelect: //WORK ON DIFFICULTY if (kb.IsKeyDown(Keys.D1)) { //CHANGING DIFFICULTY LEVEL difficultyLevel = 1; gameState = GameStates.Playing; //LIVES - 1, because the game includes 0 as a life. Total lives are lives remaining + 1. Fixed it in the display, so life 1 is your last life. playerManager.LivesRemaining = 5; //ENEMIES enemyManager.MinShipsPerWave = 2; enemyManager.MaxShipsPerWave = 4; //ASTEROIDS asteroidManager.minSpeed = 40; asteroidManager.maxSpeed = 80; //SCORES collisionManager.enemyPointValue = 50; for (int i = 0; i < 7; i++) { asteroidManager.AddAsteroid(); } } else if (kb.IsKeyDown(Keys.D2)) { difficultyLevel = 2; gameState = GameStates.Playing; playerManager.LivesRemaining = 2; enemyManager.MinShipsPerWave = 6; enemyManager.MaxShipsPerWave = 8; asteroidManager.minSpeed = 60; asteroidManager.maxSpeed = 120; collisionManager.enemyPointValue = 100; for (int i = 0; i < 10; i++) { asteroidManager.AddAsteroid(); } } else if (kb.IsKeyDown(Keys.D3)) { difficultyLevel = 3; gameState = GameStates.Playing; playerManager.LivesRemaining = 1; enemyManager.MinShipsPerWave = 12; enemyManager.MaxShipsPerWave = 16; asteroidManager.minSpeed = 100; asteroidManager.maxSpeed = 140; collisionManager.enemyPointValue = 200; for (int i = 0; i < 13; i++) { asteroidManager.AddAsteroid(); } } else if (kb.IsKeyDown(Keys.D4)) { difficultyLevel = 4; playerManager.isD4 = true; gameState = GameStates.Playing; playerManager.LivesRemaining = 0; enemyManager.MinShipsPerWave = 20; enemyManager.MaxShipsPerWave = 24; asteroidManager.minSpeed = 160; asteroidManager.maxSpeed = 220; collisionManager.enemyPointValue = 400; playerManager.PowerupLevel = 4; for (int i = 0; i < 15; i++) { asteroidManager.AddAsteroid(); } } else if (kb.IsKeyDown(Keys.D9)) //Survival Mode. Score = time played. No enemies. { difficultyLevel = 9; gameState = GameStates.Playing; playerManager.LivesRemaining = 1; enemyManager.MinShipsPerWave = 0; enemyManager.MaxShipsPerWave = 0; asteroidManager.minSpeed = 200; asteroidManager.maxSpeed = 300; playerManager.playerSpeed = 400.0f; for (int i = 0; i < 20; i++) { asteroidManager.AddAsteroid(); } } //Cheat Code Viewer else if (kb.IsKeyDown(Keys.D5)) { gameState = GameStates.ccViewer; } if (kb.IsKeyDown(Keys.Z)) { gameState = GameStates.CreditsScreen; } break; case GameStates.ccViewer: if (kb.IsKeyDown(Keys.R)) { gameState = GameStates.DifficultySelect; } break; case GameStates.Playing: starField.Update(gameTime); asteroidManager.Update(gameTime); playerManager.Update(gameTime); enemyManager.Update(gameTime); explosionManager.Update(gameTime); collisionManager.CheckCollisions(); planetManager.Update(gameTime); if (playerManager.Destroyed) { SoundManager.PlayPlayerDeath(); playerDeathTimer = 0f; enemyManager.Active = false; playerManager.LivesRemaining--; if (playerManager.LivesRemaining < 0) { gameState = GameStates.GameOver; } else { gameState = GameStates.PlayerDead; } } //RESET FUNCTION if (kb.IsKeyDown(Keys.R)) { resetGame(); gameState = GameStates.DifficultySelect; playerManager.PlayerScore = 0; playerManager.playerSpeed = 320.0f; playerTimePlayed = 0f; asteroidManager.Clear(); playerManager.PowerupLevel = 1; } //PAUSE FUNCTION if (kb.IsKeyDown(Keys.P)) { gameState = GameStates.Pause; } //CHEAT CODES FOR LOSERS //Press 6 & 9 on Keypad to change lives to 69. if (kb.IsKeyDown(Keys.D6) && kb.IsKeyDown(Keys.D9)) { playerManager.LivesRemaining = 68; } //KYS if (kb.IsKeyDown(Keys.K) && kb.IsKeyDown(Keys.Y) && kb.IsKeyDown(Keys.S)) { playerManager.Destroyed = true; SoundManager.PlayPlayerDeath(); } //AND THIS IS TO GO EVEN FURTHER BEYOND! (Work on This) if (kb.IsKeyDown(Keys.S) && kb.IsKeyDown(Keys.D3)) { playerManager.playerSpeed = 480.0f; asteroidManager.minSpeed = 60; asteroidManager.maxSpeed = 120; playerManager.PowerupLevel = 2; SoundManager.PlayGoku(); } //Smokemon if (kb.IsKeyDown(Keys.D4) && kb.IsKeyDown(Keys.D2) && kb.IsKeyDown(Keys.D0)) { isWeed = true; SoundManager.PlaySmokemon(); //Plays Smokemon, but does not reset when you rest. starField = new StarField( this.Window.ClientBounds.Width, this.Window.ClientBounds.Height, 200, new Vector2(0, 30f), weedBG, new Rectangle(0, 0, 800, 600)); } /* * Automatic difficulty adjustment based on your progress * if (difficultyLevel == 4 && playerManager.LivesRemaining > 1 && playerManager.LivesRemaining < 59) * { * asteroidManager.minSpeed = 170; * asteroidManager.maxSpeed = 270; * } */ break; case GameStates.PlayerDead: playerDeathTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; starField.Update(gameTime); asteroidManager.Update(gameTime); enemyManager.Update(gameTime); playerManager.PlayerShotManager.Update(gameTime); explosionManager.Update(gameTime); planetManager.Update(gameTime); if (playerDeathTimer >= playerDeathDelayTime) { resetGame(); gameState = GameStates.Playing; } //RESET FUNCTION kb = Keyboard.GetState(); if (kb.IsKeyDown(Keys.R)) { resetGame(); gameState = GameStates.DifficultySelect; playerManager.PlayerScore = 0; playerManager.playerSpeed = 320.0f; playerTimePlayed = 0f; asteroidManager.Clear(); playerManager.PowerupLevel = 1; } break; case GameStates.GameOver: playerDeathTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; starField.Update(gameTime); asteroidManager.Update(gameTime); enemyManager.Update(gameTime); playerManager.PlayerShotManager.Update(gameTime); explosionManager.Update(gameTime); planetManager.Update(gameTime); if (playerDeathTimer >= playerDeathDelayTime) { gameState = GameStates.TitleScreen; } //RESET FUNCTION kb = Keyboard.GetState(); if (kb.IsKeyDown(Keys.R)) { resetGame(); gameState = GameStates.DifficultySelect; playerManager.PlayerScore = 0; playerManager.playerSpeed = 320.0f; playerTimePlayed = 0f; asteroidManager.Clear(); playerManager.PowerupLevel = 1; } break; } base.Update(gameTime); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } switch (gameState) { case GameStates.TitleScreen: titleScreenTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (titleScreenTimer >= titleScreenDelayTime) { if (Keyboard.GetState().IsKeyDown(Keys.Space) || (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed)) { playerManager.LivesRemaining = playerStartingLives; playerManager.PlayerScore = 0; ResetGame(); gameState = GameStates.Playing; } } break; case GameStates.Playing: starField.Update(gameTime); asteroidManager.Update(gameTime); playerManager.Update(gameTime); enemyManager.Update(gameTime); explosionManager.Update(gameTime); collisionManager.CheckCollisions(); if (playerManager.Destroyed) { playerDeathTimer = 0; enemyManager.Active = false; playerManager.LivesRemaining--; if (playerManager.LivesRemaining < 0) { gameState = GameStates.GameOver; } else { gameState = GameStates.PlayerDead; } } break; case GameStates.PlayerDead: playerDeathTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; starField.Update(gameTime); asteroidManager.Update(gameTime); enemyManager.Update(gameTime); playerManager.PlayerShotManager.Update(gameTime); explosionManager.Update(gameTime); if (playerDeathTimer >= playerDeathDelayTime) { ResetGame(); gameState = GameStates.Playing; } break; case GameStates.GameOver: playerDeathTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; starField.Update(gameTime); asteroidManager.Update(gameTime); enemyManager.Update(gameTime); playerManager.PlayerShotManager.Update(gameTime); explosionManager.Update(gameTime); if (playerDeathTimer >= playerDeathDelayTime) { gameState = GameStates.TitleScreen; } break; } base.Update(gameTime); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } // TODO: Add your update logic here switch (gameState) { case GameStates.TitleScreen: titleScreenTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (titleScreenTimer >= titleScreenDelayTime) { if ((Keyboard.GetState().IsKeyDown(Keys.Space)) || (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed)) { playerManager.LivesRemaining = playerStartingLives; playerManager.healthRemaining = playerStartingHealth; playerManager.PlayerScore = 0; resetGame(); gameState = GameStates.Playing; } } break; case GameStates.Playing: starField.Update(gameTime); planetManager.Update(gameTime); asteroidManager.Update(gameTime); playerManager.Update(gameTime); enemyManager.Update(gameTime); explosionManager.Update(gameTime); collisionManager.CheckCollisions(); if (playerManager.Destroyed) { playerDeathTimer = 0f; enemyManager.Active = false; playerManager.LivesRemaining--; if (playerManager.LivesRemaining < 0) { gameState = GameStates.GameOver; } else { gameState = GameStates.PlayerDead; } } if ((playerManager.PlayerScore / pointsPerLevel) + 1 != playerManager.CurrentLevel) { playerManager.CurrentLevel = 1 + playerManager.PlayerScore / pointsPerLevel; gameState = GameStates.LevelUp; } if (playerManager.CurrentLevel == 6) { gameState = GameStates.Win; } break; case GameStates.PlayerDead: playerDeathTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; starField.Update(gameTime); asteroidManager.Update(gameTime); enemyManager.Update(gameTime); playerManager.PlayerShotManager.Update(gameTime); explosionManager.Update(gameTime); if (playerDeathTimer >= playerDeathDelayTime) { resetGame(); gameState = GameStates.Playing; } break; case GameStates.GameOver: playerDeathTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; starField.Update(gameTime); asteroidManager.Update(gameTime); enemyManager.Update(gameTime); playerManager.PlayerShotManager.Update(gameTime); explosionManager.Update(gameTime); if (playerDeathTimer >= playerDeathDelayTime) { gameState = GameStates.TitleScreen; } break; case GameStates.LevelUp: playerDeathTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; starField.Update(gameTime); asteroidManager.Update(gameTime); enemyManager.Update(gameTime); playerManager.PlayerShotManager.Update(gameTime); explosionManager.Update(gameTime); if (playerDeathTimer >= playerDeathDelayTime) { if (playerManager.CurrentLevel == 2) { playerManager.minShotTimer = 0.15f; enemyManager.MinShipsPerWave = 6; enemyManager.MaxShipsPerWave = 9; } resetGame(); gameState = GameStates.Playing; } break; case GameStates.Win: playerDeathTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; starField.Update(gameTime); asteroidManager.Update(gameTime); enemyManager.Update(gameTime); playerManager.PlayerShotManager.Update(gameTime); explosionManager.Update(gameTime); if (playerDeathTimer >= playerDeathDelayTime) { gameState = GameStates.TitleScreen; } break; } base.Update(gameTime); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } // TODO: Add your update logic here switch (gameState) { case GameStates.TitleScreen: titleScreenTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (titleScreenTimer >= titleScreenDelayTime) { if ((Keyboard.GetState().IsKeyDown(Keys.Space)) || (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed)) { playerManager.LivesRemaining = playerStartingLives; playerManager.PlayerScore = 0; resetGame(); gameState = GameStates.Playing; } } break; case GameStates.Playing: for (int i = 0; i < starFields.Count; i++) { starFields[i].Update(gameTime); } asteroidManager.Update(gameTime); playerManager.Update(gameTime); if (gameState != GameStates.BossBattle) { enemyManager.Update(gameTime); } explosionManager.Update(gameTime); collisionManager.CheckCollisions(); planetManager.Update(gameTime); if (playerManager.Destroyed) { playerDeathTimer = 0f; enemyManager.Active = false; playerManager.LivesRemaining--; if (playerManager.LivesRemaining < 0) { gameState = GameStates.GameOver; spriteBatch.Draw(Guydish, new Rectangle(0, 0, this.Window.ClientBounds.Width, this.Window.ClientBounds.Height), Color.White); } else { gameState = GameStates.PlayerDead; } } if (playerManager.PlayerScore >= 1000) { gameState = GameStates.BossBattle; asteroidManager.Clear(); enemyManager.Enemies.Clear(); } break; case GameStates.PlayerDead: playerDeathTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; for (int i = 0; i < starFields.Count; i++) { starFields[i].Update(gameTime); } asteroidManager.Update(gameTime); enemyManager.Update(gameTime); playerManager.PlayerShotManager.Update(gameTime); explosionManager.Update(gameTime); planetManager.Update(gameTime); if (playerDeathTimer >= playerDeathDelayTime) { resetGame(); gameState = GameStates.Playing; } break; case GameStates.GameOver: playerDeathTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; for (int i = 0; i < starFields.Count; i++) { starFields[i].Update(gameTime); } asteroidManager.Update(gameTime); enemyManager.Update(gameTime); playerManager.PlayerShotManager.Update(gameTime); explosionManager.Update(gameTime); planetManager.Update(gameTime); if (playerDeathTimer >= playerDeathDelayTime) { gameState = GameStates.TitleScreen; } break; case GameStates.BossBattle: for (int i = 0; i < starFields.Count; i++) { starFields[i].Update(gameTime); } playerManager.Update(gameTime); enemyManager.Update(gameTime); explosionManager.Update(gameTime); collisionManager.CheckCollisions(); planetManager.Update(gameTime); break; } base.Update(gameTime); }