public virtual void Update(GameTime gameTime) { UpdatePosition(gameTime); UpdateRotation(gameTime); UpdateBehaviour(gameTime); // Is outside of the screen? IsOutside = Game.GameManager.IsOutside(Position()); // New position timer if (StartNewPositionTimer && NewPositionTimerFinished != null) { if (NewPositionTimer.TotalMilliseconds > 0) { NewPositionTimer -= gameTime.ElapsedGameTime; } else { NewPositionTimer = TimeSpan.FromSeconds(NewPositionTimerTime); NewPositionTimerFinished.Invoke(this, NewPositionTimerTime); } } // Shoot timer if (StartShootTimer && ShootTimerFinished != null) { if (ShootTimer.TotalMilliseconds > 0) { ShootTimer -= gameTime.ElapsedGameTime; } else { ShootTimer = TimeSpan.FromSeconds(ShootTimerTime); ShootTimerFinished.Invoke(this, ShootTimerTime); } } if (_hitTimer.TotalMilliseconds > 0) { _hitTimer -= gameTime.ElapsedGameTime; } Tinted = _hitTimer.TotalMilliseconds > 0; var portion = (InitialLife / Behaviours.Count); var value = Life - (InitialLife - (CurrentBehaviourIndex + 1) * portion); _hpBar.Scale = new Vector2(value / portion, 1f); _hpBar.Color = Tinted ? Color.White : GameConfig.BossHPBarColors[CurrentBehaviourIndex]; _timer += gameTime.ElapsedGameTime; _timerLabel.Text = _timer.ToString("mm\\:ss"); CurrentAnimator.Update(gameTime.ElapsedGameTime.Milliseconds); }
public virtual void Update(GameTime gameTime) { if (_destroyed) { if (Game.GameManager.TransitioningToEndGame() && Game.SpriteBatchManager.Boss != null) { PlayExplosionAnimation(); Dispose(); } return; } if (_bossEntranceAnimation) { if (Position().EqualsWithTolerence(InitialPosition, 1E-02f)) { Position(InitialPosition); _ready = true; _bossEntranceAnimation = false; Invincible = false; } } if (!_destroyed && PhysicsEnabled) { PhysicsWorld.Step((float)gameTime.ElapsedGameTime.TotalSeconds); SynchronizeGraphicsWithPhysics(); } if (_randomPosition && !TargetingPosition) { var newPosition = Vector2.Zero; if (_randomPositionLongDistance) { var currentPosition = Position().ToPoint(); var minDistance = (RandomMovingArea.Width - RandomMovingArea.X) / 2; // Choose a random long distance new X position var leftSpace = currentPosition.X - RandomMovingArea.X; var rightSpace = RandomMovingArea.Width - currentPosition.X; if (leftSpace > minDistance) { if (rightSpace > minDistance) { if (Game.GameManager.Random.NextDouble() > 0.5) { newPosition.X = Game.GameManager.Random.Next(currentPosition.X + minDistance, RandomMovingArea.Width); } else { newPosition.X = Game.GameManager.Random.Next(RandomMovingArea.X, currentPosition.X - minDistance); } } else { newPosition.X = Game.GameManager.Random.Next(RandomMovingArea.X, currentPosition.X - minDistance); } } else { newPosition.X = Game.GameManager.Random.Next(currentPosition.X + minDistance, RandomMovingArea.Width); } // minDistance only depends on the random area X and width if (RandomMovingArea.Height - RandomMovingArea.Y > minDistance) { // Choose a random long distance new Y position var topSpace = currentPosition.Y - RandomMovingArea.Y; var bottomSpace = RandomMovingArea.Height - currentPosition.Y; if (topSpace > minDistance) { if (bottomSpace > minDistance) { if (Game.GameManager.Random.NextDouble() > 0.5) { newPosition.Y = Game.GameManager.Random.Next(currentPosition.Y + minDistance, RandomMovingArea.Height); } else { newPosition.Y = Game.GameManager.Random.Next(RandomMovingArea.Y, currentPosition.Y - minDistance); } } else { newPosition.Y = Game.GameManager.Random.Next(RandomMovingArea.Y, currentPosition.Y - minDistance); } } else { newPosition.Y = Game.GameManager.Random.Next(currentPosition.Y + minDistance, RandomMovingArea.Height); } } else { newPosition.Y = Game.GameManager.Random.Next(RandomMovingArea.Y, RandomMovingArea.Height); } } else { newPosition.X = Game.GameManager.Random.Next(RandomMovingArea.X, RandomMovingArea.Width); newPosition.Y = Game.GameManager.Random.Next(RandomMovingArea.Y, RandomMovingArea.Height); } MoveTo(newPosition, 1.5f); } UpdatePosition(gameTime); UpdateRotation(gameTime); UpdateBehaviour(gameTime); if (_destroyed) { return; } // Is outside of the screen? IsOutside = Game.GameManager.IsOutside(Position()); // New position timer if (StartNewPositionTimer && NewPositionTimerFinished != null) { if (NewPositionTimer.TotalMilliseconds > 0) { NewPositionTimer -= gameTime.ElapsedGameTime; } else { NewPositionTimer = TimeSpan.FromSeconds(NewPositionTimerTime); NewPositionTimerFinished.Invoke(this, NewPositionTimerTime); } } // Shoot timer if (StartShootTimer && ShootTimerFinished != null) { if (ShootTimer.TotalMilliseconds > 0) { ShootTimer -= gameTime.ElapsedGameTime; } else { ShootTimer = TimeSpan.FromSeconds(ShootTimerTime); ShootTimerFinished.Invoke(this, ShootTimerTime); } } if (_hitTimer.TotalMilliseconds > 0) { _hitTimer -= gameTime.ElapsedGameTime; } Tinted = _hitTimer.TotalMilliseconds > 0; CurrentAnimator.Update(gameTime.ElapsedGameTime.Milliseconds); }