Graphics3D 640,480
SeedRnd MilliSecs()
PlayerPhysicsPivot = CreatePivot()
Player = CreateSphere(6)
; Lights and Camera
Camera = CreateCamera()
PositionEntity camera,0,20,-20
TurnEntity camera,30,0,0
Light = CreateLight(2)
PositionEntity Light,1000,1000,0
; Create the Ground
Ground = CreatePlane()
GroundTex = CreateCheck()
ScaleTexture GroundTex,10,10
EntityTexture Ground,GroundTex
EntityAlpha Ground,.6
Mirror = CreateMirror()
PositionEntity Mirror,0,-.1,0
; Position the player start point
PositionEntity Player,0,40,0
; amount of force to apply to entity
Force# = 0.02
Repeat
; Player input force
If KeyDown(200) Then TranslateEntity PlayerPhysicsPivot,0,0,Force#
If KeyDown(208) Then TranslateEntity PlayerPhysicsPivot,0,0,-Force#
If KeyDown(203) Then TranslateEntity PlayerPhysicsPivot,-Force#,0,0
If KeyDown(205) Then TranslateEntity PlayerPhysicsPivot,Force#,0,0
; Jump
If KeyHit(57) Then TranslateEntity PlayerPhysicsPivot,0,1,0
; Gravity Force
TranslateEntity PlayerPhysicsPivot,0,-.01,0
; Drag, the 0.1 is how much drag, the higher the figure the more drag (from 0 to 1)
drag# = 0.1
TranslateEntity PlayerPhysicsPivot,-EntityX(PlayerPhysicsPivot)*drag,0,-EntityZ(PlayerPhysicsPivot)*drag
TranslateEntity Player,EntityX(PlayerPhysicsPivot),EntityY(PlayerPhysicsPivot),EntityZ(PlayerPhysicsPivot)
; Check for the ground and bounce
If EntityY(Player)<0.5
; How bouncy the player is, 0 being not bouncy at all, 1 being 100% bouncy
Bounce# = 0.5
TranslateEntity Player,0,0.5 - EntityY(player),0
TranslateEntity PlayerPhysicsPivot,0,-EntityY(PlayerPhysicsPivot)*(1+bounce),0
EndIf
RenderWorld
Flip
Until KeyHit(1)
Function CreateCheck()
i = CreateImage(256,256)
t = CreateTexture(256,256)
SetBuffer ImageBuffer(i)
Color 0,0,255
Rect 0,0,128,128
Rect 128,128,128,128
Color 0,100,200
Rect 128,0,128,128
Rect 0,128,128,128
CopyRect 0,0,256,256,0,0,ImageBuffer(i),TextureBuffer(t)
FreeImage i
Return t
End Function