Some code that will help you write games that run at same speed all pc's. What may run ok'ish on your pc may run too fast on a super-duper computer.
Should be ok for 2d and 3d games.
Simply gosub the init routine before main loop and gosub other routine as first thing in main loop.
The idea being that routine counts how many loops are run every second and modifies move# accordingly. It updates once per second for smoothness sake, but you can change t9 if you want it to update more regularly.
Have included some basic objects to show how to use move#
You can therefore force objects to move a certain amount in 1 second, rotate a set number of degrees in 1 second.
Enjoy!
sync on : sync rate 0 : autocam off
` make some objects
make matrix 1,1000,1000,50,50
make object sphere 1,50 : position object 1,500,0,600 : set object wireframe 1,1
make object cube 2,40
make object cube 3,10 : position object 3,400,5,700
position camera 500,20,400
x#=0
gosub init_timer
do
gosub timer_stuff
` player moves 40 units in 1 second and rotates 90 degrees in one second
control camera using arrowkeys 0,40.0*move#,90.0*move#
` rotate sphere so it rotates 180 degrees in 1 second
turn object left 1,180.0*move#
` bob cube up and down so it takes 1 second
x#=wrapvalue(x#+(360.0*move#))
position object 2,550,50.0*sin(x#),600
` make object chase you at rate of 20 units per second
point object 3,camera position x(),camera position y(),camera position z()
xrotate object 3,0
move object 3,20.0*move#
text 0,20,get time$()
text 0,0,str$(screen fps())
sync
loop
init_timer:
` t9 is how often to change speed (in milliseconds)
t1=timer() : t9=1000
return
timer_stuff:
` don't change any of this!
t2=timer() : inc t3
if t2-t1 >= t9
move#=((t2-t1)/1000.0)/t3 : t1=t2 : t3=0 : t4=1
else
if t4=0 then move#=((t2-t1)/1000.0)/t3
endif
return
If your mansion house needs haunting, just call Rentaghost!