'*********************************************************** 
'*          DEA - DirectX Engine Ambient - By Boris        *
'*  Ver  1.2  modified by JohnK                            *
'*       http://www.holyguard.net http://www.rapidq.it     *
'*                                                         * 
'*       Source file compiled with Rapidq by William Yu    *
'*          Created with Hellionor IDE for RapidQ          *
'*                                                         *
'*           3d models created with DeleD Engine           *
'*                  http://delgine.com                     *
'*                                                         *
'***********************************************************
$TYPECHECK ON
$optimize on
'-----------starting declarations-----------------

DECLARE SUB DXInitialize(Sender AS QDXScreen)
DECLARE SUB DXInitializeSurface(Sender AS QDXScreen)
DECLARE SUB TimerExpired
DECLARE SUB TimerAzioniSub
DECLARE SUB KeyDown(TheKey AS WORD, Shift AS INTEGER)
DECLARE SUB mouse
DECLARE SUB Make_Sky_Floor_Clouds
DECLARE SUB play_tank_engine_sound
DECLARE SUB stop_tank_engine_sound
DECLARE SUB RenderLoop

$INCLUDE <Rapidq2.inc>
$INCLUDE <RapidQ_D3D.inc>

'consts
DEFINT ScreenRes_x = 640
DEFINT ScreenRes_y = 480
DEFINT Max_fireballs = 2        'balls in explosion
DEFINT trees_number = 30        ' number of trees
DEFINT Fighter_Num = 10         ' numero di nuvole
DEFINT Fini = False
DEFSNG FireBall_Scale 
DEFSNG FireBall_Alpha
DEFINT TheBadGuy
DEFSNG TheBadGuy_x
DEFSNG TheBadGuy_z

DIM indice_oggetto as integer

   DIM Light AS QD3DLight, Ambient AS QD3DLight
   DIM Light1 AS QD3DLight
   DIM LightFrame AS QD3DFrame
   
   DIM MeshFrame2 AS QD3DFrame
   DIM MeshFrame5 AS QD3DFrame
   DIM MeshFrame6 AS QD3DFrame
   DIM MeshFramesky AS QD3DFrame
   DIM MeshFrameTerrain AS QD3DFrame

   DIM MeshBuilder2 AS QD3DMeshBuilder
   DIM MeshBuilder5 AS QD3DMeshBuilder
   DIM MeshBuilder6 AS QD3DMeshBuilder
   DIM MeshBuilderSky AS QD3DMeshBuilder
   DIM MeshBuilderTerrain AS QD3DMeshBuilder

'-----  explosion -------
'    DIM FireBall  AS QD3DPrimitive

    DIM FireBall  AS QD3DCloneMesh
    WITH FireBall
        .CloneNum = Max_fireballs
        .File = "sphere.x"
    END WITH

'-------trees initialization--------
    DIM MyTrees AS QD3DCloneMesh
    WITH MyTrees
        .CloneNum = trees_number
        .File = "albero2.x"
        .Range.Top = -500
        .Range.left = -500
        .Range.Bottom = 500
        .Range.Right = 500
        .RandPos = True      'randomize locations
    END WITH
    DIM Shadow_trees AS QD3DVisual


'-------Fighter jets initialization--------
    DIM Fighters AS QD3DCloneMesh
    WITH Fighters
        .CloneNum = Fighter_Num
        .File = "astrofighter.x"
        .Range.Top = -500
        .Range.left = -500
        .Range.Bottom = 500
        .Range.Right = 500
        .RandPos = True      'randomize locations
    END WITH

'-------  HUD "heads up display"  --------
DIM HUD AS QBITMAP
WITH HUD
    .LoadFromFile("HUD.bmp")
    .Transparent = True
    .TransparentColor = 0
END WITH
DEFINT HUD_x = ScreenRes_x\2 - HUD.Width\2
DEFINT HUD_y = ScreenRes_y\2 - HUD.Height\2
DEFINT HUD_On = True
'------------------------------------

    DIM Texture AS QD3DTexture
    DIM Shadow AS QD3DVisual
    DIM wrap AS QD3DWRAP
    DIM wrapType AS LONG:      wrapType = D3DRMWRAP_SPHERE

'-- mp3 player --------------------------------------------
    DIM ret AS Long
    DIM mp3file AS String
    DIM Play AS String
    DIM Cmd AS String

