[4.1] How to handle time?

darkhog

New member
I want to make "timed" platformer like original Mario was. I know how to make player die when it reaches 0, know how to set up it in the hud, but have no idea how to make it count down (as in, arithmetic itself is easy, just don't know where to put timing code so it would execute roughly each second).
 

dale_coop

Moderator
Staff member
Not be too difficult to add a variable in the timer... update this on hud...
Almost as chronosv2 did in its 4.0 demo.
 

darkhog

New member
Yep, most of it is not difficult at all. My problem is where to put JSR to the code so it'd execute roughly each second. Rest of it is easy.
 

chronosv2

New member
If you need to check for a certain value you should make a copy of HandleGameTimer.asm (GameEngineData\Routines\Basic\System\HandleGameTimer.asm), then insert your code at Line 3.
If you want quick, easy and minimal extra variables you could AND gameTimer against the number 63 ($3F, %00111111) and run your timer second tick if equal.

Edit: You'll also need to re-load GameTimer into the accumulator for the BNE that was on Line 3 you'll be displacing.
 

chronosv2

New member
I used 63 because it's easy to AND against, and uses the least code.
Since it's binary 00111111, when you AND against it and the result equals 0 you have either 0, 64, 128, 192.

At least right now, the timer starts at 0, then subtracts 1 to get 255, then subtracts until it reaches 0 again. You could compare the results of your AND to the number 60 but any time the binary representation of 60 becomes true, whether the number is a multiple of 60 or not, the countdown would tick.

In this case, though, since I'm already ANDing 63 with gameTimer it probably would only really be those extra couple bytes and 2 CPU cycles, but 63 is close enough to 60 that unless you're speedrunning your average player's not going to object to 0.05sec drift.
 
Top Bottom