Yup, you can.
The best way to do it would be to create a loop and check all your bullets that way.
I would set it up into three parts, one part will handle creating the bullet, the other part will handle moving bullets that already exist, and the third will detect if the bullet has hit anything.
To create a bullet you'll need to check if your shoot button is fired like you do in your original code, then you can send your program to a subroutine.
So something like this:
If spacekey() = 1 then GOTO createbullet
For the
createbullet subroutine you'll need to check a range of bullets so you don't accidently create a bullet that exists already. The best way to do this is to define a variable that you'll use as your bullet number and increment it one everytime you create a bullet so then next bullet will have a different number. You should also try and specify a range of numbers so you don't create an infinte amount of bullets using up all your object numbers. So with the example I'm going to show you, you should define the variable
bullet# before you run your game and set it to 800.
So your subroutine should look something like this:
createbullet:
`bullet# is the variable and 800 to 850 is the range of bullets
`so if the bullet number goes over 850 it will reset it to 800
if bullet# = 850 then bullet# = 800
`make your bullet and position it
make object cube bullet#,15
set object collision to boxes bullet#
b3x# = newxvalue(x#,aY#,20)
b3z# = newzvalue(x#,aY#,20)
position object bullet#,x#,0,z#
yrotate object bullet#,aY#
`increment the bullet variable one, so the next time you create
`a bullet it creates a new one
inc bullet#
RETURN
Next you need to move your bullet. This can be done with a loop, I like using a
For loop because its easier for me to work with. What a
For loop will do is repeat a loop a set number of times. In this case we need to repeat it 50 times for all 50 bullets.
So like this:
`the variable t is arbitrary, all you need to check for is the range
`of numbers the bullets are in, this case 800 to 850
for t=800 to 850
`this will check to see if the bullet actually exists, t being
`the bullet number
if object exist(t) = 1
`if the bullet does exist, it will move the bullet forward
move object t, 40
`you can also make some checks for the distance and delete
`the object but this would require an array
endif
next t
And lastly you need to check to see if your bullet has hit something. Using the same concept of moving the bullet all you would need to do is remove the
move object command and replace it with your collision detection code.
So:
`again the variable t is arbitrary
for t=800 to 850
`check if your bullet exists first
if object exist(t) = 1
`then check to see if the bullet hit anything
if object collision(t,0)
`if it does, delete it.
delete object t
endif
endi
next t
I would put all those into subroutines and call them once during your main loop. You may also want to check to see if your bullet already exists when creating it, so your program doesn't run into any errors. And maybe make it a bit more flexible so you can check the bullet distance with an array and delete bullets that are out of range.