Example #1
0
        /// <summary>
        /// Creates a new instance of the BladeSpinner Class
        /// </summary>
        /// <param name="id">the ID for the base enemy class</param>
        /// <param name="content">A ContentManager to load resources with</param>
        /// <param name="position">The position of the Dart ship in the game world</param>
        public BladeSpinner(uint id, ContentManager content, Vector2 position)
            : base(id)
        {
            spritesheet = content.Load <Texture2D>("Spritesheets/newsh#.shp.000000");

            //Moves frame initialization to a separate function to make the constructor cleaner
            initializeFrames();

            this.position = position;

            //initial directiion and state settings
            horDir       = flightDirection.positive;
            vertDir      = flightDirection.positive;
            patrolVector = new Vector2(50, 1);

            state = spinnerState.flying;
            frame = animationFrame.flying1;

            frameTimer = 0;
        }
        /// <summary>
        /// Creates a new instance of the BladeSpinner Class
        /// </summary>
        /// <param name="id">the ID for the base enemy class</param>
        /// <param name="content">A ContentManager to load resources with</param>
        /// <param name="position">The position of the Dart ship in the game world</param>
        public BladeSpinner(uint id, ContentManager content, Vector2 position)
            : base(id)
        {
            spritesheet = content.Load<Texture2D>("Spritesheets/newsh#.shp.000000");

            //Moves frame initialization to a separate function to make the constructor cleaner
            initializeFrames();

            this.position = position;

            //initial directiion and state settings
            horDir = flightDirection.positive;
            vertDir = flightDirection.positive;
            patrolVector = new Vector2(50, 1);

            state = spinnerState.flying;
            frame = animationFrame.flying1;

            frameTimer = 0;
        }
