Nice function for "rolling score up"?

Posted by bobobobo on Game Development See other posts from Game Development or by bobobobo
Published on 2013-10-23T00:31:23Z Indexed on 2013/10/23 4:12 UTC
Read the original article Hit count: 212

Filed under:

I'm adding to the player's score, and I'm using a per-frame formula like:

int score, displayedScore ;// score is ACTUAL score player has,
// displayedScore is what is shown this frame to the player
// (the creeping/"rolling" number)

float disparity = score - displayedScore ;
int d = disparity * .1f ; // add 1/10 of the difference,
if( !d )  d = signum( disparity ) ; // last 10 go by 1's
score += d ;

Where

inline int signum( float val ){
  if( val > 0 )  return 1 ;
  else if( val < 0 )  return -1 ;
  else return 0 ;
}

So, it kind of works where it makes big changes rapidly, then it creeps in the last few one at a time.

But I'm looking for better (or possibly well known?) score-creeping functions. Any one?

© Game Development or respective owner

Related posts about scoring