TO SQUASH: Show scores at level end.

This commit is contained in:
2026-08-27 14:41:40 -04:00
parent 683cfdcc9f
commit af58cd1cb0
9 changed files with 1577 additions and 58 deletions
+103 -1
View File
@@ -1,6 +1,7 @@
using UnityEngine;
using System.Collections;
using UnityEngine.InputSystem;
using UnityEngine.UI;
using System.Collections;
public class LevelEnder : MonoBehaviour
{
@@ -26,6 +27,34 @@ public class LevelEnder : MonoBehaviour
public AudioClip victory;
public AudioClip showBonus;
public AudioClip countBonus;
public AudioClip multiplierBonusSound;
public AudioClip multiplierPenaltySound;
public Text timeBonus;
public Text overachieverBonus;
public Text overachieverPercent;
public Text isolationBonus;
public Text isolationCount;
public Text multiplierBonus;
public Text totalBonus;
public SpriteRenderer overarchieverPercentLabel;
public SpriteRenderer isolationCountSingleLabel;
public SpriteRenderer isolationCountPluralLabel;
private AudioSource audioSource;
private bool levelEnded = false;
@@ -110,9 +139,82 @@ public class LevelEnder : MonoBehaviour
worldFiller.ClearSpawnedWalls();
}
private void ShowBonus(Text bonusText, int bonusValue, int? bonusCount, Text countLabel, SpriteRenderer bonusLabel, AudioClip bonusSound)
{
bonusText.text = $"{bonusValue}";
if (bonusCount.HasValue)
{
countLabel.text = $"{bonusCount.Value}";
}
if (bonusLabel)
{
bonusLabel.enabled = true;
}
audioSource.PlayOneShot(bonusSound);
}
private IEnumerator EndLevelAfterDelay()
{
yield return new WaitForSeconds(victory.length);
EndLevel();
// Wait a moment before showing the bonus tally.
yield return new WaitForSeconds(1.5f);
int total = player.bonus;
ShowBonus(timeBonus, player.bonus, null, null, null, showBonus);
ShowBonus(totalBonus, total, null, null, null, showBonus);
// Calculate and show the overachiever bonus.
yield return new WaitForSeconds(0.75f);
int overachieverBonusCount = 20 - (100 - player.percentCovered);
int overachieverBonusValue = 100 * overachieverBonusCount;
total += overachieverBonusValue;
ShowBonus(
overachieverBonus,
overachieverBonusValue,
overachieverBonusCount,
overachieverPercent,
overarchieverPercentLabel,
showBonus
);
ShowBonus(totalBonus, total, null, null, null, showBonus);
// Calculate and show the isolation bonus.
yield return new WaitForSeconds(0.75f);
int isolationBonusCount = 0;
int isolationBonusValue = 100 * isolationBonusCount;
total += isolationBonusValue;
ShowBonus(
isolationBonus,
isolationBonusValue,
isolationBonusCount,
isolationCount,
isolationBonusCount == 1 ? isolationCountSingleLabel : isolationCountPluralLabel,
showBonus
);
ShowBonus(totalBonus, total, null, null, null, showBonus);
// Calculate and show the multiplier bonus if applicable.
if (player.multiplier != 1.0f)
{
yield return new WaitForSeconds(0.75f);
int multiplierValue = player.multiplier == 0.5f ? 1 : (int)(player.multiplier);
total = (int)(total * player.multiplier);
ShowBonus(
multiplierBonus,
multiplierValue,
null,
null,
null,
multiplierValue == 1 ? multiplierPenaltySound : multiplierBonusSound
);
ShowBonus(totalBonus, total, null, null, null, showBonus);
}
}
}