- Joined
- Jul 25, 2006
- Messages
- 26
- Reaction score
- 0
Im writting a Program in KPL v2 also known as Phrogram and Im having some troubles with it. I was hoping someone here has some experience with this and can tell me where my program is not working properly.
Its basically a 3D program in which you fly a ship through 20 targets... I have no errors in the porgram and when i run it, it loads the targets and the map correctly but I cannot move the ship. Please Help.
Its basically a 3D program in which you fly a ship through 20 targets... I have no errors in the porgram and when i run it, it loads the targets and the map correctly but I cannot move the ship. Please Help.
Code:
Program ShipDemo
Define ship As Model3D
Define targetCount As Int = 2
Define targets As Model3D[targetCount]
Method Main()
HideToolbar()
SwitchTo3D()
Define cam As Camera = CreateCamera( 0, 10, 10 )
Define sky As Skybox3D = LoadSkybox( "Skybox7.x" )
//sky.Location = cam.Location
Sky.Scale(.1,.1,.1)
Define fps As TextLabel
fps.Width = ScreenWidth()
fps.Height = ScreenHeight()
fps.MoveTo( 1, 0 )
fps.Color = Colors.AliceBlue
fps.SetFont( "Verdana", 12 )
fps.SetFontStyle( True, False, False )
Define frameTime As Decimal = 0.0
Define ship As Model3D
ship.LoadMesh ( "Fighter1.x" )
ship.MoveTo (0,0,0)
ship.Scale (.08, .08, .08)
ship.AddCategory ( "Pointer")
ship.EnableCollisions( "target" )
Define moveAmount As Decimal = 5 * frameTime
If IsKeyDown( Escape ) Then
Return
End If
If IsKeyDown( Left ) Then
ship.TurnLeft( moveAmount )
End If
If IsKeyDown( Right ) Then
ship.TurnRight( moveAmount )
End If
If IsKeyDown( Up ) Then
Ship.TiltUP( moveAmount )
End If
If IsKeyDown( Down ) Then
Ship.TiltDown( moveAmount )
End If
Ship.Forward( MoveAmount * 10)
RenderFrame()
//Plays Sandstorm-DaRude during the Demo.
PlaySound ("Sandstorm.wav")
Define I As Int
For I = 1 To targetCount
fps.Text = "Loading target " + I + " of " + targetCount
RenderFrame()
targets[i] = LoadModel("Sphere.x")
targets[i].Scale( 3, 3, 3 )
targets[i].AddCategory( "target" )
targets[i].MoveTo( Random( -20, 20 ), Random( -20, 20 ), Random( -50, 50 ) )
Next
Define target As Model3D
Define targetPoint As Point3D = target.Location
Define elapsed As Decimal
Define lastCamChange As Decimal
Define follow As Bool = False
While Not IsKeyDown( Escape )
Define startTime As Decimal = TickCount()
sky.Location = cam.Location
For I = 1 To TargetCount
Targets[i].ScrollTexture( frameTime * 0.1, frameTime * 0.1 )
Next
If IsKeyDown( "F" ) And TickCount() - lastCamChange > 250 Then
Follow = Not Follow
lastCamChange = TickCount()
End If
If Follow Then
cam.Follow( ship, 6, 2 )
Else
If Not cam.IsFacing( ship.Location, DegreesToRadians(1) ) Then
cam.TurnToward( ship.Location, frameTime * 3.75 )
End If
End If
ship.TurnToward( targetPoint, frameTime * 3 )
If ship.IsFacing( targetPoint, DegreesToRadians(5) ) Then
ship.MoveToward( targetPoint, frameTime * 4.5 )
End If
If ship.HasCollision( Target ) Or IsKeyDown( Space ) Then
targetPoint = CreatePoint3D( Random( -20, 20 ), Random( -20, 20 ), Random( -50, 50 ) )
target.Location = targetPoint
targetPoint = target.Location
elapsed = 0
End If
RenderFrame()
targetPoint = target.Location
frameTime = Math.Min( 0.01, (TickCount() - startTime) * 0.001 )
elapsed = elapsed + frameTime
Define displayText As String = "FPS: " + FramesPerSecond + "\r\nTarget at " + targetPoint + "\r\nship at " + ship.Location
displayText = displayText + "\r\nCAM: " + cam.Location
If Not Follow Then
displayText = displayText + "\r\nPress (F) for Follow Mode"
Else
displayText = displayText + "\r\nPress (F) to return to Track Mode"
End If
fps.Text = displayText
End While
End Method
End Program

