Bullets in arrays

Blitz3D Forums/Blitz3D Programming/Bullets in arrays

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

A similar thing with an array might be

Global gTime=Millisecs()
Global gMissile=CreateCube()
PositionEntity gMissile,0,0,-1000; put template missile out of the way
Global gShip=LoadMesh("MySpaceshipMesh.b3d")
Dim missile(100)

;then call this function every frame

Function Update_Missiles()

If MouseDown(1) Or KeyDown(157)
If MilliSecs()-gTime>100
createnewmissile=True
EndIf
EndIf

For m=0 To 99
;create a new one in an empty array element
If createnewmissile=True
If missile(m)=0
missile(m)=CopyEntity(gMissile)
PositionEntity missile(m),EntityX(gShip),EntityY(gShip),EntityZ(gShip)+6
createnewmissile=False
gTime=MilliSecs()
EndIf
EndIf
;move them
If missile(m)<>0
MoveEntity missile(m),0,0,2
If EntityZ(missile(m))>50
FreeEntity missile(m)
missile(m)=0
EndIf 
EndIf
Next

End Function


You don't have to delete the missiles either, you could just leave them offscreen and move them back when they need firing again.