DECLARE Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _ 
    (ByVal lpstrCommand As String, _
    ByVal lpstrReturnString As String, _
    ByVal uReturnLength As Long, _ 
    ByVal hwndCallback As Long) As Long
        mp3file = command$(1)
        Cmd = "Open " & chr$(34) & mp3file & chr$(34) & " Alias Rapid-MP3"
        Play = "Play rapid-mp3"

'--------------- movement params ---------------------------------

    DIM The_Speed   AS SINGLE : The_Speed = 10  'speed of translation motion
    DIM Cam_Orient  AS Q3DVector    'fix bug
    DIM Cam_Pos     AS Q3DVector :Cam_Pos.y=10
    DIM Omega       AS SINGLE: Omega = -3.1416'/2 'for camera rotation = pi/2 or 90 degrees

'--------------- tank initial parameters -------------------------
    DIM Tank_Orient  AS Q3DVector
        Tank_Orient.dvx=-1
    DIM Tank_Pos  AS Q3DVector 
        Tank_Pos.x=100: Tank_Pos.y=-0.5: Tank_Pos.z=100
    DIM TankX_Now AS SINGLE
    DIM TankY_Now AS SINGLE
    Dim TankSim_x as integer
    Dim TankSim_y as integer
    Dim Tank_Navigation as integer
'-----------------------------------------------------------------
    DEFINT SUN_POS_Y =500  'as Integer
    DEFINT SUN_POS_Z =1000 'as Integer
    
    Dim Mid_x as integer
    Dim Mid_y as integer
    Dim Fire as integer
    
    Mid_X = (ScreenRes_x/2)
    Mid_Y = (ScreenRes_y/2)
    
    DIM MouseX_Now AS SINGLE
    DIM MouseY_Now AS SINGLE
    
    Dim Mousesim_x as integer
    Dim Mousesim_y as integer


    DIM Mx AS INTEGER 
    DIM My AS INTEGER 


DIM TheTimer AS QTimer
   TheTimer.Enabled = 0
   TheTimer.Interval = 1            'interval > 0 !!
   TheTimer.OnTimer = TimerExpired

'  DIM DXTimer AS QDXTimer          'doesn't share globals
'     DXTimer.Enabled = 0
'     DXTimer.Interval = 10
'     DXTimer.OnTimer = RenderLoop '



CREATE Form AS QForm
    Center
    BorderStyle = 0
    OnKeyDown = KeyDown
    ClientWidth = ScreenRes_x
    ClientHeight = ScreenRes_y

     CREATE tank_engine_Sound AS Qdxsound
'          Looped = False
          fileName = "sounds\motor.wav"
'          volume = 0
'          pan = 0
          Stop
'          volume = 100
'          Looped = True
      END CREATE

    CREATE DXScreen AS QDXScreen
        Cursor = crNone
        Width = ScreenRes_x
        Height = ScreenRes_y
        bitCount = 24
        use3D = 1
        useHardware = 1
        FullScreen = 1
        OnInitialize = DXInitialize
        OnInitializeSurface = DXInitializeSurface
        OnKeyDown = KeyDown
        OnMouseMove = mouse
    END CREATE
END CREATE



