/// <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(); }
/// <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; } }
/// <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; } }
/// <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; } }
/// <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; }
/// <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(); }
/// <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; } }