'Load textures.
Dim shared texture01 As nTEXTURE
	texture01 = LoadTexture("media/mur_Ambiant.jpg")
	
Dim Shared texture02 As nTEXTURE
	texture02 = LoadTexture("media/Brick.jpg")
	
Dim Shared texture03 As nTEXTURE
	texture03 = LoadTexture("media/wall1.jpg")

Dim Shared texture04 As nTEXTURE
	texture04 = LoadTexture("media/wall.jpg")

Dim Shared texture05 As nTEXTURE 
	texture05 = LoadTexture("media/Wood.jpg")
	
'Load the sound.
Dim shared sound01 As nSOUND
	sound01 = LoadSound("media/bullet_hit1.wav")
		SoundType(sound01,1)

'###################################################################################################
'# BULLET

Sub CreateBullet()
	
'Position of the target.
	dim As S tarx = TargetX(camera)
	dim As S tary = TargetY(camera)
	dim As S tarz = TargetZ(camera)
	
'Camera position.
	dim As S camx = EntityX(camera)
	dim As S camy = EntityY(camera)
	dim As S camz = EntityZ(camera)
	
'Create a sphere.
	Dim As nMESH mesh = CreateMeshSphere(16)
			ScaleMesh(mesh,15,15,15)
		
'Create a body type field.
	dim As nBODY body = CreateBodySphere(15,15,15,5)
			EntityParent(body,mesh)'The mesh uses the address data
										  'The body.
			PositionEntity(body,camx,camy,camz)'The positions
			LinearVelocity(body,tarx-camx,tary-camy,tarz-camz)'I applied speed

'Activate the sound.
	PlaySound(sound01)

End sub

'###################################################################################################
'# PYRAMID

sub CreatePyramid(ByVal px As S,ByVal py As S,ByVal pz As S,ByVal count As I)

	dim As I i,j
	Dim As nMESH mesh
	Dim As nBODY body
		
	For i=0 To count
		For j=0 To i
		
		mesh = CreateMeshCube()'Creates a mesh type cube.
			ScaleMesh(mesh,16,16,16)'Increase the size of the mesh.
			EntityTexture(mesh,texture01,0)'I applied a texture.
	
		body = CreateBodyCube(16,16,16,1)'Create a body type cube.
			PositionEntity(body,px+(j*20-i*10),py+(150-i*20),pz+0)'Position
			EntityParent(body,mesh)'The mesh uses the address data
										  'The body.
		
		Next
	Next
	
End sub

'###################################################################################################
'# TOWER

sub CreateTower(ByVal pc As S,ByVal py As S,ByVal pz As S)

	dim As I height = 4
	
	Dim As S column_width = 2.5
	Dim As S column_height = 10
	
	Dim As S floor_width = 15
	Dim As S floor_height = 2.0
	
	Dim As S column_density = floor_width - 1
	
	Dim As nMESH mesh
	Dim As nBODY body
	
	py = py + column_height
	
	Dim As I x,y,z
	
	For y = 0 To height
		For x = -1 To 1 Step 2
			For z = -1 To 1 Step 2
	
				mesh = CreateMeshCylinder(8)
					ScaleMesh(mesh,column_width,column_height,column_width)
					EntityTexture(mesh,texture02,0)
					
				body = CreateBodyCylinder(column_width,column_height,1)
					EntityParent(body,mesh)
					PositionEntity(body,pc+x*column_density,py+y*1.25*(column_height+floor_height),pz+z*column_density)
			
			Next
		Next
	
		mesh = CreateMeshCube()
			ScaleMesh(mesh,floor_width*2.5,floor_height+0.01,floor_width*2.5)
			EntityTexture(mesh,texture03,0)	
					
		body = CreateBodyCube(floor_width*2.5,floor_height+0.01,floor_width*2.5,1)
			EntityParent(body,mesh)
			PositionEntity(body,pc,py+y*1.25*(column_height+floor_height)+column_height+floor_height,pz)
	
	Next
	
	mesh = CreateMeshCone(12)
		ScaleMesh(mesh,15,30,15)
		EntityColor(mesh,64,128,128)'Change the diffuse color of the mesh

	body = CreateBodyCone(15,30,5)
		EntityParent(body,mesh)
		PositionEntity(body,pc,py+(height+1)*1.25*(column_height+floor_height),pz)

End sub

'###################################################################################################
'# GROUND

Sub CreateGround()

	Dim mesh As nMESH
	Dim body As nBODY

	mesh = CreateMeshCube()
		ScaleMesh(mesh,512,20,1)
		PositionEntity(mesh,0,10,256)
		EntityTexture(mesh,texture05,0)
	body = CreateBodyCube(512,20,1,0)
		PositionEntity(body,0,10,256)
	
	mesh = CreateMeshCube()
		ScaleMesh(mesh,1,20,512)
		PositionEntity(mesh,256,10,0)
		EntityTexture(mesh,texture05,0)
	body = CreateBodyCube(1,20,512,0)
		PositionEntity(body,256,10,0)
	
	mesh = CreateMeshCube()
		ScaleMesh(mesh,512,20,1)
		PositionEntity(mesh,0,10,-256)
		EntityTexture(mesh,texture05,0)
	body = CreateBodyCube(512,20,1,0)
		PositionEntity(body,0,10,-256)
	
	mesh = CreateMeshCube()
		ScaleMesh(mesh,1,20,512)
		PositionEntity(mesh,-256,10,0)
		EntityTexture(mesh,texture05,0)
	body = CreateBodyCube(1,20,512,0)
		PositionEntity(body,-256,10,0)
	
	mesh = CreateMeshPlane(64,8)
		EntityTexture(mesh,texture04,0)
	body = CreateBodyCube(512,1,512,0)
		PositionEntity(body,0,-1,0)

End Sub

Sub Interface()

	Colors(0,0,0)'Change the color of the graphs, apart from here
				   'Will be colored black.
	Transparency(128)'Change the transparency level.
		If ViewPortWidth=640 Then
			Rect2D(0,0,640,60)'Draw a rectangle.
			Rect2D(0,420,640,480)
		EndIf
		If ViewPortWidth=1024 Then
			Rect2D(0,0,1024,120)'Draw a rectangle.
			Rect2D(0,648,1024,768)
		EndIf
	Colors(255,255,255)
	Transparency(255)

	Font(0)'Set the default font.

	Text(15,10,"Triangles: "+Str$(TrisRendered),0,0)'Displays on the screen
																	'Triangles in the scene.
	Text(15,20,"FPS: "+Str$(Fps),0,0)'Displays on the screen
												'Frames per second.
	Text(560,10,"Total Lights: "+Str$(LightCount),0,0)'Displays on the screen
															 'Lights in the scene.
	Text(560,20,"Total Meshes: "+Str$(PrimitiveCount),0,0)'Displays on the screen
															 		'Meshes in the scene.
	Text(560,30,"Total Bodies: "+Str$(BodyCount),0,0)'Displays on the screen
															 		'Bodies in the scene.
	
End Sub