SUB KeyDown(TheKey AS WORD, Shift AS INTEGER)
    
  SELECT CASE TheKey
    CASE = 32  ' toggle HUD
        IF HUD_On THEN HUD_On = False ELSE HUD_On = True
    
    CASE = 81  ' Avanti continuo
    ' Navigation = 1
    
    'CASE = 65  ' indietro continuo
    ' Navigation = -1
    
    CASE = 33  ' Alto
        Cam_Pos.y = (Cam_Pos.y + 1)
    
    CASE = 34  ' Basso
        Cam_Pos.y = (Cam_Pos.y - 1)
    
    CASE = 40  ' Indietro
        Cam_Pos.y = Cam_Pos.y - (Cam_Orient.dvy* The_Speed/2)
        Cam_Pos.x = Cam_Pos.x - (Cam_Orient.dvx* The_Speed/2)
        Cam_Pos.z = Cam_Pos.z - (Cam_Orient.dvz* The_Speed/2)
    
    CASE = 39  ' Destra
        Mousesim_x=Mousesim_x+10
        MouseX_Now = Omega * (Mousesim_x - Mid_X)/ Mid_X
        Cam_Orient.dvx = COS(MouseX_Now)
        Cam_Orient.dvz = SIN(MouseX_Now)
    
    CASE = 38  ' Avanti
        Cam_Pos.x = Cam_Pos.x + (Cam_Orient.dvx* The_Speed/1)
        Cam_Pos.z = Cam_Pos.z + (Cam_Orient.dvz* The_Speed/1)
        Cam_Pos.y = Cam_Pos.y + (Cam_Orient.dvy* The_Speed/1)
    
    CASE = 37  ' Sinistra
        Mousesim_x=Mousesim_x-10
        MouseX_Now = Omega * (Mousesim_x - Mid_X)/ Mid_X
        Cam_Orient.dvx = COS(MouseX_Now)
        Cam_Orient.dvz = SIN(MouseX_Now)
    
    CASE = 27  ' ESC
        Fini= True
    
    '---- tank(object) movement------- 
     CASE = 87'w key avanti
        Tank_Pos.x = Tank_Pos.x + (Tank_Orient.dvx* The_Speed/2)
        Tank_Pos.z = Tank_Pos.z + (Tank_Orient.dvz* The_Speed/2)
        Tank_Pos.y = Tank_Pos.y + (Tank_Orient.dvy* The_Speed/2)
    
    CASE = 65'a key sinistra
        Tanksim_x=Tanksim_x-10
        TankX_Now = Omega * (Tanksim_x - Mid_X)/ Mid_X
        Tank_Orient.dvx = COS(TankX_Now)
        Tank_Orient.dvz = SIN(TankX_Now)
    
    CASE = 83's key destra
        Tanksim_x=Tanksim_x+10
        TankX_Now = Omega * (Tanksim_x - Mid_X)/ Mid_X
        Tank_Orient.dvx = COS(TankX_Now)
        Tank_Orient.dvz = SIN(TankX_Now)
    
    CASE = 90'z key indietro
        Tank_Pos.y = Tank_Pos.y - (Tank_Orient.dvy* The_Speed/2)
        Tank_Pos.x = Tank_Pos.x - (Tank_Orient.dvx* The_Speed/2)
        Tank_Pos.z = Tank_Pos.z - (Tank_Orient.dvz* The_Speed/2)
    

  END SELECT

    '********** tank auto movement *********
    
'     select case Tank_Navigation
'         CASE = 1
'             Tank_Pos.x = Tank_Pos.x + (Tank_Orient.dvx* The_Speed/2)
'             Tank_Pos.z = Tank_Pos.z + (Tank_Orient.dvz* The_Speed/2)
'             Tank_Pos.y = Tank_Pos.y + (Tank_Orient.dvy* The_Speed/2)
'         case=-1
'             Tank_Pos.y = Tank_Pos.y - (Tank_Orient.dvy* The_Speed/2)
'             Tank_Pos.x = Tank_Pos.x - (Tank_Orient.dvx* The_Speed/2)
'             Tank_Pos.z = Tank_Pos.z - (Tank_Orient.dvz* The_Speed/2)
'         case=0
'             Tank_Pos.y = Tank_Pos.y 
'             Tank_Pos.x = Tank_Pos.x
'             Tank_Pos.z = Tank_Pos.z
'     end select
'     
	MeshFrame5.SetPosition(Tank_Pos.x, Tank_Pos.y, Tank_Pos.z)
    MeshFrame5.SetOrientation(Tank_Orient.dvx, .001, Tank_Orient.dvz,Tank_Orient.x, 1000, Tank_Orient.z)
END SUB




SUB DXInitialize(Sender AS QDXScreen)
    DXScreen.SetTextureQuality = D3DRMTEXTURE_MIPNEAREST

    'mp3file="storm.mp3" 
    ' mp3file="sounds/edgen.mp3"
    '    Cmd = "Open "& chr$(34) & mp3file & chr$(34) & " Alias Rapid-MP3"
    '    ret = mciSendString(Cmd, 0, 0, 0)
    '    ret = mciSendString(Play, 0, 0, 0)

    DXScreen.CreateFrame(MeshFrame2)
    DXScreen.CreateFrame(MeshFrame5)
    DXScreen.CreateFrame(MeshFrame6)
    DXScreen.CreateFrame(LightFrame)
    DXScreen.CreateMeshBuilder(MeshBuilder2)
    DXScreen.CreateMeshBuilder(MeshBuilder5)
    DXScreen.CreateMeshBuilder(MeshBuilder6)
    
    DXScreen.CreateFrame(MeshFrameSky)
    DXScreen.CreateMeshBuilder(MeshBuildersky)
    DXScreen.CreateFrame(MeshFrameTerrain)
    DXScreen.CreateMeshBuilder(MeshBuilderTerrain)

    MyTrees.Init(DXScreen)
    MyTrees.Mesh.Scale(.2,.2,.2)
    MyTrees.RandScale = True
    
    Fighters.Init(DXScreen)
    Fighters.Mesh.Scale(.1,.1,.1)
    for indice_oggetto = 1 to Fighter_Num
        Fighters.Frame(indice_oggetto).SetRotation(0,.1, 0,90)
        Fighters.pos(indice_oggetto).y = 200 'put up in the sky
    next indice_oggetto


