Destroying a Target

Blitz3D Forums/Blitz3D Beginners Area/Destroying a Target

This works ... although clearly you were missing alot of code from the above.

Graphics3D 640,480,32,1

Global Gun = CreateCamera()
PositionEntity gun, 0,60,0

Const type_target=1
Const type_missile=2
Global SOUNDbam ;= LoadSound("Plasma Gun.wav" )

;Ceating the bullets
Global BULLETmesh = CreateSprite() ;LoadSprite("Shot 1.bmp")
ScaleSprite BULLETmesh,.2,.2
EntityType BULLETmesh,type_missile
EntityRadius BULLETmesh,.02
HideEntity BULLETmesh
Global fullmag=100
Dim bullet( fullmag-1 )
For i = 0 To fullmag-1
	bullet(i)= CopyEntity( BULLETmesh )
	HideEntity bullet(i)
Next

;Creating the targets with an array
Global targets = 20
Dim target_one( targets-1)
For x = 0 To targets-1
	target_one(x)=CreateCube()
	PositionEntity target_one(x),(x-10 )*5 ,60,Rand(-300,300)
	ScaleEntity target_one(x),2,2,2
	EntityType target_one(x),type_target
Next

Collisions type_missile,type_target,2,1

While Not KeyDown(1)

	TurnEntity Gun, 0, -MouseXSpeed()*.1, 0
	MoveMouse 320,240

	;Firing bullets
	If MouseHit(1) And reload = 0
		HideEntity bullet(t)
		EntityParent bullet(t),gun
		PositionEntity bullet(t),0,2,0 ;1,500,-10
		RotateEntity bullet(t),0,0,0
		ShowEntity bullet(t)
		EntityParent bullet(t),0
		t=t+1
		;PlaySound SOUNDbam
	EndIf
	
	bulletpath()
	UpdateWorld
	RenderWorld
	Flip

Wend
End

;====================================================================
;====================================================================
;====================================================================

Function bulletpath()

	For q = 0 To fullmag-1
	
		MoveEntity bullet(q),.02,-.04,2.5

		If CountCollisions(bullet(q)) > 0

			HideEntity bullet(q)

		Else

			For x = 0 To Targets-1
			
				If EntityDistance(bullet(q),target_one(x)) <= 3
					HideEntity target_one(x)
				EndIf
			
			Next

		EndIf

	Next

End Function