void Rotate() { angle = 0; targetAngle = targetAngle % 360; targetAngle = angle + (new Random()).Next(1, 1) * 90; substate = GameSubstate.Rotating; uiPlayer.StartRotate(); uiAIPlayer.StartRotate(); uiFood.StartRotate(); currentMazeDirection = (MoveDirection)(((int)currentMazeDirection + 1) % (int)MoveDirection.NIL); }
public void Update(float elapsedSeconds) { switch (state) { case GameState.Ready: totalElapsedSeconds += elapsedSeconds; if (totalElapsedSeconds > 2) { SetState(GameState.Playing); } break; case GameState.Playing: switch (substate) { case GameSubstate.Normal: totalElapsedSeconds += elapsedSeconds; if (player != null) { player.Update(elapsedSeconds); } if (aiPlayer != null) { aiPlayer.Update(elapsedSeconds); } if (food != null) { food.Update(elapsedSeconds); } if (player.IsCollideWith(food)) { isPlayerWin = true; SetState(GameState.Finished); } else if (aiPlayer != null && aiPlayer.IsCollideWith(food)) { isPlayerWin = false; SetState(GameState.Finished); } if (totalElapsedSeconds > 15.0f) { Random rand = new Random(); if (rand.Next(0, 100) % 7 == 0) { Rotate(); totalElapsedSeconds = 0; } } break; case GameSubstate.Rotating: angle += 5; if (angle >= targetAngle) { angle = targetAngle; substate = GameSubstate.Normal; } double rad = angle * Math.PI / 180; foreach (UIWall wall in uiWalls) { wall.Rotate(centerPoint, rad, targetAngle, angle >= targetAngle); } uiPlayer.Rotate(centerPoint, rad, targetAngle, angle >= targetAngle); uiAIPlayer.Rotate(centerPoint, rad, targetAngle, angle >= targetAngle); uiFood.Rotate(centerPoint, rad, targetAngle, angle >= targetAngle); if (substate == GameSubstate.Normal) { RotateAll(); } break; } break; case GameState.Paused: break; case GameState.Finished: totalElapsedSeconds += elapsedSeconds; break; } }
protected override void Update(GameTime gameTime) { MouseState mouseState = Mouse.GetState(); switch (_currectGameState) { case GameState.mainMenu: switch (_currectGameSubstate) { case GameSubstate.uninitilized: _stateStartTime = gameTime.TotalGameTime; _currectGameSubstate = GameSubstate.loading; IsMouseVisible = true; PlayMenuMusic(); _fadeBox.FadeIn(); _levelNumber = 1; break; case GameSubstate.loading: if (_fadeBox.State == FadeBox.FadeState.Idle) { _currectGameSubstate = GameSubstate.active; } break; case GameSubstate.active: if(MousePressedOverViewport(mouseState)) { _currectGameSubstate = GameSubstate.unloading; _menuMusic.Stop(AudioStopOptions.Immediate); _fadeBox.FadeOut(); } break; case GameSubstate.unloading: if (_fadeBox.State == FadeBox.FadeState.Idle) { _currectGameState = GameState.activeLevel; _currectGameSubstate = GameSubstate.uninitilized; } break; default: break; } break; case GameState.activeLevel: _spawnManager.Update(gameTime); _powerup.Update(gameTime); switch (_currectGameSubstate) { case GameSubstate.uninitilized: _stateStartTime = gameTime.TotalGameTime; _currectGameSubstate = GameSubstate.loading; _fadeBox.FadeIn(); IsMouseVisible = false; _spidersKilled = 0; _fireAntsKilled = 0; _reticle.Reload(); _spawnManager.Components.Clear(); _bulletCraters.Clear(); _spawnManager.LevelStartTime = gameTime.TotalGameTime; _spawnManager.LevelNumber = _levelNumber; ResetPowerupSpawn(gameTime); _soundBank.PlayCue("76405__dsp9000__old-church-bell"); PlayLevelMusic(); break; case GameSubstate.loading: if (_fadeBox.State == FadeBox.FadeState.Idle) { _currectGameSubstate = GameSubstate.active; } break; case GameSubstate.active: _reticle.Update(gameTime); if (_reticle.FiredThisFrame) { Point shotPos = new Point((int)_reticle.Position.X, (int)_reticle.Position.Y); // Add bullet impact crater sprite. _bulletCraters.Add( new Sprite(this, _bulletCraterImage, new Vector2(shotPos.X - (_bulletCraterImage.Width / 2), shotPos.Y - (_bulletCraterImage.Height / 2) + 3))); if (_powerup.ContainsPoint(shotPos)) { _reticle.StartPowerUp(gameTime); _powerup.Remove(); } foreach (AutomatedSprite bug in _spawnManager.Components) { // Check for reticle collisions if (!bug.IsDead() && bug.CollisionRect.Contains(shotPos)) { bug.Hurt(); if (bug.IsDead()) { if (bug.Predator) { FireAntKilled(); } else { SpiderKilled(); } } } } } if (gameTime.TotalGameTime > _nextPowerupSpawn) { SpawnPowerup(gameTime); } if (_levelDuration < (gameTime.TotalGameTime - _stateStartTime)) { _currectGameSubstate = GameSubstate.unloading; _levelMusic.Stop(AudioStopOptions.Immediate); _fadeBox.FadeOut(); } break; case GameSubstate.unloading: if (_fadeBox.State == FadeBox.FadeState.Idle) { _currectGameState = GameState.gameOver; _currectGameSubstate = GameSubstate.uninitilized; } break; default: break; } break; case GameState.gameOver: switch (_currectGameSubstate) { case GameSubstate.uninitilized: _stateStartTime = gameTime.TotalGameTime; _currectGameSubstate = GameSubstate.loading; _fadeBox.FadeIn(); if (_spidersKilled >= _spiderKillsRequired && _fireAntsKilled >= _fireAntKillsRequired) { PlayEndWinMusic(); } else { PlayEndLoseMusic(); } IsMouseVisible = true; break; case GameSubstate.loading: if (_fadeBox.State == FadeBox.FadeState.Idle) { _currectGameSubstate = GameSubstate.active; } break; case GameSubstate.active: if (gameTime.TotalGameTime - _stateStartTime > TimeSpan.FromSeconds(2) && MousePressedOverViewport(mouseState) && _lastMouseState.LeftButton != ButtonState.Pressed) { _fadeBox.FadeOut(); _currectGameSubstate = GameSubstate.unloading; } break; case GameSubstate.unloading: if (_fadeBox.State == FadeBox.FadeState.Idle) { if (_levelNumber <= _maxLevel) { _currectGameState = GameState.activeLevel; } else { _currectGameState = GameState.mainMenu; } _currectGameSubstate = GameSubstate.uninitilized; if (_spidersKilled >= _spiderKillsRequired && _fireAntsKilled >= _fireAntKillsRequired) { _levelNumber++; _spiderKillsRequired = (int)(_spiderKillsRequired * 1.1f + 1); _fireAntKillsRequired = (int)(_fireAntKillsRequired * 1.1f + 1); } } break; default: break; } break; default: break; } _lastMouseState = mouseState; base.Update(gameTime); _fadeBox.Update(gameTime); }