This is the main important code:
Code: Select all
dim shared MOVEMENT_AMOUNT as double
type App
private:
dim Fps as integer
dim Max_Fps as integer = 200
dim Game as Engine
public:
declare Function FrameCounter() As Integer
declare Function Regulate(ByVal MyFps As Integer,ByRef fps As Integer) As Integer
declare sub Main()
end type
'=============================================================================== Dodicat
Function App.FrameCounter() As Integer
Var t1=Timer,t2=t1
Static As Double t3,frames,answer
frames+=1
If (t2-t3) >= 1 Then t3 = t2 : answer = frames : frames = 0
Function= answer
End Function
'==============================================================================
Function App.Regulate(ByVal MyFps As Integer, ByRef fps As Integer) As Integer
fps=FrameCounter()
Static As Double timervalue,lastsleeptime
Dim As Double delta
Var k=fps-myfps,i=1/myfps
If Abs(k)>1 Then delta+=i*Sgn(k)
Var sleeptime=lastsleeptime+(i-Timer+timervalue)*2000+delta
If sleeptime<1 Then sleeptime=1
lastsleeptime=sleeptime
timervalue=Timer
Return sleeptime
End Function
'===============================================================================
sub App.Main()
this.Game.Init()
do 'The main rendering loop
screenlock 'locks the screen so you can put stuff on it
cls 'clears the screen
this.Game.Render() 'Renders the game onto the screen
print "FPS:"; this.fps
screenunlock 'Unlocks the screen
sleep this.Regulate(this.Max_FPS, this.fps) 'sleeps for a specified amount of time
if FPS > 0 then 'Sets the global movement speed
MOVEMENT_AMOUNT = 1/FPS
end if
this.Game.Update() 'Updates the engine
loop until inkey = chr(255) + "k" or multikey(SC_ESCAPE) 'loops until the escape key is hit or the close button is hit
end sub
dim Self as App
Self.Main()
Code: Select all
sleep this.Regulate(this.Max_FPS, this.fps) 'sleeps for a specified amount of time
if FPS > 0 then 'Sets the global movement speed
MOVEMENT_AMOUNT = 1/FPS
end if
Code: Select all
leftRight = multikey(LEFT_KEY) + -1*multikey(RIGHT_KEY)
upDown = multikey(UP_KEY) + -1*multikey(DOWN_KEY)
moveX = leftRight*MOVEMENT_AMOUNT*this.PlayerSpeed
moveY = upDown*MOVEMENT_AMOUNT*this.PlayerSpeed