Cash register score is a staple of arcade games. This is the technique of incrementing a score upwards in the UI whenever a player achieves some score amount, rather than doing a one-time addition of the score amount to the total score.
One of the simplest ways to implement this is to simply add any new score amount to a variable called score_queue and whenever score_queue is non-zero to subtract 1 from score_queue and add 1 to total_score every few milliseconds (for example, every 0.017s).
This naive approach is obviously problematic when dealing with big scores. For example, if I kill an enemy worth 250,000 score and add 1 to my total_score every frame, it would take 250,000 * 0.017 = ~71 seconds for my score counter to tick to the final value! Yuck.
One way I thought to combat this is with logic like the following (simplified for illustration):
Code: Select all
// cash register score
if (score_queue > 0)
{
if (Time.time > time_of_last_score_update + score_frequency)
{
time_of_last_score_update = Time.time;
if (score_queue >= 1000 && score_queue % 1000 == 0)
{
score_queue -= 1000;
score += 1000;
}
else
{
score_queue -= 10;
score += 10;
}
}
}
So, what are some techniques that you use to implement nice cash register score?