Exemplo n.º 1
0
        /// <summary>
        /// Creates a shiny new jet
        /// </summary>
        /// <param name="id">the factory id on the underside of this jet</param>
        /// <param name="content">The content manager to use</param>
        /// <param name="newPosition">The position to spawn the jet</param>
        public TwinJet(uint id, ContentManager content, Vector2 newPosition)
            : base(id)
        {
            //Setting the health
            this.Health = FullHealth;

            //Setting alive to 'true'
            _isAlive = true;

            //Initializing the states
            _myVisualState   = TwinJetVisualState.HEALTHY;
            _myBehaviorState = TwinJetBehaviouralState.INTRO;
            _myFireState     = TwinJetFireState.STAGE1;
            _myGunState      = GunState.REST;
            _oldGunState     = GunState.LEFT;

            //Initializing rotation
            _myRotation = 0;

            //Setting the flight pattern to null
            _myPattern = null;

            //Setting position and velocity
            _position = newPosition;
            _velocity = Vector2.Zero;

            //Marking the intro as still occurring
            _isIntroOver = false;

            //Setup firerates
            _timerGunFireRate     = 0;
            _timerMissileFireRate = 0;

            //Bring in the spritesheet
            _spriteSheet = content.Load <Texture2D>("Spritesheets/newshi.shp.000000");

            //Setting up Sprite Bounds for the jet and gun
            _spriteBounds[(int)TwinJetVisualState.HEALTHY]      = new Rectangle(98, 143, 93, 80);
            _spriteBounds[(int)TwinJetVisualState.DAMAGED]      = new Rectangle(2, 143, 93, 53);
            _spriteBounds[(int)TwinJetVisualState.GUNDESTROYED] = new Rectangle(2, 143, 93, 53);
            _spriteBounds[(int)TwinJetVisualState.EXPLODING]    = Rectangle.Empty;
            _spriteBounds[(int)TwinJetVisualState.DEAD]         = Rectangle.Empty;

            _spriteGunBounds[(int)GunState.LEFT]      = new Rectangle(62, 196, 21, 21);
            _spriteGunBounds[(int)GunState.REST]      = new Rectangle(38, 196, 21, 20);
            _spriteGunBounds[(int)GunState.RIGHT]     = new Rectangle(14, 196, 21, 21);
            _spriteGunBounds[(int)GunState.DESTROYED] = new Rectangle(38, 196, 21, 11);

            //Calls the on entry method to initialize some things
            onEntry();
        }