Example #3
0
        /// <summary>
        /// Updates the blade spinner
        /// </summary>
        /// <param name="elapsedTime">The in-game time between the previous and current frame</param>
        public override void Update(float elapsedTime)
        {
            //If the spinner is dead do nothing
            if (state == spinnerState.dead)
            {
                return;
            }

            //"Sense" the player ship
            PlayerShip player = ScrollingShooterGame.Game.Player;

            //-40 is so the Spinner actually covers the ship instead of menacing its back right corner
            Vector2 playerPosition = new Vector2(player.Bounds.Center.X - 40, player.Bounds.Center.Y - 40);
            // Get a vector from our position to the player's position
            Vector2 toPlayer = playerPosition - this.position;

            //Conditionals to keep the spinner on screen by adjusting the patrol vector
            //A switch statement may be more efficient
            if (horDir == flightDirection.positive && this.position.X > 725)
            {
                horDir = flightDirection.negative;
            }
            else if (horDir == flightDirection.negative && this.position.X < 25)
            {
                horDir = flightDirection.positive;
            }
            if (vertDir == flightDirection.negative && this.position.Y < 25)
            {
                vertDir = flightDirection.positive;
            }
            else if (vertDir == flightDirection.positive && this.position.Y > 400)
            {
                vertDir = flightDirection.negative;
            }
            patrolVector.X = ((int)horDir * 50);
            patrolVector.Y = ((int)vertDir) * 5;
            //End of conditionals to stay on screen


            //Determine if the player is "seen"
            if (toPlayer.LengthSquared() < 30000 && state != spinnerState.dying)
            {
                //if seen attack player
                state = spinnerState.attacking;
            }
            else if (state != spinnerState.dying)
            {
                state = spinnerState.flying;
            }

            switch (state)
            {
            case spinnerState.flying:
                //normalize the patrol vector
                patrolVector.Normalize();

                //move
                this.position += patrolVector * elapsedTime * 250;
                break;

            case spinnerState.attacking:
                // Get a normalized steering vector
                toPlayer.Normalize();

                // Steer towards them
                this.position += toPlayer * elapsedTime * 125;
                break;

            case spinnerState.dying:
                //No movement while dying
                break;
            }

            //Collision detection?

            /*
             * if(state==spinnerState.attacking)
             * {
             *     if(hitPlayer)
             *          damage player
             *
             *    if(hitProjectile)
             *    {
             *          take a little damage
             *          if(hp==0)
             *              state==spinnerState.dying;
             *     }
             * }
             * else if(state==spinnerState.flying)
             *{
             *      if(hitPorjectile)
             *      {
             *          take more damage
             *          if(hp==0)
             *              state==spinnerState.dying;
             *      }
             *      if(hitPlayer)
             *      {
             *          //Should never happen
             *          damage player a little
             *          state = spinnerState.dying;
             *      }
             *}
             * else if(state==spinnerState.dying)
             *{
             *      if(hit Object)
             *      {
             *          do "med" damage
             *      }
             *}
             */
        }
        /// <summary>
        /// Updates the blade spinner
        /// </summary>
        /// <param name="elapsedTime">The in-game time between the previous and current frame</param>
        public override void Update(float elapsedTime)
        {
            //If the spinner is dead do nothing
            if (state == spinnerState.dead)
                return;

            //"Sense" the Player ship
            PlayerShip Player = ScrollingShooterGame.Game.Player;

            //-40 is so the Spinner actually covers the ship instead of menacing its back right corner
            Vector2 PlayerPosition = new Vector2(Player.Bounds.Center.X-40, Player.Bounds.Center.Y-40);
            // Get a vector from our position to the Player's position
            Vector2 toPlayer = PlayerPosition - this.position;

            //Conditionals to keep the spinner on screen by adjusting the patrol vector
            //A switch statement may be more efficient
            if (horDir == flightDirection.positive && this.position.X > 725)
            {
                horDir = flightDirection.negative;
            }
            else if (horDir == flightDirection.negative && this.position.X < 25)
            {
                horDir = flightDirection.positive;
            }
            if (vertDir == flightDirection.negative && this.position.Y < 25)
            {
                vertDir = flightDirection.positive;
            }
            else if (vertDir == flightDirection.positive && this.position.Y > 400)
            {
                vertDir = flightDirection.negative;
            }
            patrolVector.X = ((int)horDir * 50);
            patrolVector.Y = ((int)vertDir) * 5;
            //End of conditionals to stay on screen

            //Determine if the Player is "seen"
            if (toPlayer.LengthSquared() < 30000 && state != spinnerState.dying)
            {
                //if seen attack Player
                state = spinnerState.attacking;
            }
            else if (state != spinnerState.dying)
            {
                state = spinnerState.flying;
            }

            switch (state)
            {
                case spinnerState.flying:
                    //normalize the patrol vector
                    patrolVector.Normalize();

                    //move
                    this.position += patrolVector * elapsedTime * 250;
                    break;
                case spinnerState.attacking:
                    // Get a normalized steering vector
                    toPlayer.Normalize();

                    // Steer towards them
                    this.position += toPlayer * elapsedTime * 125;
                    break;
                case spinnerState.dying:
                    //No movement while dying
                    break;
            }

            //Collision detection?
            /*
             * if(state==spinnerState.attacking)
             * {
             *     if(hitPlayer)
             *          damage Player
             *
             *    if(hitProjectile)
             *    {
             *          take a little damage
             *          if(hp==0)
             *              state==spinnerState.dying;
             *     }
             * }
             * else if(state==spinnerState.flying)
             *{
             *      if(hitPorjectile)
             *      {
             *          take more damage
             *          if(hp==0)
             *              state==spinnerState.dying;
             *      }
             *      if(hitPlayer)
             *      {
             *          //Should never happen
             *          damage Player a little
             *          state = spinnerState.dying;
             *      }
             *}
             *else if(state==spinnerState.dying)
             *{
             *      if(hit Object)
             *      {
             *          do "med" damage
             *      }
             *}
             */
        }