Scrolling Counter

Started by Global Lint, Fri 30/04/2010 18:39:13

Previous topic - Next topic

Global Lint

-Scrolling point counter-

I would like to make a scrolling HP counter that loosely mimics the one used in Earthbound.  It definitely doesn't need to be as artistic or fancy as Earthbound's, just functional (but I'll gladly accept any advice on creating a counter that actually scrolls like an old digital clock.)

Let's say I wanted to create a point counter (used as an hp counter) where the numbers are subtracted or added slowly, instead of jumping instantly to the sum.  For instance, if the @SCORE@ begins at 10, and the player uses an item that restores 20 points, you would see the score go from 10 to 11 to 12 to 13 to 14... to 20, each number lasting on the screen for about half a second.

Any ideas?
Spaz ate the dopefish.

discordance

Code: ags

int new_hp = hp + 20;
while (hp < new_hp) {
  hp++;
  //display the value of hp, however it is you're doing this
  Wait(20);
}


Is that the kind of thing you're after?

Global Lint

#2
I think that's exactly it.  I'll edit this post tomorrow if it was useful.  Thank you :)

EDIT-

Thanks a ton!  This is exactly what I'm looking for!  

I might be back if I don't want the game to take away controls from the player while counting down or up, but for now it's fine.  :)
Spaz ate the dopefish.

Mr Flibble

#3
AGS will crash if you make it run a single loop more than 15,000 times, just to warn you incase you forsee jumps of that size. You could work around this by making the increment of the score relative to the increase in score.

Just remember to convert all decimal numbers back to integers and watch out for overshooting your target.

So for instance you might want code that does the following:
Code: ags

int increase; //amount hp will go up by
int new_hp = hp + increase;
int increment = increase/10; //then convert this to an integer, I don't remember the code off the top of my head.
//You'd ideally make the 10 relative to the size of increase, since depending on your method of converting to 
//an integer, values of increase below 5 will always result in an increment of 0.

while (hp<new_hp){
         if (new_hp - hp < increment) { //if the difference is less than the increment value 
                                        //ie. if the next increment would overshoot the target
                       hp = new_hp; //just add the difference and reach the target already
         }
        else { //otherwise, run our standard code here
                      hp = hp + increment;
                      Wait(20);
        }
}


This is more complicated than you need probably, but it represents a more flexible solution which might be helpful to someone in the future when searching for how to do this.
Ah! There is no emoticon for what I'm feeling!

Ryan Timothy B

Quote from: Mr Flibble on Sat 01/05/2010 21:40:14
AGS will crash if you make it run a single loop more than 15,000 times, just to warn you incase you forsee jumps of that size.
You could always use: noloopcheck  (check it up in the manual)
But just as the manual says, you should never use this unless you actually need a loop to run more than 15,000 times.

Mr Flibble

Quote from: Ryan Timothy on Sun 02/05/2010 00:53:36
You could always use: noloopcheck  (check it up in the manual)

Oh god, I never knew about that. I've already rewritten code because of it. Admittedly it's better code now, but still.
Ah! There is no emoticon for what I'm feeling!

Khris

I've written the first version of a module.

Explanation and download here:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=40796.0

SMF spam blocked by CleanTalk