TO SQUASH: actual scoring.
This commit is contained in:
@@ -59,7 +59,13 @@ public class LevelEnder : MonoBehaviour
|
||||
|
||||
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
|
||||
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()
|
||||
{
|
||||
tallyShown = false;
|
||||
|
||||
// Stop all spawners.
|
||||
ballSpawner.StopSpawning();
|
||||
multiplierSpawner.StopSpawning();
|
||||
@@ -139,6 +157,26 @@ public class LevelEnder : MonoBehaviour
|
||||
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)
|
||||
{
|
||||
bonusText.text = $"{bonusValue}";
|
||||
@@ -163,15 +201,15 @@ public class LevelEnder : MonoBehaviour
|
||||
|
||||
// Wait a moment before showing the bonus tally.
|
||||
yield return new WaitForSeconds(1.5f);
|
||||
int total = player.bonus;
|
||||
scoreTotal = player.bonus;
|
||||
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.
|
||||
yield return new WaitForSeconds(0.75f);
|
||||
int overachieverBonusCount = 20 - (100 - player.percentCovered);
|
||||
int overachieverBonusValue = 100 * overachieverBonusCount;
|
||||
total += overachieverBonusValue;
|
||||
scoreTotal += overachieverBonusValue;
|
||||
|
||||
ShowBonus(
|
||||
overachieverBonus,
|
||||
@@ -181,13 +219,13 @@ public class LevelEnder : MonoBehaviour
|
||||
overarchieverPercentLabel,
|
||||
showBonus
|
||||
);
|
||||
ShowBonus(totalBonus, total, null, null, null, showBonus);
|
||||
ShowBonus(totalBonus, scoreTotal, 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;
|
||||
scoreTotal += isolationBonusValue;
|
||||
|
||||
ShowBonus(
|
||||
isolationBonus,
|
||||
@@ -197,14 +235,14 @@ public class LevelEnder : MonoBehaviour
|
||||
isolationBonusCount == 1 ? isolationCountSingleLabel : isolationCountPluralLabel,
|
||||
showBonus
|
||||
);
|
||||
ShowBonus(totalBonus, total, null, null, null, showBonus);
|
||||
ShowBonus(totalBonus, scoreTotal, 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);
|
||||
scoreTotal = (int)(scoreTotal * player.multiplier);
|
||||
|
||||
ShowBonus(
|
||||
multiplierBonus,
|
||||
@@ -214,7 +252,12 @@ public class LevelEnder : MonoBehaviour
|
||||
null,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user