Skip to content

Instantly share code, notes, and snippets.

@aliustaoglu
Last active August 8, 2021 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aliustaoglu/13ea9bb0a0e5609272feddb64086d120 to your computer and use it in GitHub Desktop.
Save aliustaoglu/13ea9bb0a0e5609272feddb64086d120 to your computer and use it in GitHub Desktop.
FPS Control in AppGameKit
Global SyncRate = 30
SetSyncRate(SyncRate, 1)
SetClearColor(0, 0, 0)
CreateText(1, "Loading...")
SetTextAlignment(1, 1)
SetTextPosition(1, 50, 45)
SetTextSize(1, 10)
SetWindowSize( 640, 480, 1 )
SetupTimer()
SetRawMouseVisible(0)
Sync()
gosub LoadLevel
DeleteText(1)
rem Camera Position may need to be adjusted!
SetCameraPosition(1, 969, 552, 2950)
SetCameraRotation(1,0,0,0)
//player=CreateObjectBox(2,6,2)
//setObjectPosition(player, 969, 555, 2950)
speed# = .1
spdPlay = 10
CamX as Integer
CamY as Integer
CamZ as Integer
CamX = 0
CamY=0
CamZ=0
CenterX#=50
CenterY#=50
sunR#=125
sunG#=125
sunB#=125
SetSkyBoxSkyColor( 161,183,209 )
SetSkyBoxHorizonColor( 161, 183, 209 )
SetSunColor(sunR#,sunG#,sunB# )
SetSkyBoxSunColor(sunR#,sunG#,sunB# )
SetSkyBoxSunSize(10,50)
SetSkyBoxVisible(1)
setcamerarange(1,10,9999)
Do
GoSub FPSControl
Sync()
Loop
FPSControl:
GoSub MouseLook
GoSub WASD
Return
WASD:
if GetRawKeyState( 87 ) = 1
MoveCameraLocalZ(1, spdPlay)
endif
if GetRawKeyState( 83 ) = 1
MoveCameraLocalZ( 1, -spdPlay )
endif
if GetRawKeyState( 65 ) = 1
MoveCameraLocalX( 1, -spdPlay )
endif
if GetRawKeyState( 68 ) = 1
MoveCameraLocalX( 1, spdPlay )
endif
Return
MouseLook:
Xpos#=GetRawMouseY()
Ypos#=GetRawMouseX()
Print(GetPointerX())
DiffX#=XPos#-CenterX#
DiffY#=YPos#-CenterY#
//Print(DiffX#)
//Print(DiffY#)
//CamX=CamX-DiffX#
CamY=CamY+(DiffY#)
CamX=CamX+(DiffX#)
SetCameraRotation(1, CamX, CamY, CamZ)
SetRawMousePosition(CenterX#,CenterY#)
Return
LoadLevel:
Rem Shaders Create By TGC
LoadShader(1, "vertex.vs", "pixel.ps")
Dim lm[1]
lm[0] = LoadImage("0.png")
lm[1] = LoadImage("1.png")
For t = 0 to 1
SetImageWrapU(lm[t], 1)
SetImageWrapV(lm[t], 1)
Next t
objmax = 75
For obj = 1 to objmax
obj$ = "mesh-" + Str(obj) + ".obj"
LoadObject(obj, obj$, 0)
If obj >= 1 And obj <= 1 Then tex$ = "texture-" + Str(obj) + "-0.png"
If obj >= 2 And obj <= 8 Then tex$ = "texture-" + Str(obj) + "-1.png"
If obj >= 9 And obj <= 9 Then tex$ = "texture-" + Str(obj) + "-0.png"
If obj >= 10 And obj <= 28 Then tex$ = "texture-" + Str(obj) + "-1.png"
If obj >= 29 And obj <= 75 Then tex$ = "texture-" + Str(obj) + "-0.png"
texname$ = Left(tex$, Len(tex$) - 4)
lm$ = Right(texname$, 1)
If lm$ = "-" Then lm$ = "0"
teximg = LoadImage(tex$)
SetImageWrapU(teximg, 1)
SetImageWrapV(teximg, 1)
SetObjectImage(obj, teximg, 0)
SetObjectImage(obj, lm[val(lm$)], 1)
SetObjectShader(obj, 1)
perc# = obj
perc# = perc# / objmax
perc = perc# * 100
SetTextString(1, "Loading - " + Str(perc) + "%")
Sync()
Next obj
Return
CheckForInput:
if GetRawKeyState(37) = 1 then RotateCameraLocalY(1, -TimerMove(0.2))
if GetRawKeyState(38) = 1 then MoveCameraLocalZ(1, TimerMove(0.2))
if GetRawKeyState(39) = 1 then RotateCameraLocalY(1, TimerMove(0.2))
if GetRawKeyState(40) = 1 then MoveCameraLocalZ(1, -TimerMove(0.2))
Return
Rem Based on the Timer System by Airslide
Function SetupTimer()
Global fps#
Global rate#
Global difference
Global previousTime
EndFunction
Function UpdateTimer()
difference = Timer() - previousTime
if difference=0 then difference=1
fps# = 1000 / difference
rate# = fps# / SyncRate
previousTime = Timer()
EndFunction
Function TimerMove(moveAmount#)
value# = moveAmount# * rate#
EndFunction value#
Do
GoSub FPSControl
Sync()
Loop
FPSControl:
GoSub MouseLook
GoSub WASD
Return
WASD:
if GetRawKeyState( 87 ) = 1
MoveCameraLocalZ(1, spdPlay)
endif
if GetRawKeyState( 83 ) = 1
MoveCameraLocalZ( 1, -spdPlay )
endif
if GetRawKeyState( 65 ) = 1
MoveCameraLocalX( 1, -spdPlay )
endif
if GetRawKeyState( 68 ) = 1
MoveCameraLocalX( 1, spdPlay )
endif
Return
MouseLook:
Xpos#=GetRawMouseY()
Ypos#=GetRawMouseX()
DiffX#=XPos#-CenterX#
DiffY#=YPos#-CenterY#
Print(DiffX#)
Print(DiffY#)
//CamX=CamX-DiffX#
CamY=CamY+(DiffY#)
CamX=CamX+(DiffX#)
SetCameraRotation(1, CamX, CamY, CamZ)
SetRawMousePosition(CenterX#,CenterY#)
Return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment