/// <summary> /// reset the weapon to go into cooldown /// </summary> public void Reset() { //resets the weapon's damage and timer as we are not focused on the same enemy anymore TimeThatHasPassed = 0; damageIncrease = 1; enemyBeingAttacked = closestEnemy; //set the cooldown when the player was shooting an enemy but missed or a new enemy get in the way if (engaged == true) { //triggers cooldown which will stop the weapon from firing next update cycle timerUsedForCooldown = timeToUseForCooldown; } }
//Methods /// <summary> /// Updates the weapon's location and where it faces /// Calls up the Attacking method used for dealing damage /// Needs to be called in update loop in Game1 /// </summary> /// <param name="characterPosition">the player's location as a rectangle</param> /// <param name="mouseXCoordinate">the X coordinate of the mouse needed for determing what direction the weapon should face</param> /// <param name="gameTime">the timer to be used to keep track of cooldown time</param> public override void Update(List <EnemiesAbstract> listOfEnemies, Player player, GameTime gameTime) { //stores how much time has passed since last update and stores it in a variable TimeThatHasPassed += gameTime.ElapsedGameTime.TotalSeconds; //checks to see if the weapon should go into attacking phase if (IsAttacking) { // change weapon's direction DetermineWeaponDirection(player); if (timerUsedForCooldown >= 0) { IsAttacking = false; CooldownTime = timeToUseForCooldown; timerUsedForCooldown = timeToUseForCooldown - (float)TimeThatHasPassed; } else { CooldownTime = -1; //progress through attacking sequence Attacking(listOfEnemies, player); } } else { //keeps everything set to default value when not attacking anymore enemyBeingAttacked = null; damageIncrease = 1; engaged = false; if (timerUsedForCooldown >= 0) { CooldownTime = timeToUseForCooldown; timerUsedForCooldown = timeToUseForCooldown - (float)TimeThatHasPassed; } else { CooldownTime = -1; TimeThatHasPassed = 0; } //If player is null, then this weapon is dropped and is not being held by the player. //Thus does nothing to weapon's position if (player != null) { DetermineWeaponDirection(player); } } }
//Attack() method is defined in WeaponAbstract and can be called elsewhere to make this weapon attack /// <summary> /// ATTACKING METHOD FOR Disintegrator Ray WEAPON /// /// creates a rectangle in a straight line and checks if hit enemy. /// If they do, calls up the enemy's TakenDamage() method /// </summary> /// <param name="listOfEnemies">the list of enemies to check for collusion with</param> /// <param name="player">the player to use for location of weapon</param> protected override void Attacking(List <EnemiesAbstract> listOfEnemies, Player player) { closestEnemy = null; //creates a path going in direction that the gun is facing //make beam in direction that is is facing if (WeaponFacing == WeaponDirection.Up) { //shoots up beamPath.X = location.X + faceUp.Width / 2 - 5; beamPath.Y = 0; beamPath.Width = 4; beamPath.Height = location.Y + 5; //loops through list of enemies and see if it hit one of them //if so, damages the enemy for (int b = 0; b < listOfEnemies.Count; b++) { if (beamPath.Intersects(listOfEnemies[b].EnemyHitBox) && listOfEnemies[b].Health > 0) { //stores enemy in closest enemy variable if it intersects the beam. //replaces that stored enemy with the new enemy if the new one is closer to weapon if (closestEnemy == null) { closestEnemy = listOfEnemies[b]; } else if (listOfEnemies[b].EnemyHitBox.Y > closestEnemy.EnemyHitBox.Y) { closestEnemy = listOfEnemies[b]; } } } //checks to see if we are staying focused on the same enemy and increase damage if we stayed focused long enough if (closestEnemy != null && enemyBeingAttacked == closestEnemy) { if (TimeThatHasPassed > timeTillRampUp) { damageIncrease += 1; } closestEnemy.TakeDamageButNoKnockback(Damage + damageIncrease); } else { Reset(); } //modify beam path for the draw method later on if (closestEnemy != null) { engaged = true; beamPath.Y = closestEnemy.EnemyHitBox.Y + closestEnemy.EnemyHitBox.Height / 2; beamPath.Height -= closestEnemy.EnemyHitBox.Y + closestEnemy.EnemyHitBox.Height / 2; } else { engaged = false; } } else if (WeaponFacing == WeaponDirection.Down) { //shoots down beamPath.X = location.X + faceDown.Width / 2 - 5; beamPath.Y = location.Y + faceDown.Height / 2 - 2; beamPath.Width = 4; beamPath.Height = 650 - location.Y; //loops through list of enemies and see if it hit one of them //if so, damages the enemy for (int b = 0; b < listOfEnemies.Count; b++) { if (beamPath.Intersects(listOfEnemies[b].EnemyHitBox) && listOfEnemies[b].Health > 0) { //stores enemy in closest enemy variable if it intersects the beam. //replaces that stored enemy with the new enemy if the new one is closer to weapon if (closestEnemy == null) { closestEnemy = listOfEnemies[b]; } else if (listOfEnemies[b].EnemyHitBox.Y < closestEnemy.EnemyHitBox.Y) { closestEnemy = listOfEnemies[b]; } } } //checks to see if we are staying focused on the same enemy and increase damage if we stayed focused long enough if (closestEnemy != null && enemyBeingAttacked == closestEnemy) { if (TimeThatHasPassed > timeTillRampUp) { damageIncrease += 1; } closestEnemy.TakeDamageButNoKnockback(Damage + damageIncrease); } else { Reset(); } //modify beam path for the draw method later on if (closestEnemy != null) { engaged = true; beamPath.Height = closestEnemy.EnemyHitBox.Y - closestEnemy.EnemyHitBox.Height / 2 - location.Y; } else { engaged = false; } } else if (WeaponFacing == WeaponDirection.Right) { //shoots right beamPath.X = location.X + faceLeft.Width / 2 + 12; beamPath.Y = location.Y + faceLeft.Height / 2 + 15; beamPath.Width = 800 - location.X; beamPath.Height = 4; //loops through list of enemies and see if it hit one of them //if so, damages the enemy for (int b = 0; b < listOfEnemies.Count; b++) { if (beamPath.Intersects(listOfEnemies[b].EnemyHitBox) && listOfEnemies[b].Health > 0) { //stores enemy in closest enemy variable if it intersects the beam. //replaces that stored enemy with the new enemy if the new one is closer to weapon if (closestEnemy == null) { closestEnemy = listOfEnemies[b]; } else if (listOfEnemies[b].EnemyHitBox.X < closestEnemy.EnemyHitBox.X) { closestEnemy = listOfEnemies[b]; } } } //checks to see if we are staying focused on the same enemy and increase damage if we stayed focused long enough if (closestEnemy != null && enemyBeingAttacked == closestEnemy) { if (TimeThatHasPassed > timeTillRampUp) { damageIncrease += 1; } closestEnemy.TakeDamageButNoKnockback(Damage + damageIncrease); } else { Reset(); } //modify beam path for the draw method later on if (closestEnemy != null) { engaged = true; beamPath.Width = closestEnemy.EnemyHitBox.X - closestEnemy.EnemyHitBox.Width - location.X; } else { engaged = false; } } else { //shoots left beamPath.X = 0; beamPath.Y = location.Y + faceLeft.Height / 2 - 10; beamPath.Width = location.X + 11; beamPath.Height = 4; //loops through list of enemies and see if it hit one of them //if so, damages the enemy for (int b = 0; b < listOfEnemies.Count; b++) { if (beamPath.Intersects(listOfEnemies[b].EnemyHitBox) && listOfEnemies[b].Health > 0) { //stores enemy in closest enemy variable if it intersects the beam. //replaces that stored enemy with the new enemy if the new one is closer to weapon if (closestEnemy == null) { closestEnemy = listOfEnemies[b]; } else if (listOfEnemies[b].EnemyHitBox.X > closestEnemy.EnemyHitBox.X) { closestEnemy = listOfEnemies[b]; } } } //checks to see if we are staying focused on the same enemy and increase damage if we stayed focused long enough if (closestEnemy != null && enemyBeingAttacked == closestEnemy) { if (TimeThatHasPassed > timeTillRampUp) { damageIncrease += 1; } closestEnemy.TakeDamageButNoKnockback(Damage + damageIncrease); } else { Reset(); } //modify beam path for the draw method later on if (closestEnemy != null) { engaged = true; beamPath.X = closestEnemy.EnemyHitBox.X + closestEnemy.EnemyHitBox.Width / 2; beamPath.Width -= closestEnemy.EnemyHitBox.X + closestEnemy.EnemyHitBox.Width / 2; } else { engaged = false; } } }