Well this may not be the best way of doing it and there are a few potentials for error, such as if there are more than 500 bullets in your scene at one time...but these can be ironed out withot too much bother. I guess if there are 32 ships in a scene each firing 10 rounds a second then it is highly likely you'd have more than 500 bullets pretty rapidly - except the game would probably slow down stupidly at this point so there'd need some way to prevent this...some kind of bullet cap. I don't know what yet.
Still this works hunky dory at the mo.
shotFired:
`For determining rate of fire of bullets:
if (timer()-lastShotFiredTime)>ProjectileROF
lastShotFiredTime=timer()
`shots=number of bullets "alive" in the scene
`shotObjNo= the new object no to give to the cloned bullet object
inc shots
inc shotObjNo
`May be a better way to do this to ensure duplicate shot objects are not made
if shotObjNo>500 then shotObjNo=1
`clone the bullet object
clone object 100,500+shotObjNo
`set object properties - ie not affected by light, transparency
set object shotObjNo+500,1,1,0
set object ambient shotObjNo+500,0
`Bullet physics properties
projectilespeed=20000
`This camAngle and cam variables relate to camera angle and position
projectileXAngle#=camAnglex#
projectileYAngle#=camAngley#
`using "shots-1" because the first bullet will be stored at shot(0) nad not shot(1)
shot(shots-1).object=500+shotObjNo
`projectile=location of bullet in space - this is initiated to be camera position
shot(shots-1).projectileX#=camX#
shot(shots-1).projectileY#=camY#
shot(shots-1).projectileZ#=camZ#
`projV=velocity of bullet
shot(shots-1).projVy=sin(projectileXAngle#)*projectilespeed*-1
shot(shots-1).projVx=sin(projectileYAngle#)*(cos(projectileXAngle#))*projectilespeed
shot(shots-1).projVz=cos(projectileYAngle#)*(cos(projectileXAngle#))*projectilespeed
`time of bullet creation so we can kill it after a certain period of time if required
shot(shots-1).bulletbirth=startTime#
endif
Return
checkShots:
` This sub-routine is to move existing bullets and add and remove data from the bullet array
if shots>0
i=0
` This code will loop until the array reaches an empty space
while shot(i).object>0
`the bullet is a flat textured object so we want it to always point at the camera
point object shot(i).object,camx#,camy#,camz#
`bullets are affected by gravity just as much as any other object
`this also helps remove bullets from the scene as they will ultimately hit the ground
inc shot(i).projVy,gravity#
`calculate new position of existing bullets
`nb scale#=a scaler value I have specified so everything in the scene is in proportion - will vary from game to game
`timephase#=calculated outside loop with "GetTimer()", equals milliseconds between each pass of the code
inc shot(i).projectilex#, shot(i).projVx*timephase#*scale#
inc shot(i).projectiley#, shot(i).projVy*timephase#*scale#
inc shot(i).projectilez#, shot(i).projVz*timephase#*scale#
position object shot(i).object,shot(i).projectilex#,shot(i).projectiley#,shot(i).projectilez#
`if shot hits the ground or bullet has been in the scene for more than a certain time (ms)
` - Kill it and move last array entry in to its place.
if shot(i).projectiley#<0 || startTime#-shot(i).bulletbirth>bulletLifespan
delete object shot(i).object
inc shots,-1
`this may be the only shot in existence, in which case there'll be no need to mess with the array.
`If there are one or more left then take the last array entry and move it to the first
if shots>0
shot(i).object=shot(shots).object
shot(i).bulletbirth=shot(shots).bulletbirth
shot(i).projectilex#=shot(shots).projectilex#
shot(i).projectiley#=shot(shots).projectiley#
shot(i).projectilez#=shot(shots).projectilez#
shot(i).projVx=shot(shots).projVx
shot(i).projVy=shot(shots).projVy
shot(i).projVz=shot(shots).projVz
endif
`this will ensure the last object entry is cleared so the while loop will stop at the right place
shot(shots).object=0
endif
inc i
endwhile
endif
Return
Obviously need to declare the array type.