'--------------------------- luci ambientali ----------------------------------------------
    DXScreen.CreateLightRGB(D3DRMLIGHT_AMBIENT, .1, .1, .1, Ambient) 'ambient is dim grey
    DXScreen.AddLight(Ambient)
    DXScreen.CreateLightRGB(D3DRMLIGHT_POINT, 1, 1, 1, Light)
    DXScreen.AddLight(Light)
    LightFrame.AddLight(Light)   'Luce che simula il SOLE
    LightFrame.SetPosition(20,SUN_POS_Y,SUN_POS_Z)
'---------------------------- oggetti --------------------------------------------------

    MeshBuilder2.Load("models/castello.x")
    MeshBuilder2.Scale(0.025, 0.025, 0.025)
    MeshBuilder2.SetQuality(D3DRMFILL_MASK)'D3DRMRENDER_PHONG)
    
    MeshBuilder5.Load("tank1.x")
    MeshBuilder5.Scale(.05, .05, .05)
    MeshBuilder5.SetQuality(D3DRMSHADE_MASK + D3DRMFILL_MASK +D3DRMLIGHT_ON)'D3DRMRENDER_PHONG)
    
    MeshBuilder6.Load("castlex.x")
    MeshBuilder6.Scale(.025, .025, .025)
    MeshBuilder6.SetQuality(D3DRMRENDER_PHONG)
    
    ' inserimento del cielo
    MeshBuildersky.Load("sky_piramid1.x")
    MeshBuildersky.Scale(15, 15, 15)
    MeshBuildersky.SetQuality(D3DRMRENDER_UNLITFLAT)
    MeshFramesky.AddVisual(MeshBuildersky)
    MeshFramesky.SetPosition(0, -10, 0)
    MeshFramesky.SetRotation(0, 0, 0,0)
    meshBuildersky.loadTexture("cloud_test.bmp")
    'dxScreen.createWrap(D3DRMWRAP_BOX, 0,0,0, 0,0,1, 0,1,0, 0,0, 1,1, wrap)
    dxScreen.createWrap(D3DRMWRAP_CHROME, 0,0,0, 0,0,1, 0,1,0, .5,.5, 0,.75, wrap)
    wrap.apply(meshBuildersky)
    
    'inserimento del piano terra
    MeshBuilderTerrain.Load("terrainbig.x")
    MeshBuilderTerrain.Scale(4, 4, 4)
    MeshFrameTerrain.AddVisual(MeshBuilderTerrain)
    MeshFrameTerrain.SetPosition(0, D3DGROUND_ZERO-.5, 0)
    MeshFrameTerrain.SetRotation(0, 0, 0,0)

'-------------------------------

    MeshFrame2.AddVisual(MeshBuilder2)
    MeshFrame2.SetPosition(300, 0, 0)'
    MeshFrame2.SetRotation(0, 0, 0,0)' Angle of rotation
    
    MeshFrame5.AddVisual(MeshBuilder5)
	MeshFrame5.SetPosition(Tank_Pos.x, Tank_Pos.y, Tank_Pos.z)
    MeshFrame5.SetOrientation(Tank_Orient.dvx, .001, Tank_Orient.dvz,Tank_Orient.x, 1000, Tank_Orient.z)

    MeshFrame6.AddVisual(MeshBuilder6)    
    MeshFrame6.SetPosition(-200,0, -200)
    MeshFrame6.SetRotation(0, 0, 0,0)


