Ejemplo n.º 1
0
        /// <summary>
        /// Checks if this Jet is within firing range of the Player,
        /// if so then begin firing
        /// </summary>
        private void checkIfInFiringRange(Vector2 PlayerPosition, int PlayerWidth)
        {
            switch (_myBehaviourState)
            {
            //Only need to check when in Fire or Strafe states
            case JetMinionBehaviourState.STRAFE:

                if (Math.Abs((PlayerPosition.X + PlayerWidth * 0.5) - (Position.X + Bounds.Width * 0.5)) <= FireRange)
                {
                    _myBehaviourState = JetMinionBehaviourState.FIRE;
                    onEntry();
                }

                break;

            case JetMinionBehaviourState.FIRE:

                if (Math.Abs(PlayerPosition.X - Position.X) > FireRange)
                {
                    _myBehaviourState = JetMinionBehaviourState.STRAFE;
                }

                break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks if this Jets life time is up,
        /// if so then start retreating
        /// </summary>
        private void checkIfLifeTimeOver()
        {
            switch (_myVisualState)
            {
            //Need to check this for both Healthy and Damaged states
            case JetMinionVisualState.HEALTHY:
            case JetMinionVisualState.DAMAGED:

                if (_timerLife <= 0)
                {
                    _myBehaviourState = JetMinionBehaviourState.RETREAT;
                }

                break;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Checks if the Jet can sense the Player yet
        /// </summary>
        private void checkIfInAlertRange(Vector2 PlayerPosition)
        {
            switch (_myBehaviourState)
            {
            //Only need to do this in the ALERT state
            case JetMinionBehaviourState.ALERT:

                //Gets the vector from the Player to this jet and gets its length (squared for efficiency)
                //and compares it with the alert range (squared)
                if ((Position - PlayerPosition).LengthSquared() <= (AlertRange * AlertRange))
                {
                    _myBehaviourState = JetMinionBehaviourState.SEEKSTRAFE;
                }

                break;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Checks if this Jet is in strafing range of the Player,
        /// if so then begin strafing
        /// </summary>
        private void checkIfInStrafingRange(Vector2 PlayerPosition)
        {
            switch (_myBehaviourState)
            {
            case JetMinionBehaviourState.SEEKSTRAFE:

                //StrafeDistance is just a distance between the tip of the Jet
                //and the Player position, so no fancy math here

                float distanceAway = PlayerPosition.Y - (Position.Y + Bounds.Height);

                if (distanceAway > StrafeDistance - 5 && distanceAway < StrafeDistance + 5)
                {
                    _myBehaviourState = JetMinionBehaviourState.STRAFE;
                }

                break;
            }
        }
Ejemplo n.º 5
0
        //All methods below this are private

        #region Sensor Checks (and subsequent transitions)

        /// <summary>
        /// Checks if this Jet is On screen, if so then Alert it
        /// </summary>
        private void checkIfOnScreen()
        {
            switch (_myBehaviourState)
            {
            //Only need to do this if in the IDLE state
            case JetMinionBehaviourState.IDLE:

                //I realize I *might* be able to do this with the Intersects() method with
                //the sprite bounds and Game screen, but I'm not sure if that will work
                //and I know that if I do do that, I will just have to change it later -_-

                //Check if sprite is past left and top sides
                if ((Position.X + Bounds.Width) > 0 && (Position.Y + Bounds.Height) > 0)
                {
                    //Check if the sprite has not passed the right or bottom sides
                    if (Position.X < GameScreen.Width && Position.Y < GameScreen.Height)
                    {
                        _myBehaviourState = JetMinionBehaviourState.ALERT;
                    }
                }
                break;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes the values of this Jet
        /// </summary>
        /// <param name="content"></param>
        /// <param name="position"></param>
        private void Initiailize(ContentManager content, Vector2 position)
        {
            //Setting Health
            _health = FullHealth;

            //Initializing States
            _myVisualState = JetMinionVisualState.HEALTHY;
            _myBehaviourState = JetMinionBehaviourState.IDLE;
            _myGunState = GunState.REST;
            _oldGunState = GunState.RIGHT;

            //Setting the initial position of the ship
            _position = position;

            //Setting up the initial direction
            _isMovingLeft = true;

            //Setting up the timers
            _timerLife = TotalLifeTime;
            _timerFire = HealthyFireRate;
            _timerExplosion = TotalExplosionTime;

            //Setting up the Explosion Animator
            _explosionAnimator = new ExplodeAnim(ExplosionType.SINGLE, 0.2f, new Rectangle((int)position.X, (int)position.Y, _spriteBounds[1].Width, _spriteBounds[1].Height));

            _spriteSheet = content.Load<Texture2D>("Spritesheets/newshi.shp.000000");
            _explosionSpriteSheet = content.Load<Texture2D>("Spritesheets/newsh6.shp.000000");

            #region Initializing _spriteBounds

            _spriteBounds[(int)JetMinionVisualState.HEALTHY].X = 98;
            _spriteBounds[(int)JetMinionVisualState.HEALTHY].Y = 143;
            _spriteBounds[(int)JetMinionVisualState.HEALTHY].Width = 93;
            _spriteBounds[(int)JetMinionVisualState.HEALTHY].Height = 80;

            _spriteBounds[(int)JetMinionVisualState.DAMAGED].X = 2;
            _spriteBounds[(int)JetMinionVisualState.DAMAGED].Y = 143;
            _spriteBounds[(int)JetMinionVisualState.DAMAGED].Width = 93;
            _spriteBounds[(int)JetMinionVisualState.DAMAGED].Height = 53;

            //This makes returning bounds easier, no check required
            _spriteBounds[(int)JetMinionVisualState.EXPLODING] = Rectangle.Empty;
            _spriteBounds[(int)JetMinionVisualState.DEAD] = Rectangle.Empty;

            #endregion

            #region Initializing _spriteGun

            _spriteGun[(int)GunState.LEFT].X = 62;
            _spriteGun[(int)GunState.LEFT].Y = 196;
            _spriteGun[(int)GunState.LEFT].Width = 21;
            _spriteGun[(int)GunState.LEFT].Height = 21;

            _spriteGun[(int)GunState.REST].X = 38;
            _spriteGun[(int)GunState.REST].Y = 196;
            _spriteGun[(int)GunState.REST].Width = 21;
            _spriteGun[(int)GunState.REST].Height = 20;

            _spriteGun[(int)GunState.RIGHT].X = 14;
            _spriteGun[(int)GunState.RIGHT].Y = 196;
            _spriteGun[(int)GunState.RIGHT].Width = 21;
            _spriteGun[(int)GunState.RIGHT].Height = 21;

            #endregion
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Checks if this Jet is On screen, if so then Alert it
        /// </summary>
        private void checkIfOnScreen()
        {
            switch (_myBehaviourState)
            {
                //Only need to do this if in the IDLE state
                case JetMinionBehaviourState.IDLE:

                    //I realize I *might* be able to do this with the Intersects() method with
                    //the sprite bounds and Game screen, but I'm not sure if that will work
                    //and I know that if I do do that, I will just have to change it later -_-

                    //Check if sprite is past left and top sides
                    if ((Position.X + Bounds.Width) > 0 && (Position.Y + Bounds.Height) > 0)
                    {
                        //Check if the sprite has not passed the right or bottom sides
                        if (Position.X < GameScreen.Width && Position.Y < GameScreen.Height)
                        {
                            _myBehaviourState = JetMinionBehaviourState.ALERT;
                        }
                    }
                    break;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Checks if this Jets life time is up,
        /// if so then start retreating
        /// </summary>
        private void checkIfLifeTimeOver()
        {
            switch (_myVisualState)
            {
                //Need to check this for both Healthy and Damaged states
                case JetMinionVisualState.HEALTHY:
                case JetMinionVisualState.DAMAGED:

                    if (_timerLife <= 0)
                    {
                        _myBehaviourState = JetMinionBehaviourState.RETREAT;
                    }

                    break;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Checks if this Jet is in strafing range of the player, 
        /// if so then begin strafing
        /// </summary>
        private void checkIfInStrafingRange(Vector2 playerPosition)
        {
            switch (_myBehaviourState)
            {
                case JetMinionBehaviourState.SEEKSTRAFE:

                    //StrafeDistance is just a distance between the tip of the Jet
                    //and the player position, so no fancy math here

                    float distanceAway = playerPosition.Y - (Position.Y + Bounds.Height);

                    if (distanceAway > StrafeDistance - 5 && distanceAway < StrafeDistance + 5)
                    {
                        _myBehaviourState = JetMinionBehaviourState.STRAFE;
                    }

                    break;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Checks if this Jet is within firing range of the player,
        /// if so then begin firing
        /// </summary>
        private void checkIfInFiringRange(Vector2 playerPosition, int playerWidth)
        {
            switch (_myBehaviourState)
            {
                //Only need to check when in Fire or Strafe states
                case JetMinionBehaviourState.STRAFE:

                    if (Math.Abs((playerPosition.X + playerWidth * 0.5) - (Position.X + Bounds.Width * 0.5)) <= FireRange)
                    {
                        _myBehaviourState = JetMinionBehaviourState.FIRE;
                        onEntry();
                    }

                    break;

                case JetMinionBehaviourState.FIRE:

                    if (Math.Abs(playerPosition.X - Position.X) > FireRange)
                    {
                        _myBehaviourState = JetMinionBehaviourState.STRAFE;
                    }

                    break;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Checks if the Jet can sense the player yet
        /// </summary>
        private void checkIfInAlertRange(Vector2 playerPosition)
        {
            switch (_myBehaviourState)
            {
                //Only need to do this in the ALERT state
                case JetMinionBehaviourState.ALERT:

                    //Gets the vector from the player to this jet and gets its length (squared for efficiency)
                    //and compares it with the alert range (squared)
                    if ((Position - playerPosition).LengthSquared() <= (AlertRange * AlertRange))
                    {
                        _myBehaviourState = JetMinionBehaviourState.SEEKSTRAFE;
                    }

                    break;
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Initializes the values of this Jet
        /// </summary>
        /// <param name="content"></param>
        /// <param name="position"></param>
        private void Initiailize(ContentManager content, Vector2 position)
        {
            //Setting Health
            _health = FullHealth;

            //Initializing States
            _myVisualState    = JetMinionVisualState.HEALTHY;
            _myBehaviourState = JetMinionBehaviourState.IDLE;
            _myGunState       = GunState.REST;
            _oldGunState      = GunState.RIGHT;

            //Setting the initial position of the ship
            _position = position;

            //Setting up the initial direction
            _isMovingLeft = true;

            //Setting up the timers
            _timerLife      = TotalLifeTime;
            _timerFire      = HealthyFireRate;
            _timerExplosion = TotalExplosionTime;

            //Setting up the Explosion Animator
            _explosionAnimator = new ExplodeAnim(ExplosionType.SINGLE, 0.2f, new Rectangle((int)position.X, (int)position.Y, _spriteBounds[1].Width, _spriteBounds[1].Height));

            _spriteSheet          = content.Load <Texture2D>("Spritesheets/newshi.shp.000000");
            _explosionSpriteSheet = content.Load <Texture2D>("Spritesheets/newsh6.shp.000000");

            #region Initializing _spriteBounds

            _spriteBounds[(int)JetMinionVisualState.HEALTHY].X      = 98;
            _spriteBounds[(int)JetMinionVisualState.HEALTHY].Y      = 143;
            _spriteBounds[(int)JetMinionVisualState.HEALTHY].Width  = 93;
            _spriteBounds[(int)JetMinionVisualState.HEALTHY].Height = 80;

            _spriteBounds[(int)JetMinionVisualState.DAMAGED].X      = 2;
            _spriteBounds[(int)JetMinionVisualState.DAMAGED].Y      = 143;
            _spriteBounds[(int)JetMinionVisualState.DAMAGED].Width  = 93;
            _spriteBounds[(int)JetMinionVisualState.DAMAGED].Height = 53;

            //This makes returning bounds easier, no check required
            _spriteBounds[(int)JetMinionVisualState.EXPLODING] = Rectangle.Empty;
            _spriteBounds[(int)JetMinionVisualState.DEAD]      = Rectangle.Empty;

            #endregion

            #region Initializing _spriteGun

            _spriteGun[(int)GunState.LEFT].X      = 62;
            _spriteGun[(int)GunState.LEFT].Y      = 196;
            _spriteGun[(int)GunState.LEFT].Width  = 21;
            _spriteGun[(int)GunState.LEFT].Height = 21;

            _spriteGun[(int)GunState.REST].X      = 38;
            _spriteGun[(int)GunState.REST].Y      = 196;
            _spriteGun[(int)GunState.REST].Width  = 21;
            _spriteGun[(int)GunState.REST].Height = 20;

            _spriteGun[(int)GunState.RIGHT].X      = 14;
            _spriteGun[(int)GunState.RIGHT].Y      = 196;
            _spriteGun[(int)GunState.RIGHT].Width  = 21;
            _spriteGun[(int)GunState.RIGHT].Height = 21;

            #endregion
        }