EntityInView with types

Blitz3D Forums/Blitz3D Programming/EntityInView with types

I am not really undertsanding what your mission is with the code

He wants shipseen to be set true if any one ship has come into view.

Spriteman, the next step would be to get rid of the shipseen variable altogether -- it's currently acting as a global bridge between the ColourShips() function and the main code that decides which text message to present. To tidy things up I would delete the shipseen stuff from ColourShips() and write an extra function that directly returns the information that shipseen is currently being used to store:

Const NUMBER_OF_SHIPS = 2

Graphics3D 800,600,0,2
SetBuffer BackBuffer()
cam = CreateCamera()
PositionEntity cam,0,5,-20
light = CreateLight()
PositionEntity light,100,100,-100

Type ship
	Field geom
	Field seen
End Type
CurrentShip.Ship = Null

Function CreateShip.Ship()
	NewShip.Ship = New ship
	NewShip\geom = CreateSphere(8)
	EntityPickMode NewShip\geom,1
	Return NewShip.Ship
End Function

Function CheckShipsAgainst(player_arg.player)
	For CurrentShip.ship = Each ship
		If EntityInView(CurrentShip\geom,player_arg\cam)
			CurrentShip\seen = True
		Else
			CurrentShip\seen = False
		EndIf
	Next
End Function

Function ColourShips()
	For CurrentShip.ship = Each ship
		If CurrentShip\seen
			EntityColor CurrentShip\geom,100,255,255
		Else
			EntityColor CurrentShip\geom,100,100,100
		EndIf
	Next
End Function

Function AnyShipSeen%()
	For CurrentShip.ship = Each ship
		If CurrentShip\seen Return True
	Next
	Return False
End Function


Type player
	Field cam
	Field geom
End Type

Function CreatePlayer.Player(viewX_arg, viewY_arg)
	Local NewPlayer.Player = New player
	NewPlayer\cam = CreateCamera()
	CameraViewport NewPlayer\cam,viewX_arg,viewY_arg,256,256
	CameraClsColor NewPlayer\cam,10,10,10
	NewPlayer\geom = CreateCone()
	RotateEntity NewPlayer\geom,90,0,0
	EntityParent NewPlayer\geom,NewPlayer\cam
	Return NewPlayer
End Function
CurrentPlayer.Player = CreatePlayer(0,0)


worldPiv = CreatePivot()
PointEntity cam,worldPiv
For i = 1 To NUMBER_OF_SHIPS
	CurrentShip = CreateShip()
	PositionEntity CurrentShip\geom,0,0,15
	EntityParent CurrentShip\geom, worldPiv
	TurnEntity worldPiv, 0, 360/NUMBER_OF_SHIPS, 0
Next



While Not MouseHit(1)
	TurnEntity worldPiv,0,1,0
	TurnEntity CurrentPlayer\cam,0,-.5,0

	CheckShipsAgainst(CurrentPlayer)
	ColourShips()

	RenderWorld
	If AnyShipSeen()
		Text 0,0, "Ship in view"
	Else
		Text 0,0, "Ship out of view" 
	EndIf	 

	Flip True
	Cls
	Delay 1
Wend