'************ shadows ***********

    DXScreen.CreateShadow(MeshBuilder6, Light ,0, -.2, 0, 0, .2, 0 ,Shadow)
    MeshFrame6.AddVisual(Shadow)
    
    DXScreen.CreateShadow(MeshBuilder5, Light ,0, -.2, 0, 0, .2, 0 ,Shadow)
    MeshFrame5.AddVisual(Shadow)
    
    DXScreen.CreateShadow(MeshBuilder2, Light ,0, -.2, 0, 0, .2, 0 ,Shadow)
    MeshFrame2.AddVisual(Shadow)
    
    DXScreen.CreateShadow(MyTrees.Mesh, Light ,0, -.2, 0, 0, .2, 0 ,Shadow_trees)
    for indice_oggetto = 1 to trees_number
        MyTrees.Frame(indice_oggetto).AddVisual(Shadow_trees)
    next indice_oggetto


'******************************
    FireBall.Init(DXScreen)
    WITH FireBall
'       .MakeSphere (DXScreen, 88)
        .File = "sphere.x"
'       .DrawCenter.y = 0
'       .ViewFromOutside = True                         'view from outside
       .Mesh.Scale(2, 2, 2)'
       .Mesh.SetQuality = D3DRMFILL_MASK +D3DRMLIGHT_OFF
'       .Mesh.SetRGB(1.0, 0.50, 0.0)
       .Frame(1).SetPosition(-20,20,0)
    END WITH
    DxScreen.createWrap(D3DRMWRAP_SPHERE , 0,0,0, 1,0,0, 0,0,1, 0,0, 5, 5, wrap)
    FireBall.Mesh.loadTexture("flame.bmp")
    wrap.apply(FireBall.Mesh)

'******************************
    DXScreen.SetCameraPosition(0, 16, -30) 
    DXScreen.CameraLookAt(MeshFrame5, D3DRMCONSTRAIN_Z)
END SUB


SUB DXInitializeSurface(Sender AS QDXScreen)
    DXScreen.SetRenderMode(D3DRMRENDERMODE_BLENDEDTRANSPARENCY OR D3DRMRENDERMODE_SORTEDTRANSPARENCY)
    TheTimer.Enabled = True
'DXTimer.Enabled = True
END SUB



SUB RenderLoop
DO
    '------------- posizione del sole ed intensità ------------
'    SUN_POS_Y=((sin(valoreazione/100)*1000))
'    SUN_POS_Z=((cos(valoreazione/100)*1500))
'    if SUN_POS_Y < 5 then SUN_POS_Y = 5
'    LightFrame.SetPosition(20,SUN_POS_Y,SUN_POS_Z)
    
    
    '------------- spostamento nuvole con il vento -------------------------
    
    for indice_oggetto = 1 to Fighter_Num
    if Fighters.pos(indice_oggetto).z <-1500 then 
        Fighters.pos(indice_oggetto).z =1500
        Fighters.pos(indice_oggetto).x = RND(1000) - 500
    end if
    Fighters.pos(indice_oggetto).z = Fighters.pos(indice_oggetto).z - 40 '10
    Fighters.Frame(indice_oggetto).SetPosition(Fighters.pos(indice_oggetto).x,_
            Fighters.pos(indice_oggetto).y, _
            Fighters.pos(indice_oggetto).z)
    next indice_oggetto
    
    '=====================================================================
        'min and max camera position
    if Cam_Pos.y <=D3DGROUND_ZERO+.5 then Cam_Pos.y = D3DGROUND_ZERO+.5
    if Cam_Pos.y >=630 then Cam_Pos.y = 630
    if Cam_Pos.x <=-380 then Cam_Pos.x = -380
    if Cam_Pos.x >=380 then Cam_Pos.x = 380  
    if Cam_Pos.z <=-380 then Cam_Pos.z = -380
    if Cam_Pos.z >=380 then Cam_Pos.z = 380
    
    DXScreen.SetCameraPosition(Cam_Pos.x, Cam_Pos.y, Cam_Pos.z)
    DXScreen.SetCameraOrientation(Cam_Orient.dvx, Cam_Orient.dvy, Cam_Orient.dvz,Cam_Orient.x, Cam_Orient.y, Cam_Orient.z) 
    'DXScreen.CameraLookAt(MeshFrame5, D3DRMCONSTRAIN_Z)

    FireBall.Pos(1).x = TheBadGuy_x
    FireBall.Pos(1).z = TheBadGuy_z
    FireBall.Pos(2).x = TheBadGuy_x
    FireBall.Pos(2).z = TheBadGuy_z
    FireBall.Frame(1).SetPosition(TheBadGuy_x , 0, TheBadGuy_z)
    FireBall.Frame(2).SetPosition(TheBadGuy_x , 0 ,TheBadGuy_z)

    DXScreen.Render

    '========================= text on screen ============================
