Actually... it needs to be more like...
delay = x 'where x = seconds... 1 = 1 second... .5 = 1/2 second...
t = timer 'initalize timer
Do
If timer => t + delay Then
ShootLaser 'execute the laser routine
t = timer 'reset timer
End If
Loop Until inkey$ <> "" '*(I hate endless loops)
That should get you a little better results...
or even put a delay for the entire program loop...
delay = x 'Set Delay to X seconds
t = timer 'initalize timer
Do
Loop Until timer => t + delay 'wait until the delay has completed
...this will give you better results in the long run by regulating the flow of the program
By doing this the game should run the same on any computer that meets or exceeds the requirements to run the game
Be sure to set the delay LOW... like .01 to .1:
.017 is about 60 frames per second
.033 is about 30 frames per second
or just set the delay by saying: Delay = frames / 1
Delay = 30 / 1 'for 30fps
Delay = 60 / 1 'for 60fps
One last thing to think about...
TIMER returns the number of seconds past midnight (data-type: Double)
So, there is a rare case when the clock ticks between 11:59pm and 12:00am and the timer is reset to 0 (from 86399)
Unless you realy want your program to delay for at least 24 hours... You can trap this by doing the following:
replace
Loop Until timer => t + delay with Loop Until ABS(timer - t) => delay
this way if the clock does happen to click over in the middle of your loop it will read...
abs(0 - 86399) => delay (86399 => delay)
instead of 0 => 86399 + delay
...which could easily end up being an endless loop if t + delay > 86400 making it impossible for the timer to exceed, and causing your program to lock up
Probably the best way to use a delay is like this...
delay = frames / 1 'Set Delay (fps)
do 'start main loop
t = timer 'initalize timer before main loop code
'Your main loop code goes here
'This way the processing time is included in the delay and not added to it
Do
Loop Until abs(timer - t) => delay 'if the delay has not been exceeded, finish delay
Loop Until inkey$ <> "" 'I still hate endless loops
This should give you a few things to think about
-Josh
Sometimes... the BASIC things in life are the best...
or at least the most fun ;-)
-Josh Stribling