;www.boolean.name ;Nex Graphics3D 1024,768,32,2 SetBuffer (BackBuffer ()) SeedRnd (MilliSecs ()) Global t#,dt# Global CameraMaxAngle% = 80,gravity# = 20.0 Global shovelRes%, swordRes%, axeRes% Global shovelID% = 1, swordID% = 2, axeID% = 3 Global imageRes% = CreateImage (512,512,4) Global ground%,camera% Global player%,player_x#,player_y#,player_z#,player_speed# = 7.0, isGround% = 0 Global ItemInHand%,itemPos% Global pickDistance# = 2.0 ;дистанция на которой подымается шмотка Global brown_brush% = CreateBrush (128,64,0), silver_brush% = CreateBrush (128,128,128) Global inventory_mas% [9] ; Global selectSlot% = 0,oldSelectSlot%=-1 Type TDrop Field ent%,mesh% Field sort% Field x#,y#,z# Field isDelete% End Type Type TItem Field ent% Field positionNum% Field sort% End Type CreateResource () CreatePlayer () For i%=1 To 20 CreateDropItem (Rand (1,3),Rnd (-20,20),Rnd (-20,20)) Next While Not KeyHit (1) UpdateDelta () UpdateCamera () UpdatePlayer () UpdateDropItem () UpdateInventory () UpdateWorld () RenderWorld () DrawInventory () Flip Wend End ;==================================================== Function CreateItem (num%) i.TItem = New TItem i\positionNum = num Select inventory_mas [i\positionNum] Case 1 i\sort = inventory_mas [i\positionNum] i\ent = CopyEntity (shovelRes) Case 2 i\sort = inventory_mas [i\positionNum] i\ent = CopyEntity (swordRes) Case 3 i\sort = inventory_mas [i\positionNum] i\ent = CopyEntity (axeRes) End Select HideEntity i\ent End Function Function GetItem% (positionNum%) For i.TItem = Each TItem If i\positionNum = positionNum Then Return i\ent EndIf Next End Function ;==================================================== Function CreateDropItem (sort%,x#,z#) d.TDrop = New TDrop d\x = x :d\y = 1.5:d\z = z d\ent = CreatePivot () Select sort Case 1 :d\mesh = CopyEntity (shovelRes) :d\sort = shovelID ;лопата Case 2 :d\mesh = CopyEntity (swordRes) :d\sort = swordID ;меч Case 3 :d\mesh = CopyEntity (axeRes) :d\sort = axeID ;топор End Select PositionEntity d\ent,d\x,d\y,d\z PositionEntity d\mesh,d\x,d\y,d\z End Function Function UpdateDropItem () For d.TDrop = Each TDrop If d\isDelete = True Then FreeEntity d\mesh FreeEntity d\ent Delete d Else d\x = EntityX (d\ent) d\y = EntityY (d\ent) d\z = EntityZ (d\ent) TurnEntity d\mesh, 0, 200.0*dt, 0 TranslateEntity d\mesh,0,Sin (EntityYaw (d\mesh))*0.015,0 If EntityDistance (d\ent, player) <= pickDistance Then slot% = CheckInventory% () If slot = -1 Then Return inventory_mas [slot] = d\sort CreateItem (slot) d\isDelete = True EndIf EndIf Next End Function ;==================================================== Function UpdateInventory () If oldSelectSlot <> selectSlot Then If ItemInHand <> 0 Then HideEntity ItemInHand If inventory_mas [selectSlot] >0 Then ItemInHand = GetItem (selectSlot) ShowEntity ItemInHand EndIf If ItemInHand <>0 Then oldSelectSlot = selectSlot EndIf End Function Function DrawInventory () Local offset_x%=250,offset_y%=620 For i%=0 To 9 DrawImage imageRes,(offset_x-25)+(i*50),offset_y+70,0 If inventory_mas [i] >0 Then DrawImage imageRes,offset_x+i*50,offset_y,inventory_mas [i] Next ;------------------------- Color 255,0,0 Rect (offset_x-25)+(selectSlot*50),offset_y+70,50,5 Rect (offset_x-25)+(selectSlot*50),offset_y+70,5,50 Rect (offset_x-25)+(selectSlot*50),offset_y+118,50,5 Rect (offset_x-25)+(selectSlot*50)+48,offset_y+70,5,53 Color 255,255,255 End Function Function CheckInventory% () For i%=0 To 9 If inventory_mas [i] = 0 Then Return i Next Return -1 End Function ;==================================================== ;==================================================== ;======================Не нужное======================= ;==================================================== ;==================================================== Function CreateResource () SetBuffer (ImageBuffer (imageRes,0)) Color 150,150,150 Rect 0,0,120,10 Rect 0,120,120,10 Rect 0,0,10,120 Rect 120,0,10,130 Color 255,255,255 SetBuffer (BackBuffer ()) light = CreateLight () RotateEntity light,65,0,0 AmbientLight 255,255,255 camera = CreateCamera () PositionEntity camera,0,0,-10 itemPos = CreatePivot () MoveEntity itemPos,1.2,0,-8.5 EntityParent itemPos, camera shovelRes = CreateMesh () t = CreateCylinder () ScaleMesh t,0.15,2.0,0.15 PaintMesh t, brown_brush AddMesh t,shovelRes FreeEntity t t = CreateCube () PaintMesh t, silver_brush ScaleMesh t,0.8,0.8,0.1 PositionMesh t,0.0,-2.0,0.0 AddMesh t,shovelRes FreeEntity t ScaleMesh shovelRes,0.4,0.4,0.4 RotateMesh shovelRes,0,0,180 RenderWorld () CopyRect 490,140,80,300,0,0,BackBuffer (),ImageBuffer (imageRes,1) HideEntity shovelRes swordRes = CreateMesh () t = CreateCone () PaintMesh t,silver_brush ScaleMesh t, 0.3,0.5,0.1 PositionMesh t,0,2.5,0 AddMesh t, swordRes FreeEntity t t = CreateCube () PaintMesh t,silver_brush ScaleMesh t,0.3,2.0,0.1 AddMesh t, swordRes FreeEntity t t = CreateCube () PaintMesh t,brown_brush ScaleMesh t,1.0,0.2,0.2 PositionMesh t,0,-1.8,0 AddMesh t, swordRes FreeEntity t t = CreateCylinder () PaintMesh t,silver_brush ScaleMesh t,0.15,0.6,0.15 PositionMesh t,0.0,-2.5,0.0 AddMesh t, swordRes FreeEntity t t = CreateSphere () PaintMesh t,brown_brush ScaleMesh t,0.3,0.3,0.3 PositionMesh t,0,-3.0,0 AddMesh t, swordRes FreeEntity t ScaleMesh swordRes,0.4,0.4,0.4 RenderWorld () CopyRect 490,100,40,350,0,0,BackBuffer (),ImageBuffer (imageRes,2) HideEntity swordRes axeRes = CreateMesh () t = CreateCylinder () PaintMesh t,brown_brush ScaleMesh t,0.15,2.0,0.15 AddMesh t, axeRes FreeEntity t t = CreateCube () PaintMesh t,silver_brush ScaleMesh t,0.25,0.25,0.25 PositionMesh t,0,1.6,0 AddMesh t, axeRes FreeEntity t t = CreateCone () PaintMesh t,silver_brush RotateMesh t,0,0,-90 ScaleMesh t,0.7,0.7,0.1 PositionMesh t,-0.45,1.6,0 AddMesh t, axeRes FreeEntity t ScaleMesh axeRes,0.4,0.4,0.4 RenderWorld () CopyRect 485,130,40,300,0,0,BackBuffer (),ImageBuffer (imageRes,3) HideEntity axeRes TFormFilter False ScaleImage imageRes,0.4,0.4 CameraRange camera,0.1,1000 CameraClsColor camera,0,174,239 CameraFogMode camera,True CameraFogColor camera,0,174,239 CameraFogRange camera,5,50.0 PositionEntity camera,0,5,0 ground = CreatePlane () tempTex = CreateTexture (256,256) SetBuffer (TextureBuffer (tempTex)) Color 79,166,36 Rect (0,0,256,256) For i%=0 To 500 Color Rand (35,155),173,33 size% = 8 Rect (Rand (0,256),Rand (0,256),size,size) Next Color 255,255,255 SetBuffer (BackBuffer ()) ScaleTexture tempTex,4,4 EntityTexture ground,tempTex FreeTexture tempTex End Function Function UpdateCamera () msx# = MouseXSpeed ()*0.5 msy# = MouseYSpeed ()*0.5 MoveMouse (GraphicsWidth ()/2.0, GraphicsHeight ()/2.0) pitch# = EntityPitch (camera) +msy If pitch > CameraMaxAngle Then pitch = CameraMaxAngle If pitch <-CameraMaxAngle Then pitch = -CameraMaxAngle RotateEntity camera,pitch,EntityYaw (camera) -msx,0 End Function ;==================================================== Function CreatePlayer () player = CreatePivot () PositionEntity player,0,1.0,0 End Function Function UpdatePlayer () player_x = EntityX (player) player_y = EntityY (player) player_z = EntityZ (player) If player_y <=1.0 Then isGround = True gravity = 20.0 PositionEntity player,player_x,1.0,player_z Else isGround = False EndIf If KeyHit (57) Then If (isGround = True) Then TranslateEntity player,0,gravity*dt,0 EndIf If isGround = False Then gravity = gravity -0.4 TranslateEntity player,0,gravity*dt,0 EndIf If KeyDown (17) Then MoveEntity player,0,0,player_speed*dt If KeyDown (31) Then MoveEntity player,0,0,-player_speed*dt If KeyDown (30) Then MoveEntity player,-player_speed*dt,0,0 If KeyDown (32) Then MoveEntity player,player_speed*dt,0,0 mzs% = MouseZSpeed () If mzs <>0 Then selectSlot = selectSlot +mzs If selectSlot <0 Then selectSlot = 0 If selectSlot >9 Then selectSlot = 9 RotateEntity player,0,EntityYaw (camera),0 PositionEntity camera,EntityX (player),EntityY (player)+2.0,EntityZ (player) If ItemInHand <>0 Then RotateEntity ItemInHand,0,EntityYaw (camera)-90,EntityPitch (camera) PositionEntity ItemInHand,EntityX (itemPos,1),EntityY (itemPos,1),EntityZ (itemPos,1) EndIf End Function ;==================================================== Function UpdateDelta () If T=0 Then T=MilliSecs() dt=(MilliSecs()-T)/1000 T=MilliSecs() End Function