Global gameFPS = 30
Global framePeriod = 1000 / gameFPS
Global frameTime = MilliSecs () - framePeriod
Global frameTween# = 1.0
gx=1024:gy=768
px=gx/2:py=gy/2
Graphics3D gx,gy,32,0
SetBuffer BackBuffer()
HidePointer
;--------------------Устоновка шрифта
fnt = LoadFont ("Vernada",22)
SetFont fnt
;--------------------Создаем тип игрока
Type player
Field ent,ent1
End Type
;--------------------
Const PL = 1
Const ZEM = 2
Const MHOME = 3
;-------------------
Collisions PL,ZEM,2,3
Collisions PL,MHOME,2,3
;-------------------
Global cam
Global cu = CreateSphere (8)
HideEntity cu
Global home
Global home_a
;--------------------
et=MilliSecs()
dt=et-st
game()
While Not KeyHit (1)
Repeat
frameElapsed = MilliSecs () - frameTime
Until frameElapsed
frameTicks = frameElapsed / framePeriod
frameTween# = Float (frameElapsed Mod framePeriod) / Float (framePeriod)
For frameLimit = 1 To frameTicks
If frameLimit = frameTicks Then CaptureWorld
frameTime = frameTime + framePeriod
update_game()
Lcam()
Next
UpdateWorld
RenderWorld frameTween
Oval px,py,5,5,0
Text 10,10,"Tris: "+TrisRendered()
Text 10,40,"FPS: "+fps2
For p.player = Each player
Text 150,10,"X: "+EntityX(p\ent)
Text 150,40,"Y: "+EntityY(p\ent)
Text 150,70,"Z: "+EntityZ(p\ent)
Next
;fps
fps=fps+1
If fps_t<MilliSecs()
fps2=fps
fps_t=1000+MilliSecs()
fps=0
EndIf
Flip 0
Wend
End
Function game()
p.player = New player
p\ent = CopyEntity (cu)
PositionEntity p\ent,-25,20,-12
EntityAlpha p\ent,0
EntityType p\ent,PL
p\ent1 = CreatePivot (p\ent)
PositionEntity p\ent1,0,3,0
;---------------------------------------
cam = CreateCamera (p\ent1)
CameraClsColor cam,80,110,120
CameraFogMode cam,1
CameraFogColor cam,80,110,120
CameraFogRange cam,20,50
CameraRange cam,1,252
EntityType cam,MCAM
lit = CreateLight ()
AmbientLight 200,200,200
ter = LoadTerrain ("DATA\Terrain\ter.bmp")
ScaleEntity ter,15,50,15
PositionEntity ter,-60,0,-50
t_t = LoadTexture("DATA\Textures\MossyGround.bmp")
ScaleTexture t_t,1,1
EntityTexture ter,t_t
EntityType ter,ZEM
;-----------------------------------------------------
home = LoadAnimMesh ("DATA\Models\home.b3d")
ScaleEntity home,.7,.7,.7
PositionEntity home,-13,7,7
EntityType home,MHOME
End Function
Function update_game()
If user_time=0 user_time=MilliSecs()
new_time=MilliSecs()
delta_t=new_time-user_time
user_time=new_time
For p.player = Each player
If KeyDown (17) Then MoveEntity p\ent,0,0,.3
If KeyDown (31) Then MoveEntity p\ent,0,0,-.3
If KeyDown (30) Then MoveEntity p\ent,-.3,0,0
If KeyDown (32) Then MoveEntity p\ent,.3,0,0
jumpvel#=.3
gravity#=.01
If jumping=0
If KeyDown(57) Then yvel#=jumpvel# jumping=1
EndIf
If jumping=1
yvel#=yvel#-gravity#
by#=by#+yvel#
EndIf
If by#<1 Then by#=1 yvel#=0 jumping=0
MoveEntity p\ent,EntityX(p\ent)#,EntityY(p\ent)#,EntityZ(p\ent)#
If KeyDown(16) And AnimSeq=0 Then Animate home,3,0.03,0,0
TranslateEntity p\ent,0,-.5,0
Next
End Function
Function Lcam()
u#=70
For p.player = Each player
TurnEntity cam,MouseYSpeed()*0.2,0,0
TurnEntity p\ent,0,-MouseXSpeed()*0.2,0
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
If Abs(EntityPitch#(cam))>u# RotateEntity cam,u#*Sgn(EntityPitch#(cam)),0,0
End Function