/// <summary> /// Called 60 frames/per second and updates the positions /// of all the drawable objects /// </summary> /// <param name="gameTime"> /// Can work out the elapsed time since last call if /// you want to compensate for different frame rates /// </param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } restartButton.Update(gameTime); playerSprite.Update(gameTime); enemySprite.Update(gameTime); enemySprite2.Update(gameTime); enemySprite3.Update(gameTime); if (playerSprite.HasCollided(enemySprite)) { playerSprite.IsActive = false; playerSprite.IsAlive = false; enemySprite.IsActive = false; LoadContent(); score = 0; } if (playerSprite.HasCollided(enemySprite2)) { playerSprite.IsActive = false; playerSprite.IsAlive = false; enemySprite2.IsActive = false; LoadContent(); score = 0; } if (playerSprite.HasCollided(enemySprite3)) { playerSprite.IsActive = false; playerSprite.IsAlive = false; enemySprite3.IsActive = false; LoadContent(); score = 0; } if (gameTime.TotalGameTime.Milliseconds % 2000 == 0) { score += 10; } if (gameTime.TotalGameTime.Seconds == 8) { SetupEnemy(); SetupEnemy2(); SetupEnemy3(); } base.Update(gameTime); }
/// <summary> /// Called 60 frames/per second and updates the positions /// of all the drawable objects /// </summary> /// <param name="gameTime"> /// Can work out the elapsed time since last call if /// you want to compensate for different frame rates /// </param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } restartButton.Update(gameTime); // Update Asteroids //shipSprite.Update(gameTime); asteroidSprite.Update(gameTime); //if (shipSprite.HasCollided(asteroidSprite) && shipSprite.IsAlive) //{ // flameEffect.Play(); //shipSprite.IsActive = false; //shipSprite.IsAlive = false; //shipSprite.IsVisible = false; //} // Update Chase Game playerSprite.Update(gameTime); enemySprite.Update(gameTime); if (playerSprite.HasCollided(enemySprite)) { playerSprite.IsActive = false; playerSprite.IsAlive = false; enemySprite.IsActive = false; } if (playerSprite.HasCollided(asteroidSprite)) { playerSprite.IsActive = false; playerSprite.IsAlive = false; playerSprite.CanWalk = false; asteroidSprite.IsActive = false; } coinsController.Update(gameTime); coinsController.HasCollided(playerSprite); base.Update(gameTime); }
/// <summary> /// Called 60 frames/per second and updates the positions /// of all the drawable objects /// </summary> /// Can work out the elapsed time since last call if /// you want to compensate for different frame rates /// </param> protected override void Update(GameTime gameTime) { gameState = GameState.PLAYING; if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } restartButton.Update(gameTime); quitButton.Update(gameTime); playerSprite.Update(gameTime); enemyController.Update(gameTime); enemyController.HasCollided(playerSprite); coinsController.Update(gameTime); playerSprite.Score += coinsController.HasCollided(playerSprite); // Player wins the game if their score is over 800. if (playerSprite.Score >= MAX_SCORE) { gameState = GameState.WON; enemyController.RemoveEnemy(); playerController.RemovePlayer(); } else if (playerSprite.HasCollided(enemySprite)) { gameState = GameState.LOST; enemyController.RemoveEnemy(); playerController.RemovePlayer(); } base.Update(gameTime); }
/// <summary> /// Update player, enemy and coins /// </summary> public void Update(GameTime gameTime) { pauseButton.Update(gameTime); if (!game.Paused) { playerSprite.Update(gameTime); enemySprite.Update(gameTime); if (playerSprite.HasCollided(enemySprite)) { playerSprite.IsActive = false; playerSprite.IsAlive = false; enemySprite.IsActive = false; } coinsController.Update(gameTime); coinsController.DetectCollision(playerSprite); } }
/// <summary> /// Called 60 frames/per second and updates the positions /// of all the drawable objects /// </summary> /// <param name="gameTime"> /// Can work out the elapsed time since last call if /// you want to compensate for different frame rates /// </param> protected override void Update(GameTime gameTime) { if (gameState == GameStates.starting) { gameState = GameStates.playing; } if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } restartButton.Update(gameTime); // Update Chase Game playerSprite.Update(gameTime); enemySprite.Update(gameTime); // todo when enemy gets to the left hand side reposition the enemy up or down //reposition it so it moves right. if (playerSprite.HasCollided(enemySprite)) { playerSprite.IsActive = false; playerSprite.IsAlive = false; enemySprite.IsActive = false; gameState = GameStates.lost; } coinsController.Update(gameTime); coinsController.HasCollided(playerSprite); if (playerSprite.Score == 100) { gameState = GameStates.won; } base.Update(gameTime); }