Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: ClrDraw on March 14, 2014, 11:36:00 pm
-
I'm making Don't Step The White Tile and need to time how long it takes the player to get to the end. How do I use a timer in axe? Do I need to use interrupts (And if so, how? My calc likes to freeze whenever I try using interrupts...)?
Please help; this is the last thing I need before my game is all finished :)
-
Yeah, interrupts are the way to go when you need to measure a time. The slowest setting should be fine for a game, since you don't need it accurate. Inside the Interrupt Service Routine you increment a variable. Since interrupt speed "6" corresponds to 118 Hz on a 83+ or to 108 Hz on a 84+, you divide by 118 or 108 to get the amount of seconds elapsed (or by 12 / 11 for tenths of a second). It is important to put the calc back to normal interrupt mode before exiting, otherwise crashes occur.
... // initializing stuff
fnInt(TMR,6) //turn on the interrupt
0->T //say T is our timer variable, reset it when the game starts.
game loop {
...// Stuff
}
T->S //save the time after the game finished
S/118->S //get the seconds elapsed
...// win display stuff
LnReg // back to normal interrupt mode, this is important
LnRegr //repair any damage done by the custom interrupt
Return //Exit
Lbl TMR //the actual interrupt service routine
T++ // increment the counter variable
Return //it's a subroutine so we return as usual
We don't need to make sure it doesn't overflow if you reset it everytime a nee game starts. Since the counter is incremented 118 a second and can only hold values up to 65535, it can run 555 seconds before it resets, that's about 9 minutes. So if a game takes longer than that, you need to use multiple variables, but I guess that shouldn't be a problem right now ;)
Either way, good luck with your project - I'm looking forward to see it :)
-
Thank you so much! That's just what I needed. It should be done really soon thanks to you ;D