In my games now what I usually do is the following:
;Core game Loop
LogicTime=Millisecs()-1
LogicTimeDelay=20 ;50fps
GraphicTimeDelay=15 ;60fps (approx)
repeat
CurTime=Millisecs()
If CurTime>LogicTime then
Delta#=1.0+Float(CurTime-LogicTime)/Float(LogicTimeDelay)
LogicTime=CurTime+LogicTimeDelay
UpdateCamera(Delta#)
UpdateUnits(Delta#)
UpdateBullets(Delta#)
UpdateParticles(Delta#) ;and so on for all the logic related functions that manage all the stuff in the game
UpdateWorld Delta#
endif
If CurTime>GraphicTime then
GraphicTime=CurTime+GraphicTimeDelay
;do all rendering stuff in here
renderworld
text 0,0,"FPS:"+str(fps)
vwait
flip false
endif
fpscount=fpscount+1
if millisecs()>fpstime then
fps=fpscount
fpstime=millisecs()+1000
fpscount=0
endif
forever
and in those functions I do the following:
for example:
;any changes in position, velocity,acceleration which are ;additive I do as follows:such as with particles
;I haven't defined the ParticleObject type but you should get the general idea
For P.ParticleObject=each ParticleObject
P\positionx=P\positionx+p\velocityx*Delta#
P\velocityx=P\velocityx+p\accelerationx*Delta#
;same for y and z
P\Scale=P\Scale+P\ScaleFactor^Delta
;Any values which are multiplied by a factor you simply take that factor and raise it to the power of Delta. Assumes that these scaling factors are not negative, but may be any value from 0 upwards.
next
|