Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK .NET / Checkkeys issue

Author
Message
tehuti2999
11
Years of Service
User Offline
Joined: 9th Nov 2012
Location: United States
Posted: 8th Feb 2013 22:28
can someone take a look at this and tell me why my checkkeys is not working? When I launch the object just reverts back to it's last position and won't move forward. Thank you I would appreciate it.[Imports DarkGDK
Imports DarkGDK.Camera

Module Prepare
Public oGameCore As GameCore

Public Sub Main()
'Starts DarkGDK
DarkGDK.Engine.InitializeGDK()

oGameCore = New GameCore()
oGameCore.Main()
End Sub
End Module

Public Class GameCore

Public Structure Point3d
Public X As Single
Public Y As Single
Public Z As Single
End Structure

Public LastPosition As New Point3d

Sub Main()


'Setup Display, Camera
DarkGDK.Display.SetDisplayMode(1200, 720, 32)
DarkGDK.Display.SetWindowLayout(0, 0, 0)
DarkGDK.Display.MaximizeWindow()
DarkGDK.Core.SyncOn()
DarkGDK.Core.SyncRate(0)
DarkGDK.Camera.DefaultCamera.AutoCamOn()
DarkGDK.Camera.DefaultCamera.BackdropOff()
DarkGDK.Core.DrawToBack()

DarkGDK.Camera.DefaultCamera.SetRange(0.1, 5000)

DarkGDK.Core.Print("Please wait, Loading model...")
DarkGDK.Core.Sync()
DarkGDK.Core.Sync()

DarkGDK.IO.File.SetCurrentDirectory("..\..\Media")
'sets up mouse to rotate camera
Dim fCameraAngleX As Single = 0.0F
Dim fCameraAngleY As Single = 0.0F
'------------------------------------------------------------------
Dim ter As New DarkGDK.Basic3D.Object3D("Terrain1.x")
Dim rec As New DarkGDK.Basic3D.Object3D("Recon.x")
Dim CameraDistance As Point3d



rec.Scale(2, 2, 2)
rec.YRotate(180)
ter.Scale(5000, 5000, 5000)
rec.SetCollisionToBoxes()
ter.SetCollisionToPolygons()
'this sets the position of Truck
CameraDistance.X = 0
CameraDistance.Y = -5
CameraDistance.Z = 10


DarkGDK.Camera.DefaultCamera.PositionCurrent(2, 10, -25)
rec.Position(DarkGDK.Camera.DefaultCamera.CurrentPositionX + CameraDistance.X, DarkGDK.Camera.DefaultCamera.CurrentPositionY + CameraDistance.Y, _
DarkGDK.Camera.DefaultCamera.CurrentPositionZ + CameraDistance.Z)

DarkGDK.IO.Mouse.Hide()

'Main Loop
While DarkGDK.Engine.LoopGDK()

DarkGDK.Core.ClearScreen()

rec.Scale(2, 2, 2)
rec.YRotate(180)

'this sets up collicion of truck and terrain
LastPosition.X = DarkGDK.Camera.DefaultCamera.CurrentPositionX
LastPosition.Y = DarkGDK.Camera.DefaultCamera.CurrentPositionY
LastPosition.Z = DarkGDK.Camera.DefaultCamera.CurrentPositionZ
rec.Position(DarkGDK.Camera.DefaultCamera.CurrentPositionX + CameraDistance.X, DarkGDK.Camera.DefaultCamera.CurrentPositionY + CameraDistance.Y, _
DarkGDK.Camera.DefaultCamera.CurrentPositionZ + CameraDistance.Z)
DarkGDK.Camera.DefaultCamera.ControlDefaultUsingArrowKeys(5, 5)

If rec.Collision(ter) = True Then
DarkGDK.Camera.DefaultCamera.PositionCurrent(LastPosition.X, LastPosition.Y, LastPosition.Z)
rec.Position(DarkGDK.Camera.DefaultCamera.CurrentPositionX + CameraDistance.X, DarkGDK.Camera.DefaultCamera.CurrentPositionY + CameraDistance.Y, _
DarkGDK.Camera.DefaultCamera.CurrentPositionZ + CameraDistance.Z)

End If
Checkkeys(rec)
'this rotate the camera with mouse
fCameraAngleX = DarkGDK.Core.WrapValue(fCameraAngleX + CSng(IO.Mouse.MoveY) * 0.4F)
fCameraAngleY = DarkGDK.Core.WrapValue(fCameraAngleY + CSng(IO.Mouse.MoveX) * 0.4F)
DarkGDK.Camera.DefaultCamera.CurrentAngleX = fCameraAngleX
DarkGDK.Camera.DefaultCamera.CurrentAngleY = fCameraAngleY
'--------------------------------------------------------------
DarkGDK.Core.Sync()
End While

End Sub

Public Sub Checkkeys(ByRef rec As DarkGDK.Basic3D.Object3D)

If DarkGDK.IO.Keyboard.State(IO.Keys.S) Then
rec.Move(5)
End If

If DarkGDK.IO.Keyboard.State(IO.Keys.W) Then
rec.Move(-1)
End If

If DarkGDK.IO.Keyboard.State(IO.Keys.A) Then
rec.MoveLeft(1)
End If

If DarkGDK.IO.Keyboard.State(IO.Keys.D) Then
rec.MoveRight(1)
End If
If DarkGDK.IO.Keyboard.State(IO.Keys.Q) Then
rec.MoveDown(1)
End If
If DarkGDK.IO.Keyboard.State(IO.Keys.E) Then
rec.MoveUp(1)
End If
End Sub
End Class
]

Login to post a reply

Server time is: 2024-04-20 11:36:37
Your offset time is: 2024-04-20 11:36:37