/// <summary> /// Updates the Arrow ship /// </summary> /// <param name="elapsedTime">The in-game time between the previous and current frame</param> public override void Update(float elapsedTime) { gunTimer += elapsedTime; // Sense the Player's position PlayerShip Player = ScrollingShooterGame.Game.Player; Vector2 PlayerPosition = new Vector2(Player.Bounds.Center.X, Player.Bounds.Center.Y); // Get a vector from our position to the Player's position Vector2 toPlayer = PlayerPosition - this.position; if (toPlayer.LengthSquared() < 20000) { // We sense the Player's ship! // Get a normalized steering vector toPlayer.Normalize(); // Steer towards them! this.position += toPlayer * elapsedTime * 120; // Change the steering state to reflect our direction if (toPlayer.X < -0.5f) { steeringState = ArrowSteeringState.Left; //Fire! if (gunTimer > .7f) { ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.ArrowProjectile, position); gunTimer = 0f; } } else if (toPlayer.X > 0.5f) { steeringState = ArrowSteeringState.Right; //Fire! if (gunTimer > .7f) { ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.ArrowProjectile, position); gunTimer = 0f; } } else { steeringState = ArrowSteeringState.Straight; } } }
/// <summary> /// Creates a new instance of a Dart enemy ship /// </summary> /// <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 Arrow(uint id, ContentManager content, Vector2 position) : base(id) { this.position = position; spritesheet = content.Load<Texture2D>("Spritesheets/newsh$.shp.000000"); spriteBounds[(int)ArrowSteeringState.Left].X = 5; spriteBounds[(int)ArrowSteeringState.Left].Y = 197; spriteBounds[(int)ArrowSteeringState.Left].Width = 20; spriteBounds[(int)ArrowSteeringState.Left].Height = 28; spriteBounds[(int)ArrowSteeringState.Straight].X = 52; spriteBounds[(int)ArrowSteeringState.Straight].Y = 197; spriteBounds[(int)ArrowSteeringState.Straight].Width = 20; spriteBounds[(int)ArrowSteeringState.Straight].Height = 28; spriteBounds[(int)ArrowSteeringState.Right].X = 101; spriteBounds[(int)ArrowSteeringState.Right].Y = 197; spriteBounds[(int)ArrowSteeringState.Right].Width = 20; spriteBounds[(int)ArrowSteeringState.Right].Height = 28; steeringState = ArrowSteeringState.Straight; }
/// <summary> /// Creates a new instance of a Dart enemy ship /// </summary> /// <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 Arrow(uint id, ContentManager content, Vector2 position) : base(id) { this.position = position; spritesheet = content.Load <Texture2D>("Spritesheets/newsh$.shp.000000"); spriteBounds[(int)ArrowSteeringState.Left].X = 5; spriteBounds[(int)ArrowSteeringState.Left].Y = 197; spriteBounds[(int)ArrowSteeringState.Left].Width = 20; spriteBounds[(int)ArrowSteeringState.Left].Height = 28; spriteBounds[(int)ArrowSteeringState.Straight].X = 52; spriteBounds[(int)ArrowSteeringState.Straight].Y = 197; spriteBounds[(int)ArrowSteeringState.Straight].Width = 20; spriteBounds[(int)ArrowSteeringState.Straight].Height = 28; spriteBounds[(int)ArrowSteeringState.Right].X = 101; spriteBounds[(int)ArrowSteeringState.Right].Y = 197; spriteBounds[(int)ArrowSteeringState.Right].Width = 20; spriteBounds[(int)ArrowSteeringState.Right].Height = 28; steeringState = ArrowSteeringState.Straight; }
/// <summary> /// Updates the Arrow ship /// </summary> /// <param name="elapsedTime">The in-game time between the previous and current frame</param> public override void Update(float elapsedTime) { gunTimer += elapsedTime; // Sense the player's position PlayerShip player = ScrollingShooterGame.Game.Player; Vector2 playerPosition = new Vector2(player.Bounds.Center.X, player.Bounds.Center.Y); // Get a vector from our position to the player's position Vector2 toPlayer = playerPosition - this.position; if (toPlayer.LengthSquared() < 20000) { // We sense the player's ship! // Get a normalized steering vector toPlayer.Normalize(); // Steer towards them! this.position += toPlayer * elapsedTime * 120; // Change the steering state to reflect our direction if (toPlayer.X < -0.5f) { steeringState = ArrowSteeringState.Left; //Fire! if (gunTimer > .7f) { ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.ArrowProjectile, position); gunTimer = 0f; } } else if (toPlayer.X > 0.5f) { steeringState = ArrowSteeringState.Right; //Fire! if (gunTimer > .7f) { ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.ArrowProjectile, position); gunTimer = 0f; } } else steeringState = ArrowSteeringState.Straight; } }