Exemple #1
0
        /// <summary>
        /// Updates the brain boss
        /// </summary>
        /// <param name="elapsedTime">Time passed since last frame</param>
        public override void Update(float elapsedTime)
        {
            //TODO: remove test timer when damage is implemented

            testTimer -= elapsedTime;

            if (testTimer <= 0)
            {
                takeDamage(1000);
                if (this.protection != null)
                {
                    protection.takeDamage(1000);
                }
                if (this.psiEmitter != null)
                {
                    psiEmitter.takeDamage(1000);
                }
                testTimer = 8f;
            }

            switch (state)
            {
            case BrainBossState.Protected:
                if (protection.Health <= 0)
                {
                    ScrollingShooterGame.GameObjectManager.DestroyObject(protection.ID);
                    state      = BrainBossState.MovingToCenter;
                    protection = null;
                }
                break;

            case BrainBossState.MovingToCenter:
                if (position.X < targetPositionX)
                {
                    position.X += Math.Min(MOVE_SPEED * elapsedTime, Math.Abs(targetPositionX - position.X));
                }
                else if (position.X > targetPositionY)
                {
                    position.X -= Math.Min(MOVE_SPEED * elapsedTime, Math.Abs(targetPositionX - position.X));
                }

                if (position.Y < targetPositionY)
                {
                    position.Y += Math.Min(MOVE_SPEED * elapsedTime, Math.Abs(targetPositionY - position.Y));
                }
                else if (position.Y > targetPositionY)
                {
                    position.Y -= Math.Min(MOVE_SPEED * elapsedTime, Math.Abs(targetPositionY - position.Y));
                }

                if (Math.Abs(targetPositionX - position.X) < 2 && Math.Abs(targetPositionY - position.Y) < 2)
                {
                    state = BrainBossState.PsyAttack;
                    psiEmitter.startAttacking();
                }

                break;

            case BrainBossState.PsyAttack:

                if (psiEmitter.Health <= 0)
                {
                    state = BrainBossState.DeathCharge;
                }
                break;

            case BrainBossState.DeathCharge:
                if (Health <= 0)
                {
                    ScrollingShooterGame.GameObjectManager.DestroyObject(this.ID);
                    ScrollingShooterGame.GameObjectManager.CreateExplosion(ID);
                    return;
                }

                Vector2 vector = ScrollingShooterGame.Game.Player.GetPosition() - (position + centerOffset);
                vector.Normalize();
                vector *= MOVE_SPEED * elapsedTime;

                position.X += vector.X;
                position.Y += vector.Y;

                for (int i = 0; i < 1; i++)
                {
                    ((EnemyLightningZap)ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.EnemyLightningZap, this.position + centerOffset)).Initialize((float)(rand.NextDouble() * Math.PI * 2), this.brainSpriteBounds.Width);
                }

                break;
            }

            psiEmitter.updatePosition(this.position + centerOffset);
        }