TO SQUASH: actual scoring.

This commit is contained in:
2026-08-27 15:06:29 -04:00
parent af58cd1cb0
commit 21b0fd7648
+54 -11
View File
@@ -59,7 +59,13 @@ public class LevelEnder : MonoBehaviour
private bool levelEnded = false; private bool levelEnded = false;
private bool accelerate = false; private bool tallyShown = false;
private bool addScoreToPlayer = false;
private int scoreTotal = 0;
private float addScoreTimer = 0.0f;
// Start is called once before the first execution of Update after the MonoBehaviour is created // Start is called once before the first execution of Update after the MonoBehaviour is created
void Start() void Start()
@@ -91,12 +97,24 @@ public class LevelEnder : MonoBehaviour
) )
) )
{ {
accelerate = true; addScoreToPlayer = true;
}
if (addScoreToPlayer && tallyShown)
{
addScoreTimer += Time.deltaTime;
if (addScoreTimer >= 0.02f && scoreTotal > 0)
{
addScoreTimer = 0.0f;
addScoreToPlayer = AddScore();
}
} }
} }
public void EndLevel() public void EndLevel()
{ {
tallyShown = false;
// Stop all spawners. // Stop all spawners.
ballSpawner.StopSpawning(); ballSpawner.StopSpawning();
multiplierSpawner.StopSpawning(); multiplierSpawner.StopSpawning();
@@ -139,6 +157,26 @@ public class LevelEnder : MonoBehaviour
worldFiller.ClearSpawnedWalls(); worldFiller.ClearSpawnedWalls();
} }
private bool AddScore()
{
audioSource.PlayOneShot(countBonus);
int scoreToAdd = scoreTotal > 100 ? 100 : scoreTotal;
scoreTotal -= 100;
scoreTotal = Mathf.Max(scoreTotal, 0);
player.score += scoreToAdd;
ShowBonus(totalBonus, scoreTotal, null, null, null, showBonus);
if (scoreTotal <= 0)
{
audioSource.PlayOneShot(showBonus);
return false;
}
return true;
}
private void ShowBonus(Text bonusText, int bonusValue, int? bonusCount, Text countLabel, SpriteRenderer bonusLabel, AudioClip bonusSound) private void ShowBonus(Text bonusText, int bonusValue, int? bonusCount, Text countLabel, SpriteRenderer bonusLabel, AudioClip bonusSound)
{ {
bonusText.text = $"{bonusValue}"; bonusText.text = $"{bonusValue}";
@@ -163,15 +201,15 @@ public class LevelEnder : MonoBehaviour
// Wait a moment before showing the bonus tally. // Wait a moment before showing the bonus tally.
yield return new WaitForSeconds(1.5f); yield return new WaitForSeconds(1.5f);
int total = player.bonus; scoreTotal = player.bonus;
ShowBonus(timeBonus, player.bonus, null, null, null, showBonus); ShowBonus(timeBonus, player.bonus, null, null, null, showBonus);
ShowBonus(totalBonus, total, null, null, null, showBonus); ShowBonus(totalBonus, scoreTotal, null, null, null, showBonus);
// Calculate and show the overachiever bonus. // Calculate and show the overachiever bonus.
yield return new WaitForSeconds(0.75f); yield return new WaitForSeconds(0.75f);
int overachieverBonusCount = 20 - (100 - player.percentCovered); int overachieverBonusCount = 20 - (100 - player.percentCovered);
int overachieverBonusValue = 100 * overachieverBonusCount; int overachieverBonusValue = 100 * overachieverBonusCount;
total += overachieverBonusValue; scoreTotal += overachieverBonusValue;
ShowBonus( ShowBonus(
overachieverBonus, overachieverBonus,
@@ -181,13 +219,13 @@ public class LevelEnder : MonoBehaviour
overarchieverPercentLabel, overarchieverPercentLabel,
showBonus showBonus
); );
ShowBonus(totalBonus, total, null, null, null, showBonus); ShowBonus(totalBonus, scoreTotal, null, null, null, showBonus);
// Calculate and show the isolation bonus. // Calculate and show the isolation bonus.
yield return new WaitForSeconds(0.75f); yield return new WaitForSeconds(0.75f);
int isolationBonusCount = 0; int isolationBonusCount = 0;
int isolationBonusValue = 100 * isolationBonusCount; int isolationBonusValue = 100 * isolationBonusCount;
total += isolationBonusValue; scoreTotal += isolationBonusValue;
ShowBonus( ShowBonus(
isolationBonus, isolationBonus,
@@ -197,14 +235,14 @@ public class LevelEnder : MonoBehaviour
isolationBonusCount == 1 ? isolationCountSingleLabel : isolationCountPluralLabel, isolationBonusCount == 1 ? isolationCountSingleLabel : isolationCountPluralLabel,
showBonus showBonus
); );
ShowBonus(totalBonus, total, null, null, null, showBonus); ShowBonus(totalBonus, scoreTotal, null, null, null, showBonus);
// Calculate and show the multiplier bonus if applicable. // Calculate and show the multiplier bonus if applicable.
if (player.multiplier != 1.0f) if (player.multiplier != 1.0f)
{ {
yield return new WaitForSeconds(0.75f); yield return new WaitForSeconds(0.75f);
int multiplierValue = player.multiplier == 0.5f ? 1 : (int)(player.multiplier); int multiplierValue = player.multiplier == 0.5f ? 1 : (int)(player.multiplier);
total = (int)(total * player.multiplier); scoreTotal = (int)(scoreTotal * player.multiplier);
ShowBonus( ShowBonus(
multiplierBonus, multiplierBonus,
@@ -214,7 +252,12 @@ public class LevelEnder : MonoBehaviour
null, null,
multiplierValue == 1 ? multiplierPenaltySound : multiplierBonusSound multiplierValue == 1 ? multiplierPenaltySound : multiplierBonusSound
); );
ShowBonus(totalBonus, total, null, null, null, showBonus); ShowBonus(totalBonus, scoreTotal, null, null, null, showBonus);
} }
tallyShown = true;
yield return new WaitForSeconds(7.3f - 3.0f - (player.multiplier != 1.0f ? 0.75f : 0.0f));
addScoreToPlayer = true;
} }
} }