Exemplo n.º 2
0
        /// <summary>
        /// checks if this jet still has its guns
        /// </summary>
        private void checkIfGunDestroyed()
        {
            switch (_myVisualState)
            {
            case TwinJetVisualState.DAMAGED:
                if (this.Health <= GunLossThreshold)
                {
                    _myVisualState = TwinJetVisualState.GUNDESTROYED;

                    onEntry();
                }
                break;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks if this jet is damaged yet
        /// </summary>
        private void checkIfDamaged()
        {
            switch (_myVisualState)
            {
            case TwinJetVisualState.HEALTHY:
                if (this.Health <= DamageThreshold)
                {
                    _myVisualState = TwinJetVisualState.DAMAGED;

                    onEntry();
                }
                break;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Check if this jet is even alive
        /// </summary>
        private void checkIfIsAlive()
        {
            switch (_myVisualState)
            {
            case TwinJetVisualState.GUNDESTROYED:
                if (this.Health <= 0)
                {
                    _isAlive       = false;
                    _myVisualState = TwinJetVisualState.EXPLODING;

                    onEntry();
                }
                break;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Called every update and performs according to the current state
        /// </summary>
        /// <param name="elapsedTime">Time elapsed since last update</param>
        private void onFrame(float elapsedTime)
        {
            switch (_myVisualState)
            {
                case TwinJetVisualState.HEALTHY:
                    checkIfDamaged();
                    break;
                case TwinJetVisualState.DAMAGED:
                    checkIfGunDestroyed();
                    break;
                case TwinJetVisualState.GUNDESTROYED:
                    checkIfIsAlive();
                    break;
                case TwinJetVisualState.EXPLODING:
                    Explode();
                    _myVisualState = TwinJetVisualState.DEAD;
                    break;
                case TwinJetVisualState.DEAD:
                    break;
            }

            switch (_myBehaviorState)
            {
                case TwinJetBehaviouralState.INTRO:
                    checkIfIntroIsOver();
                    break;
                case TwinJetBehaviouralState.FIGHT:

                    Fly();

                    if (_myFireState != TwinJetFireState.STAGE3)
                    {
                        if (checkIfGunIsReady())
                        {
                            FireGun();
                        }
                        else
                        {
                            _myGunState = GunState.REST;
                        }
                    }

                    if (_myFireState != TwinJetFireState.STAGE1)
                    {
                        if (checkIfMissilesReady())
                        {
                            FireMissiles();
                        }
                    }

                    _timerGunFireRate -= elapsedTime;
                    _timerMissileFireRate -= elapsedTime;

                    break;

                case TwinJetBehaviouralState.PAUSED:

                    break;
            }

            if (!float.IsNaN(_velocity.X) && !float.IsNaN(_velocity.Y))
                _position += _velocity * elapsedTime;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Check if this jet is even alive
        /// </summary>
        private void checkIfIsAlive()
        {
            switch (_myVisualState)
            {

                case TwinJetVisualState.GUNDESTROYED:
                    if (this.Health <= 0)
                    {
                        _isAlive = false;
                        _myVisualState = TwinJetVisualState.EXPLODING;

                        onEntry();
                    }
                    break;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// checks if this jet still has its guns
        /// </summary>
        private void checkIfGunDestroyed()
        {
            switch (_myVisualState)
            {

                case TwinJetVisualState.DAMAGED:
                    if (this.Health <= GunLossThreshold)
                    {
                        _myVisualState = TwinJetVisualState.GUNDESTROYED;

                        onEntry();
                    }
                    break;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Checks if this jet is damaged yet
        /// </summary>
        private void checkIfDamaged()
        {
            switch (_myVisualState)
            {

                case TwinJetVisualState.HEALTHY:
                    if (this.Health <= DamageThreshold)
                    {
                        _myVisualState = TwinJetVisualState.DAMAGED;

                        onEntry();
                    }
                    break;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a shiny new jet
        /// </summary>
        /// <param name="id">the factory id on the underside of this jet</param>
        /// <param name="content">The content manager to use</param>
        /// <param name="newPosition">The position to spawn the jet</param>
        public TwinJet(uint id, ContentManager content, Vector2 newPosition)
            : base(id)
        {
            //Setting the health
            this.Health = FullHealth;
            this.Score = 75;

            //Setting alive to 'true'
            _isAlive = true;

            //Initializing the states
            _myVisualState = TwinJetVisualState.HEALTHY;
            _myBehaviorState = TwinJetBehaviouralState.INTRO;
            _myFireState = TwinJetFireState.STAGE1;
            _myGunState = GunState.REST;
            _oldGunState = GunState.LEFT;

            //Initializing rotation
            _myRotation = 0;

            //Setting the flight pattern to null
            _myPattern = null;

            //Setting position and velocity
            _position = newPosition;
            _velocity = Vector2.Zero;

            //Marking the intro as still occurring
            _isIntroOver = false;

            //Setup firerates
            _timerGunFireRate = 0;
            _timerMissileFireRate = 0;

            //Bring in the spritesheet
            _spriteSheet = content.Load<Texture2D>("Spritesheets/newshi.shp.000000");

            //Setting up Sprite Bounds for the jet and gun
            _spriteBounds[(int)TwinJetVisualState.HEALTHY] = new Rectangle(98, 143, 93, 80);
            _spriteBounds[(int)TwinJetVisualState.DAMAGED] = new Rectangle(2, 143, 93, 53);
            _spriteBounds[(int)TwinJetVisualState.GUNDESTROYED] = new Rectangle(2, 143, 93, 53);
            _spriteBounds[(int)TwinJetVisualState.EXPLODING] = Rectangle.Empty;
            _spriteBounds[(int)TwinJetVisualState.DEAD] = Rectangle.Empty;

            _spriteGunBounds[(int)GunState.LEFT] = new Rectangle(62, 196, 21, 21);
            _spriteGunBounds[(int)GunState.REST] = new Rectangle(38, 196, 21, 20);
            _spriteGunBounds[(int)GunState.RIGHT] = new Rectangle(14, 196, 21, 21);
            _spriteGunBounds[(int)GunState.DESTROYED] = new Rectangle(38, 196, 21, 11);

            //Calls the on entry method to initialize some things
            onEntry();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Called every update and performs according to the current state
        /// </summary>
        /// <param name="elapsedTime">Time elapsed since last update</param>
        private void onFrame(float elapsedTime)
        {
            switch (_myVisualState)
            {
            case TwinJetVisualState.HEALTHY:
                checkIfDamaged();
                break;

            case TwinJetVisualState.DAMAGED:
                checkIfGunDestroyed();
                break;

            case TwinJetVisualState.GUNDESTROYED:
                checkIfIsAlive();
                break;

            case TwinJetVisualState.EXPLODING:
                Explode();
                _myVisualState = TwinJetVisualState.DEAD;
                break;

            case TwinJetVisualState.DEAD:
                break;
            }

            switch (_myBehaviorState)
            {
            case TwinJetBehaviouralState.INTRO:
                checkIfIntroIsOver();
                break;

            case TwinJetBehaviouralState.FIGHT:

                Fly();

                if (_myFireState != TwinJetFireState.STAGE3)
                {
                    if (checkIfGunIsReady())
                    {
                        FireGun();
                    }
                    else
                    {
                        _myGunState = GunState.REST;
                    }
                }

                if (_myFireState != TwinJetFireState.STAGE1)
                {
                    if (checkIfMissilesReady())
                    {
                        FireMissiles();
                    }
                }

                _timerGunFireRate     -= elapsedTime;
                _timerMissileFireRate -= elapsedTime;

                break;

            case TwinJetBehaviouralState.PAUSED:

                break;
            }

            if (!float.IsNaN(_velocity.X) && !float.IsNaN(_velocity.Y))
            {
                _position += _velocity * elapsedTime;
            }
        }