' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  030  :  Fighter demo.
'   Historique  :
'     29/03/09  19:16    TMyke
'
' ------------------------------------------------------------
' Includes libraries
#include "N3xtD.bi"

' Dimes
Dim app As any Ptr
Dim Quit As Integer


'----------------------------------------------------------
' open n3xt-D screen
app = _CreateGraphics3D(800,600)
If app=NULL Then
  End
End If


'-----------------------------------------
' Create light And set position
Dim light as LightNode = _CreateLight(&hffffffff, 400)
_PositionNode(light, 0,150,10)



'----------------------------------------
' Load 3D objects 
  Dim obj1 as Mesh = _LoadMesh("media/land.x")
  Dim obj2 as Mesh = _LoadMesh("media/su47.x")
  _RotateMesh(obj2, 0,90,0)
  _ScaleMesh(obj2, 0.02,0.02,0.02)


'-----------------------------------------
' Create plane
Dim plane as EntityNode = _CreateEntityNode(obj1)


'-----------------------------------------
' Create fighter
Dim fighter as EntityNode =  _CreateEntityNode(obj2)
_PositionNode(fighter, 0,10,0)


'-----------------------------------------
' add a little arm, no ?
Dim cubemesh as Mesh = _CreateCubeMesh(1.0)
Dim cube as EntityNode = _CreateEntityNode(cubemesh, 0,-1.3,0, fighter)
 _ScaleNode(cube, 0.75, 0.75, 2)



'-----------------------------------------
' Create first  camera
Dim cam As CameraNode = _CreateCamera()
_PositionNode(cam, 0,17,-18)

'-----------------------------------
' Load font png
_LoadFont("media/courriernew.png")
Dim font as IGUIFont = _GetFont()



' ---------------------------------------
'           Main loop
' ---------------------------------------
While Quit=0
 

' If Escape Key, Exit	
  If _GetKeyDown(KEY_ESCAPE) then
    Quit=1
  EndIf
  
       _Movenode(fighter, 0,0,0.2)
        
       ' control fighter     
       If _GetKeyDown(KEY_ARROW_UP) then 
            _TurnNode(fighter, 2,0,0, RT_QUATERNION )
       EndIf 
       If _GetKeyDown(KEY_ARROW_DOWN)  then 
            _TurnNode(fighter, -2,0,0, RT_QUATERNION )
       EndIf 
       If _GetKeyDown(KEY_Key_B)  then 
            _TurnNode(fighter, 0,2,0, RT_QUATERNION )
       EndIf 
       If _GetKeyDown(KEY_Key_V) then  
            _TurnNode(fighter, 0,-2,0, RT_QUATERNION )
       EndIf 

       If _GetKeyDown(KEY_ARROW_LEFT ) then
            _TurnNode(fighter, 0,0, 2, RT_QUATERNION )
       EndIf 
       If _GetKeyDown(KEY_ARROW_RIGHT)  then 
            _TurnNode(fighter, 0,0,-2, RT_QUATERNION )
       EndIf 

 
   _PointNode( cam, fighter)


  	' ---------------
  	'      Render
  	' ---------------
  _BeginScene()
    _DrawScene()
    _DrawText(font, "DirKey and V/B for move fighter",  10,10,0,0, &hff00ffff)
  _EndScene()


Wend 
' end
_FreeEngine()
