Exemple #1
0
        /// <summary>
        /// Updates the Green Goblin ship
        /// </summary>
        /// <param name="elapsedTime">The in-game time between the previous and current frame</param>
        public override void Update(float elapsedTime)
        {
            // Sense the Player's position
            PlayerShip Player         = ScrollingShooterGame.Game.Player;
            Vector2    PlayerPosition = new Vector2(Player.Bounds.Center.X, Player.Bounds.Center.Y);

            gunTimer += elapsedTime;

            // Get the distance between the Player and this along the X axis
            float PlayerDistance = Math.Abs(PlayerPosition.X - this.position.X);

            // Make sure the Player is within range
            if (PlayerDistance < 60 && gunTimer > 0.20 && PlayerPosition.Y > (this.position.Y + 30))
            {
                ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.EnemyFlameball, position);
                gunTimer = 0;
            }

            //Ship flies from top to bottom
            this.position.Y += 1;

            // If the ship hasn't reached the turning point
            if (diagCount < diagFlightLength)
            {
                //If the ship has just been created
                if (0 == steeringState.CompareTo(GreenGoblinSteeringState.Straight))
                {
                    this.position.X += 2;
                    steeringState    = GreenGoblinSteeringState.Right;
                    diagCount++;
                }

                // If the ship is going right
                else if (0 == steeringState.CompareTo(GreenGoblinSteeringState.Right))
                {
                    this.position.X += 2;
                    diagCount++;
                }

                // If the ship is going left
                else if (0 == steeringState.CompareTo(GreenGoblinSteeringState.Left))
                {
                    this.position.X -= 2;
                    diagCount++;
                }
            }

            // Once diagonal motion has reach its length, switch directions
            else if (diagCount == diagFlightLength)
            {
                // If going right, switch to left
                if (0 == steeringState.CompareTo(GreenGoblinSteeringState.Right))
                {
                    this.position.X -= 1;
                    steeringState    = GreenGoblinSteeringState.Left;
                    diagCount        = 0;
                    diagFlightLength = rand.Next(20, 150);
                }

                // If going left, switch to right
                else if (0 == steeringState.CompareTo(GreenGoblinSteeringState.Left))
                {
                    this.position.X += 1;
                    steeringState    = GreenGoblinSteeringState.Right;
                    diagCount        = 0;
                    diagFlightLength = rand.Next(20, 150);
                }
            }

            else
            {
                steeringState = GreenGoblinSteeringState.Straight;
            }
        }