#Include "Ninfa3d.bi"

dim Shared camera As nCAMERA
dim light01 As nLIGHT
Dim terrain As nTERRAIN
Dim font01 As nFONT
Dim As nTEXTURE tex01,tex02
Dim wire As Integer
Dim rocket as nMesh
Dim fire As nPARTICLE
Dim emitter01 As nEMITTER
Dim tex_particle As nTEXTURE
Dim v As Single

'Enable vertical synch.
EnableVsync()

'Starts the Ninfa3D Engine
InitEngine(1280,1024,32,0)
	BackGroundColor(128,128,128)'Background Color
	AmbientLight(64,64,64)'Ambient color
	Fog(96,96,96,0.0003)' Fog

'Include the file "SampleFuntions.bi.
'It contains useful features, such as drawing the interface and create the test area.
#Include "SampleFunctions.bi"

'Create a camera
camera = CreateCamera()
	CameraRange(camera,1,42000)
    positionentity(camera,0,10,-40)
	' Position

tex_particle = LoadTexture("media/glow.BMP") 'Load the texture.
'Create the particles, in this case to create fire type 1.
fire = CreateParticle()'Creates particles
	PositionEntity(fire,0,0,-10)'Position
	ParticleEndSize(fire,-10,-10)'Size of the final particles
	EntityTexture(fire,tex_particle,0)'Texture
	
emitter01 = CreateRingEmitter(fire,100,150)
    RingEmitterCenter(emitter01,0,0,0)
    RingEmitterRadius(emitter01,0.5)
    RingEmitterThickness(emitter01,0.5)
    EmitterDirection(emitter01,0,0,0) 'Direction of emitter.
	EmitterPPS(emitter01,500,500)'Particles per second to be emitt by the emitter.
	EmitterStartColor(emitter01,255,150,200,255,150,200)'Color of the minimum and maximum particle.
	EmitterStartSize(emitter01,0,0,5,5)'Minimum and maximum size of the particle.
    

'Creates the lights
light01 = CreateLight(LGT_DIRECTIONAL)
	PositionEntity(light01,0,512,0)' Position

font01 = LoadFont("media\courier.xml")'Load the font, in format XML

'Load textures
tex01 = LoadTexture("media\Mud0029_1_M.jpg")
tex02 = LoadTexture("media\FullskiesOvercast0036_1_S.jpg")

'Create a terrain mesh
terrain = LoadTerrain("media\TOPOMAP1.jpg",5,1)
	ScaleMesh(terrain,80,4,80)
	EntityTexture(terrain,tex01,0)
	ScaleTexture(terrain,40,0)'Scale the texture of the terrain
	PositionEntity(terrain,0,0,0)

rocket=LoadMesh("media2\fighter.x")
entityparent(camera,rocket)
positionentity(rocket,2500,500,2550)
entityparent(fire,rocket)

v=0.1

CreateSkyDome(tex02,10000)'Creates the sky



While(EngineRun)'Returns 1 if the engine is running.

	'Begins scene
	BeginScene()
	
	'By pressing the "ESCAPE" closes the engine.
	If KeyHit(KEY_ESCAPE) Then CloseEngine()
	
	'Update the Engine.
	'Changing the value (only affects the physics) that will update the
	'Physical faster or slower.
	UpdateEngine(0.05)
	If KeyHit(KEY_E) Then wire = wire + 1
		
	If wire>1 Then wire = 0
	
	If Wire = 1 Then
		EntityFlag(terrain,0,1)
	Else
		EntityFlag(terrain,0,0)
	EndIf
    
    If KeyDown(KEY_W) then turnentity(rocket,0.2,0,0)'pitch
    If KeyDown(KEY_S) then turnentity(rocket,-0.2,0,0)
    If KeyDown(KEY_A) then turnentity(rocket,0,-0.5,0)'yaw
    If KeyDown(KEY_D) then turnentity(rocket,0,0.5,0)
    If KeyDown(KEY_Z) then turnentity(rocket,0,0,0.5)'roll
    If KeyDown(KEY_C) then turnentity(rocket,0,0,-0.5)
    
    If KeyDown(KEY_1) then v=0.5
    If KeyDown(KEY_2) then v=1
    If KeyDown(KEY_3) then v=1.5
    If KeyDown(KEY_4) then v=2
    If KeyDown(KEY_5) then v=2.5
    
    If KeyDown(KEY_0) then v=0
    
    moveentity(rocket,0,0,v)'roll
    
	Font(font01)'assign the font to use
	Text(15,75,"E - Wireframe, WSADZC -control, 1,2,3,4,5 - speed",0,0)
    cameratarget(camera,entityX(rocket),entityY(rocket),entityZ(rocket))
    'PositionEntity(camera,EntityX(camera),TerrainHeight(terrain,EntityX(camera),EntityZ(camera))+10,EntityZ(camera))
	'Displays the interface (FPS and triangles)
	Interface()

	'End the scene
	EndScene()
	
Wend

'Ends Ninfa3D Engine
EndEngine()