Pause the game, pause the timers

Blitz3D Forums/Blitz3D Programming/Pause the game, pause the timers

slenkar(Posted 2004) [#1]
Hi, I have some delay timers for how often a gun can fire.
If mousehit(1)
If time>gun_timer+2000
fire_gun()
gun_timer=time
EndIf
EndIf


When I pause the game the gun can fire again straight away (in game time) so how do I put the timer on pause?


John Pickford(Posted 2004) [#2]
1) Every game I've ever written (In 20 years or so!) has had a game_clock variable.

2) Pauseing games is one of those things that is never as easy as it seems.

3) I don't actually understand your problem so I'm not going to be very helpful.


CGV(Posted 2004) [#3]
Have you tried updating the gun_timer variable to the current time after unpausing the game.


ZombieWoof(Posted 2004) [#4]
onPause
store current time
onUnpause
offset = time - stored time
add to all timers like the one above


slenkar(Posted 2004) [#5]
ah yeh zombiewoof got it,

say gun_timer is 1000 and time is 1100,
*game is paused*
pause_time=1100
*game is unpaused*
new_time=2000

offset=2000-1100=900

gun_timer=1900

which means there is still 100 milliseconds til the next firing time.

thanks


OverDozing(Posted 2004) [#6]
Funny how some questions/problems open my eyes on other things... :)

Thanks guys !


Zethrax(Posted 2004) [#7]
What I do is to use a relative game timer that's updated by the amount of time taken by the previous loop at the start of each new loop.

eg.

; Untested code.
; 'game_time' holds the time value which should be used with all pausable time_out routines.

Global game_time
Global old_time
Global millisecs_time
Global time_out

old_time = MilliSecs()

Repeat

millisecs_time = MilliSecs()
the_time_taken = millisecs_time - old_time
game_time = game_time + the_time_taken
old_time = millisecs_time

If game_time > time_out
time_out = time_out + 1000
EndIf

If KeyHit( pause_key )
; -- Process pause event --
old_time = MilliSecs() ; Re-initialize 'old_time' after the pause.
EndIf

Until KeyHit( 1 )


Rimmsy(Posted 2004) [#8]
You have to be careful if you're using 3d tweening code, it stalls until the tweening code catches up.


slenkar(Posted 2004) [#9]
Ah yeah I am using tweening code and the timer thing didnt work, because now I can fire continuously with no delay - oops.

I dont have a clue what Axemans code does either arrgghh!!!!

If KeyHit(57)
FlushMouse

If paused=no
paused=yes
pause_time=time
Else

;set timers
offset_time=time-pause_time

For s.ship=Each ship
s\launch_timer=offset_time
Next

paused=no
EndIf
endif


am i doing something wrong?