#Include "Ninfa3d.bi"

dim Shared camera as nCAMERA
dim light01 As nLIGHT

Dim As nPARTICLE fairy01,fairy02,font01
Dim As nEMITTER emitter01,emitter02,emitter03

Dim tex As nTEXTURE
Dim sound As nSOUND
Dim pivot As nMESH

Dim sprite As nSPRITE

'Enable vertical synch.
EnableVsync()

'Starts the Ninfa3D Engine
InitEngine(640,480,32,0)
	BackGroundColor(0,0,0)'Background color
	AmbientLight(16,16,16)'Ambient color

'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 = CreateCameraFPS(100,0.5)
	PositionEntity(camera,0,128,-256)'Position

'Creates the light
light01 = CreateLight(LGT_POINT)
	PositionEntity(light01,0,196,0)'Position

sprite = LoadSprite("media/glow.bmp")
	EntityParent(sprite,light01)
	ScaleSprite(sprite,64,64)

pivot = CreateMeshNull()'Creates an empty mesh is used as the pivot.

CreateGround()'Creates the test area

'Load the sound.
sound = LoadSound("media\alien_creeper.wav")
	SoundType(sound,2)'Type sound, in this case 3D.
	PlaySound(sound)'Active the sound
	LoopSound(sound)'It makes repeat indefinitely
	PositionEntity(sound,0,196,0)'Position the sound.
	
	'These commands are used only for 3D sound.
	SoundReferenceDistance(sound,300)
	SoundRollOff(sound,15)

tex = LoadTexture("media/glow.BMP") 'Load the texture.

Dim As I i,r,g,b

For i = 1 To 10
	
	'Random!!!
	r = Rand(0,255)
	g = Rand(0,255)
	b = Rand(0,255)
	
	'Create the particles, in this case to create fire type 1.
	fairy01 = CreateParticle()'Creates particles
		EntityParent(fairy01,pivot)
		PositionEntity(fairy01,100*(i/6),32*(i/2),0)'Position
		ParticleEndSize(fairy01,-40,-40)'Size of the final particles
		EntityTexture(fairy01,tex,0)'Texture
		
	emitter01 = CreateBoxEmitter(fairy01,500,2000)'Creates the emitter.
		BoxEmitterSize(emitter01,4,4,4)'Box emitter size.
		EmitterDirection(emitter01,0,-0.06,0) 'Direction of emitter.
		EmitterPPS(emitter01,60,80)'Particles per second to be emitt by the emitter.
		EmitterStartColor(emitter01,r,g,b,255,255,255)'Color of the minimum and maximum particle.
		EmitterStartSize(emitter01,5,5,30,30)'Minimum and maximum size of the particle.
	
	fairy02 = CreateParticle()'Creates particles
		EntityParent(fairy02,pivot)
		PositionEntity(fairy02,-100*(i/6),32*(i/2),0)'Position
		ParticleEndSize(fairy02,-40,-40)'Size of the final particles
		EntityTexture(fairy02,tex,0)'Texture
	
	emitter02 = CreateBoxEmitter(fairy02,500,2000)'Creates the emitter.
		BoxEmitterSize(emitter02,4,4,4)'Box emitter size.
		EmitterDirection(emitter02,0,-0.06,0) 'Direction of emitter.
		EmitterPPS(emitter02,60,80)'Particles per second to be emitt by the emitter.
		EmitterStartColor(emitter02,0,r,g,b,255,255)'Color of the minimum and maximum particle.
		EmitterStartSize(emitter02,5,5,30,30)'Minimum and maximum size of the particle.
Next

'Create the particles, in this case to create font type 1.
font01 = CreateParticle()'Creates particles
	PositionEntity(font01,0,0,0)'Position
	ParticleEndSize(font01,80,80)'Size of the final particles
	EntityTexture(font01,tex,0)'Texture
	
emitter03 = CreateBoxEmitter(font01,500,2500)'Creates the emitter.
	BoxEmitterSize(emitter03,4,4,4)'Box emitter size.
	EmitterDirection(emitter03,0,0.08,0) 'Direction of emitter.
	EmitterPPS(emitter03,80,100)'Particles per second to be emitt by the emitter.
	EmitterStartColor(emitter03,0,0,128,128,128,128)'Color of the minimum and maximum particle.
	EmitterStartSize(emitter03,10,10,20,20)'Minimum and maximum size of the particle.
	
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)

	TurnEntity(pivot,0,1,0)

	'Displays the interface (FPS and triangles)
	Interface()
	
	'End the scene
	EndScene()
	
Wend

'Ends Ninfa3D Engine
EndEngine()