Skip to content

Commit

Permalink
If a turret has a greater fire rate than it should, reset it
Browse files Browse the repository at this point in the history
  • Loading branch information
Greenfoot5 committed Nov 18, 2024
1 parent 56fcfbd commit 92c62c3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
9 changes: 2 additions & 7 deletions Tower Defence/Assets/Turrets/Choker/Choker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,14 @@ public class Choker : DynamicTurret
/// Rotates towards the target if the turret have one.
/// Shoots if the turret is looking towards the target
/// </summary>
private void Update()
private new void Update()
{
// If there's no fire rate, the turret shouldn't do anything
if (fireRate.GetStat() == 0)
{
return;
}
base.Update();

// Don't do anything if the turret doesn't have a target
if (Target is null)
{
fireCountdown -= Time.deltaTime;
return;
}

// Rotates the turret each frame
Expand Down
5 changes: 5 additions & 0 deletions Tower Defence/Assets/Turrets/Gunner/Gunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public class Gunner : DynamicTurret
/// </summary>
private void Update()
{
if (fireCountdown > fireRate.GetStat())
{
fireCountdown = 1 / fireRate.GetStat();
}

// If there's no fire rate, the turret shouldn't do anything
// However, it should rapidly cool down
if (fireRate.GetStat() == 0)
Expand Down
6 changes: 1 addition & 5 deletions Tower Defence/Assets/Turrets/Lancer/Lancer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ private bool HasATarget()
/// </summary>
private void Update()
{
// If there's no fire rate, the turret shouldn't do anything
if (fireRate.GetStat() == 0)
{
return;
}
base.Update();

// Don't do anything if no enemy is in range
if (!HasATarget())
Expand Down
6 changes: 1 addition & 5 deletions Tower Defence/Assets/Turrets/Shooter/Shooter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ public class Shooter : DynamicTurret
/// </summary>
private void Update()
{
// If there's no fire rate, the turret shouldn't do anything
if (fireRate.GetStat() == 0)
{
return;
}
base.Update();

// Don't do anything if the turret doesn't have a target
if (Target is null)
Expand Down
6 changes: 1 addition & 5 deletions Tower Defence/Assets/Turrets/Smasher/Smasher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ public class Smasher : Turret
/// </summary>
private void Update()
{
// If there's no fire rate, the turret shouldn't do anything
if (fireRate.GetStat() == 0)
{
return;
}
base.Update();

// Don't do anything if no enemy is in range
Collider2D[] results = Physics2D.OverlapCircleAll(transform.position, range.GetStat());
Expand Down
14 changes: 14 additions & 0 deletions Tower Defence/Assets/Turrets/Turret.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ private void Awake()
{
rangeDisplay.SetActive(false);
}

protected void Update()
{
// If there's no fire rate, the turret shouldn't do anything
if (fireRate.GetStat() == 0)
{
return;
}

if (fireCountdown > fireRate.GetStat())
{
fireCountdown = 1 / fireRate.GetStat();
}
}

/// <summary>
/// Update the range shader's size
Expand Down

0 comments on commit 92c62c3

Please sign in to comment.