/// <summary> /// Creates a new instance of a Green Goblin enemy ship /// </summary> /// <param name="content">A ContentManager to load resources with</param> /// <param name="position">The position of the Green Goblin ship in the game world</param> public GreenGoblin(uint id, ContentManager content, Vector2 position) : base(id) { // Randomly generates the diagonal flight length diagFlightLength = rand.Next(20, 150); this.position = position; diagCount = 0; spritesheet = content.Load<Texture2D>("Spritesheets/newshf.shp.000000"); spriteBounds[(int)GreenGoblinSteeringState.Left].X = 0; spriteBounds[(int)GreenGoblinSteeringState.Left].Y = 0; spriteBounds[(int)GreenGoblinSteeringState.Left].Width = 25; spriteBounds[(int)GreenGoblinSteeringState.Left].Height = 26; spriteBounds[(int)GreenGoblinSteeringState.Straight].X = 25; spriteBounds[(int)GreenGoblinSteeringState.Straight].Y = 0; spriteBounds[(int)GreenGoblinSteeringState.Straight].Width = 25; spriteBounds[(int)GreenGoblinSteeringState.Straight].Height = 26; spriteBounds[(int)GreenGoblinSteeringState.Right].X = 50; spriteBounds[(int)GreenGoblinSteeringState.Right].Y = 0; spriteBounds[(int)GreenGoblinSteeringState.Right].Width = 25; spriteBounds[(int)GreenGoblinSteeringState.Right].Height = 26; steeringState = GreenGoblinSteeringState.Straight; }
/// <summary> /// Creates a new instance of a Green Goblin enemy ship /// </summary> /// <param name="content">A ContentManager to load resources with</param> /// <param name="position">The position of the Green Goblin ship in the game world</param> public GreenGoblin(uint id, ContentManager content, Vector2 position) : base(id) { // Randomly generates the diagonal flight length diagFlightLength = rand.Next(20, 150); this.position = position; diagCount = 0; spritesheet = content.Load <Texture2D>("Spritesheets/newshf.shp.000000"); spriteBounds[(int)GreenGoblinSteeringState.Left].X = 0; spriteBounds[(int)GreenGoblinSteeringState.Left].Y = 0; spriteBounds[(int)GreenGoblinSteeringState.Left].Width = 25; spriteBounds[(int)GreenGoblinSteeringState.Left].Height = 26; spriteBounds[(int)GreenGoblinSteeringState.Straight].X = 25; spriteBounds[(int)GreenGoblinSteeringState.Straight].Y = 0; spriteBounds[(int)GreenGoblinSteeringState.Straight].Width = 25; spriteBounds[(int)GreenGoblinSteeringState.Straight].Height = 26; spriteBounds[(int)GreenGoblinSteeringState.Right].X = 50; spriteBounds[(int)GreenGoblinSteeringState.Right].Y = 0; spriteBounds[(int)GreenGoblinSteeringState.Right].Width = 25; spriteBounds[(int)GreenGoblinSteeringState.Right].Height = 26; steeringState = GreenGoblinSteeringState.Straight; }
/// <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; } }