'    DXScreen.TextOut(10,10,"FPS: "+str$(dxTimer.frameRate), &HFFFFFF, -1)
    '    DXScreen.TextOut(10,10,"DEA Engine - Time:"+time$+" Date:"+DATE$+" FPS: "+str$(dxTimer.frameRate), &HFFFFFF, -1)
    '    DXScreen.TextOut(10,25," Mouse x:"+(str$(MouseX_Now))+" Mouse y:"+(str$(MouseY_Now)), &HFFFFFF, -1)
    '    DXScreen.TextOut(10,40," Mid_X:"+(str$(Mid_X))+" Mid_y:"+(str$(Mid_y)), &HFFFFFF, -1)
    '    DXScreen.TextOut(10,55," camx:"+(str$(Cam_Pos.x))+" camy:"+(str$(Cam_Pos.y))+" camz:"+(str$(Cam_Pos.z)), &HFFFFFF, -1)
    '    DXScreen.TextOut(10,70," cam_orient_x:"+(str$(Cam_Orient.dvx))+" cam_orient_y:"+(str$(Cam_Orient.dvy))+" cam_orient_z:"+(str$(Cam_Orient.dvz)), &HFFFFFF,-1)
'    DXScreen.TextOut(10,85," sun_y:"+str$(SUN_POS_Y)+" sun_z:"+str$(SUN_POS_Z)+" timer:"+str$(valoreazione), &HFFFFFF, -1)
    
    '------- tank values ----------
    '    DXScreen.TextOut(10,440," tank_orient_dvx:"+str$(Tank_Orient.dvx)+" tank_orient_dvz:"+str$(Tank_Orient.dvz)+" tank_orient_x:"+str$(Tank_Orient.x)+" tank_orient_z:"+str$(Tank_Orient.x), &HFFFFFF, -1)

    '---------------------------------------------------------------------
    IF HUD_On THEN DXScreen.Draw(HUD_x, HUD_y, HUD.BMP)
    DXScreen.Flip
DOEVENTS
    IF (Fini = True) THEN Form.Close:Application.Terminate
Loop
END SUB


SUB TimerExpired
    IF FireBall_Scale > 30 THEN
        FireBall_Scale = 3.0
        FireBall_Alpha = 1.0
        TheBadGuy = RND(Fighter_Num)
        TheBadGuy_x = Fighters.pos(TheBadGuy).x
        TheBadGuy_z = Fighters.pos(TheBadGuy).z
    ELSE
        INC(FireBall_Scale, 3)
        DEC (FireBall_Alpha, .1)
    END IF
   FireBall.Frame(1).AddScale(0, FireBall_Scale, FireBall_Scale, FireBall_Scale)
   FireBall.Frame(2).AddScale(0, FireBall_Scale/1.5, FireBall_Scale/1.5, FireBall_Scale/1.5)
   FireBall.Mesh.SetRGBA(1.0, 0.80 * FireBall_Alpha, 0.6 * FireBall_Alpha, FireBall_Alpha)
END SUB



SUB mouse
    dim posizionex_old_mouse as integer
    Mousesim_x=Mousesim_x+(Screen.MouseX-posizionex_old_mouse)
    
    MouseX_Now = Omega * (Mousesim_x - Mid_X)/ Mid_X
    MouseY_Now = Omega * (Screen.MouseY - Mid_Y)/ Mid_Y
    
    If MouseY_Now >= 1.4 then MouseY_Now = 1.4
    If MouseY_Now <= -1.4 then MouseY_Now = -1.4
    
    Cam_Orient.dvx = COS(MouseX_Now)
    Cam_Orient.dvy = TAN(MouseY_Now)
    Cam_Orient.dvz = SIN(MouseX_Now)
    Cam_Orient.x = 0
    Cam_Orient.y = 1
    Cam_Orient.z = 0
    
    posizionex_old_mouse=Screen.MouseX
END SUB 


SUB play_tank_engine_sound
    'tank_engine_sound.Position=0
    'tank_engine_Sound.play
END SUB

SUB stop_tank_engine_sound
    'tank_engine_sound.Position=0
    'tank_engine_Sound.stop
END SUB

 

form.Show'Modal
RenderLoop
