FMC:Phoniex Alpha Test 2

Miscellaneous Forums/Blitz Showcase/FMC:Phoniex Alpha Test 2

Ok, give me a hour or so to get it working in the latest build.

For now, here's the source to it to show easy it was.

Strict
Import "Aurora.bmx"
'-=-=-=-=-=-=-=-=-=-=-
'
'      Ogre Max
'        V1.0
'
'    '     First Person Shooter. Demo.
'
'-=-=-=-=-=-=-=-=-=-=-


Local Display:TDisplay = TDisplay.Create()
Display.OpenScreen()

Local Light:TLight = Tlight.CreateOmni()
Light.Diffuse( 255,255,255 )
Light.Position( 0,30,0 )
Light.Specular( 0,0,0 )
TLight.SetAmbient( 128,128,128 )
'Display.ShadowMode( Shadows_StencilAdd )
'Local Sl:TSceneLoader = New TSceneLoader

'Local Scene:TScene = Sl.Load("Media/Arena1.osm")
LoadScene("Scene.OSM".tocstring())


'---- Scene Set up
Local Camera:TCamera = TCamera.Create()
TGui.Init( Camera )

Local InputDevice:TInput = TInput.Create()
TPhysics.Init( Camera )
TPhysics.SetWorldSize( -1000,-1000,-1000,1000,1000,1000 )
Local Terrain:TEntity = TEntity.CreateMesh("terrain.mesh")



Local Col:TCollider = TCollider.CreateStatic( Terrain )
Local GBody:TBody = tbody.Create( col,"Ground" )
gbody.attachtopivot( terrain )
gbody.setInertia( Tinertia.CreateCube( 0,1,1,1 ) )
Local Sky:TEntity = TEntity.CreateMesh("sky.mesh")

'--- Gun set up

Local Gun:TEntity = TEntity.CreateMesh("gun1.mesh")
Gun.scale( 0.05,0.05,0.05 )
gun.setmaterial( "Examples/BumpMapping/MultiLightSpecular" )

'---Target set up

Type Target
	Function Create:Target( x#,z#,xs#,ys#,zs#)
		
		Local out:target = New target
		out.ent = TEntity.CreateMesh( "target1.mesh" )
		out.ent.castshadows( True )
		out.ent.scale( xs,ys,zs )
		Local col:TCollider = TCollider.Createconvex( out.ent )
		out.bod = Tbody.Create( col,"Target" )
		out.bod.attachtopivot( out.ent )
		out.bod.setinertia( Tinertia.createCube( 0.5,2.5,6,1 ) )
		out.bod.setCenterOfMass( 0,0.2,0 )
		out.bod.enableGravity()
		out.bod.ActivateForceAndTorque()
		Local groundy#
		If traycast.cast( x,200,z,0,-400,0 )
			groundy = traycast.y()+1
		Else
			groundy=100
		EndIf
		out.bod.position(x,groundy,z)
		Return out	
	End Function
	Field bod:TBody
	Field Ent:TEntity
End Type

Local targets = 20
Local tars:Tlist = CreateList()
For Local j=1 To targets
	
	Local tar:Target = target.create(Rnd(-100,100),Rnd(-100,100),0.2,0.2,0.2 )
	tars.addlast( tar )
	
		
Next

Local GunFire:TSound = LoadSound("Media/Shot1.wav")
Local FireTime:TTimer = TTimer.Create(100)

'--- Player Vars. Normally would be a type but this is supposed to be an easy to understand demo so not here it ain't. 
Local playx#,playy#,playz#
Local xi#,zi#
Local cinc#
Repeat


	'update physics.
	For Local j=1 To 3
		tphysics.update( 0.1 )
	Next
	
	
	If inputdevice.mousedown( 0 ) 
		If firetime.clicked()
		
	
		If camera.pick( displaywidth()/2,displayheight()/2 )
			
			Local hx#,hy#,hz#
			hx = camera.pickx()
			hy = camera.picky()
			hz = camera.pickz()
			Local bod:Tbody = camera.pickBody()
			
			Local vx#,vy#,vz#,mag#
			vx = bod.x()-camera.x()
			vy = bod.y()-camera.y()
			vz = bod.z()-camera.z()
			mag = Sqr( vx*vx+vy*vy+vz*vz )
			vx = vx/mag
			vy = vy/mag
			vz = vz/mag
			Local strength# = 100
			bod.addpush( vx*Strength,vy*Strength,vz*strength )
			'bod.push( hx,hy,hz,vx*strength,vy*strength,vz*strength )
			TParticleController.Create( hx,hy,hz,"Examples/Smoke",250,1000 )
			
		EndIf
		PlaySound gunfire
		EndIf
			
	Else
		firetime.reset()
	EndIf
	TparticleController.UpdateAll()
	
	'Check to see where the player should be on the terrain.
	If traycast.cast( playx,10,playz,0,-100,0 ) 'cast a ray
		
		playx = traycast.x()
		playy = traycast.y()+4
		playz = traycast.z()
		
	EndIf
	'position and rotate camera based on player input
	camera.position( playx,playy,playz )
	camera.pitch( -inputdevice.mouseyspeed() )
	camera.yaw( -inputdevice.mousexspeed() )
	
	If inputdevice.keydown( Key_W )
		Camera.TFormVector( 0,0,-0.2 )
		xi:+Camera.TFormedX()
		zi:+Camera.TFormedZ()
	EndIf
	If inputdevice.keydown( KEY_A )
		camera.tformvector( -0.05,0,0 )
		xi:+camera.tformedx()
		zi:+camera.tformedz()
	End If
	If inputdevice.keydown( KEY_D )
		camera.tformvector( 0.05,0,0 )
		xi:+Camera.tformedx()
		zi:+camera.tformedz()
	End If
	If inputdevice.keydown( KEY_S )
		camera.tformvector( 0,0,0.2 )
		xi:+camera.tformedx()
		zi:+camera.tformedz()
	End If
	
	xi:*0.9
	zi:*0.9
	playx:+xi
	playz:+zi
	
	'determine gun's position
	camera.tformpoint( -1,-1,-3 )
	
	gun.position( camera.tformedx(),camera.tformedy(),camera.tformedz() )
	
	'Determine gun's orientation
	
	gun.setquat( camera.getQuat() )
	
	
	Render3D()
	CaptureInput()
	tgui.freeevents()
	tgui.updateevents()
	
Until InputDevice.KeyDown(Key_Escape)