/// <summary> /// Creates a new instance of a LaserDrone /// </summary> /// <param name="content">A ContentManager to load resources with</param> /// <param name="position">The position of the LaserDrone in the game world</param> public LaserDrone(uint id, ContentManager content, Vector2 position) : base(id) { this.position = position; spritesheet = content.Load <Texture2D>("Spritesheets/newsh8.shp.000000"); spriteBounds[(int)WeaponChargeLevel.Full].X = 1; spriteBounds[(int)WeaponChargeLevel.Full].Y = 202; spriteBounds[(int)WeaponChargeLevel.Full].Width = 23; spriteBounds[(int)WeaponChargeLevel.Full].Height = 19; spriteBounds[(int)WeaponChargeLevel.Medium].X = 24; spriteBounds[(int)WeaponChargeLevel.Medium].Y = 202; spriteBounds[(int)WeaponChargeLevel.Medium].Width = 23; spriteBounds[(int)WeaponChargeLevel.Medium].Height = 19; spriteBounds[(int)WeaponChargeLevel.Low].X = 48; spriteBounds[(int)WeaponChargeLevel.Low].Y = 202; spriteBounds[(int)WeaponChargeLevel.Low].Width = 23; spriteBounds[(int)WeaponChargeLevel.Low].Height = 19; weaponChargeLevel = WeaponChargeLevel.Full; }
/// <summary> /// Creates a new instance of a LaserDrone /// </summary> /// <param name="content">A ContentManager to load resources with</param> /// <param name="position">The position of the LaserDrone in the game world</param> public LaserDrone(uint id, ContentManager content, Vector2 position) : base(id) { this.position = position; spritesheet = content.Load<Texture2D>("Spritesheets/newsh8.shp.000000"); spriteBounds[(int)WeaponChargeLevel.Full].X = 1; spriteBounds[(int)WeaponChargeLevel.Full].Y = 202; spriteBounds[(int)WeaponChargeLevel.Full].Width = 23; spriteBounds[(int)WeaponChargeLevel.Full].Height = 19; spriteBounds[(int)WeaponChargeLevel.Medium].X = 24; spriteBounds[(int)WeaponChargeLevel.Medium].Y = 202; spriteBounds[(int)WeaponChargeLevel.Medium].Width = 23; spriteBounds[(int)WeaponChargeLevel.Medium].Height = 19; spriteBounds[(int)WeaponChargeLevel.Low].X = 48; spriteBounds[(int)WeaponChargeLevel.Low].Y = 202; spriteBounds[(int)WeaponChargeLevel.Low].Width = 23; spriteBounds[(int)WeaponChargeLevel.Low].Height = 19; weaponChargeLevel = WeaponChargeLevel.Full; }
/// <summary> /// Updates the LaserDrone /// </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); switch (aiState) { case AIState.Chasing: getInPosition(PlayerPosition, elapsedTime); if (Math.Abs(PlayerPosition.X - Bounds.Center.X) < 40 && Bounds.Center.Y < PlayerPosition.Y) { //transition to firing state fireTimeRemaining = FIRE_TIME; aiState = AIState.Firing; currentSpeed = MAX_MOVE_SPEED * 0.66f; if (droneLaser == null) { droneLaser = (DroneLaser)ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.DroneLaser, Vector2.Zero); } droneLaser.isOn = true; droneLaser.laserPower = WeaponChargeLevel.Full; droneLaser.updatePosition(position.X + 23, position.Y + 30); } break; case AIState.Firing: fireTimeRemaining -= elapsedTime; //change to medium charge sprite when halfway depleted if (weaponChargeLevel == WeaponChargeLevel.Full && fireTimeRemaining / FIRE_TIME < 0.66) { weaponChargeLevel = droneLaser.laserPower = WeaponChargeLevel.Medium; } else if (weaponChargeLevel == WeaponChargeLevel.Medium && fireTimeRemaining / FIRE_TIME < 0.33) { weaponChargeLevel = droneLaser.laserPower = WeaponChargeLevel.Low; } if (fireTimeRemaining <= 0) { //transition to recharging state aiState = AIState.Recharging; currentSpeed = MAX_MOVE_SPEED * 0.33f; rechargeTimeRemaining = RECHARGE_TIME; weaponChargeLevel = WeaponChargeLevel.Low; droneLaser.isOn = false; } getInPosition(PlayerPosition, elapsedTime); droneLaser.updatePosition(position.X + 23, position.Y + 30); break; case AIState.Recharging: rechargeTimeRemaining -= elapsedTime; if (weaponChargeLevel == WeaponChargeLevel.Low && rechargeTimeRemaining / RECHARGE_TIME < 0.66) { weaponChargeLevel = WeaponChargeLevel.Medium; } if (weaponChargeLevel == WeaponChargeLevel.Medium && rechargeTimeRemaining / RECHARGE_TIME < 0.33) { weaponChargeLevel = WeaponChargeLevel.Full; } if (rechargeTimeRemaining <= 0) { aiState = AIState.Chasing; currentSpeed = MAX_MOVE_SPEED; weaponChargeLevel = WeaponChargeLevel.Full; } moveAwayFrom(PlayerPosition, elapsedTime); break; } }
/// <summary> /// Updates the LaserDrone /// </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); switch (aiState) { case AIState.Chasing: getInPosition(playerPosition, elapsedTime); if (Math.Abs(playerPosition.X - Bounds.Center.X) < 40 && Bounds.Center.Y < playerPosition.Y) { //transition to firing state fireTimeRemaining = FIRE_TIME; aiState = AIState.Firing; currentSpeed = MAX_MOVE_SPEED * 0.66f; if(droneLaser == null) droneLaser = (DroneLaser) ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.DroneLaser, Vector2.Zero); droneLaser.isOn = true; droneLaser.laserPower = WeaponChargeLevel.Full; droneLaser.updatePosition(position.X + 23, position.Y + 30); } break; case AIState.Firing: fireTimeRemaining -= elapsedTime; //change to medium charge sprite when halfway depleted if (weaponChargeLevel == WeaponChargeLevel.Full && fireTimeRemaining / FIRE_TIME < 0.66) weaponChargeLevel = droneLaser.laserPower = WeaponChargeLevel.Medium; else if (weaponChargeLevel == WeaponChargeLevel.Medium && fireTimeRemaining / FIRE_TIME < 0.33) weaponChargeLevel = droneLaser.laserPower = WeaponChargeLevel.Low; if (fireTimeRemaining <= 0) { //transition to recharging state aiState = AIState.Recharging; currentSpeed = MAX_MOVE_SPEED * 0.33f; rechargeTimeRemaining = RECHARGE_TIME; weaponChargeLevel = WeaponChargeLevel.Low; droneLaser.isOn = false; } getInPosition(playerPosition, elapsedTime); droneLaser.updatePosition(position.X + 23, position.Y + 30); break; case AIState.Recharging: rechargeTimeRemaining -= elapsedTime; if (weaponChargeLevel == WeaponChargeLevel.Low && rechargeTimeRemaining / RECHARGE_TIME < 0.66) weaponChargeLevel = WeaponChargeLevel.Medium; if (weaponChargeLevel == WeaponChargeLevel.Medium && rechargeTimeRemaining / RECHARGE_TIME < 0.33) weaponChargeLevel = WeaponChargeLevel.Full; if (rechargeTimeRemaining <= 0) { aiState = AIState.Chasing; currentSpeed = MAX_MOVE_SPEED; weaponChargeLevel = WeaponChargeLevel.Full; } moveAwayFrom(playerPosition, elapsedTime); break; } }