1. You're using the variable n multiple times for different things.
2. The spacekey() should only create bullets and you need a separate routine to handle the bullets.
I changed your usage of "n" a bit. When creating objects in a for..next loop, once you found an available pointer you must exit the loop!
dim Array(10)
for n = 0 to 10
if Array(n) = 0
Array(n) = 1
n = 10 : `<---- This here will cause the loop to end.
`Otherwise all of Array(0~10) will = 1
endif
next n
The counter for bullets are changed from "n" to "Bullets".
print "Bullet# = ";Bullets
A subroutine was added to handle the Bullets. It's still missing a delete bullet when it gets too far or collision.
BulletHandle:
for B = 51 to 149
If Object Exist(B) = 1
move object B,40
endif
next B
return
Hope this helps.
rem ==========================================
autocam off
hide mouse
sync on
sync rate 60
rem ==========================================
rem Objects used
rem --------------
rem Matrix 1 = land
rem Object 2 = plane
rem Object 3 = Camera positon
rem Object 10 - 50 = Buildings
rem Object 51 - 150 = Bullets
cls rgb(255,255,255)
get image 1,0,0,32,32,1
get image 2,0,0,32,32,1
`load image "grass.bmp",1
`load image "building.jpg",2
set camera range 10,2000
make matrix 1,10000,10000,25,25
prepare matrix texture 1,1,1,1
randomize matrix 1,300
set matrix wireframe off 1
rem GRAPHICS
SET WINDOW SIZE 1280,1024
rem Make flying object
make object box 2,150,5,20
make mesh from object 2,2
delete object 2
make object box 2,25,15,100
add limb 2,1,2
`load object "brits.x",2
`make object 2,2,1
position object 2,8000,1000,200
rem Buildings
for b=10 to 50
MAKE OBJECT BOX b,200,100,300
rem position object 1, 5000,1,9000
scale object b,50,300,50
texture object b,2
`color object b,rgb(55,55,55)
ranx=rnd(5000)
ranz=rnd(6000)
position object b, object position x(b),object position y(b),object position z(b)
mheight=GET GROUND HEIGHT(1,object position x(b)+ranx,object position z(b)+ranz)
position object b,object position x(b)+ranx+2500,mheight,object position z(b)+ranz+3000
next b
rem BULLETS
`for n=51 to 151
` make object sphere n,10
` set object n, 1,1,1,2,0,1,0
` color object n, rgb(255,255,0)
` make object collision box n, -2,-2,-2, 2,2,2, 0
` set object to object orientation n,2
`if n=150 then exit
`next n
rem Enviroment
Make light 1
set point light 1, 100,5000,100
color light 1,255,255,0
show light 1
set ambient light 30
if fog available()=1
fog on : fog distance 9000 : fog color rgb(55,55,55)
endif
rem Make drone to mark a back position
make object sphere 3,10
rem Set camera range
set camera range 1,10000
rem Main loop
do
rem Move the plane forward
rem Control free flight object
if downkey()=1 then pitch object up 2,3
if upkey()=1 then pitch object down 2,3
if leftkey()=1 then roll object left 2,3
if rightkey()=1 then roll object right 2,3
if inkey$()="a" then move object 2,20
if inkey$()="z" then move object 2,-5
if inkey$()="o" then n = 0
rem Shoot
if reload = 0
if spacekey()=1
CollisionNumber = 1
for n = 51 to 149
If Object Exist(n) = 0
make object sphere n,20
if CollisionNumber = 1
make object collision box n, -2,-2,-2, 2,2,2, 0
collisionNumber = 0
endif
position object n, object position X(2),object position y(2),object position z(2)
set object to object orientation n,2
reload = 10
n = 149
inc Bullets
endif
next n
endif
else
dec reload
endif
rem Get back position of object for camera
pitch object down 2,11
move object 2,-300
position object 3,object position x(2),object position y(2),object position z(2)
move object 2,300
pitch object up 2,11
rem Place camera and set orientation to object
position camera object position x(3),object position y(3),object position z(3)
set camera to object orientation 2
hide object 3
move object 2,12
move camera 12
x=object angle x(2)
y=object angle y(2)
z=object angle z(2)
`print "Angle X=";x
`print "Angle Y=";y
`print "Angle Z=";z
print "Bullet# = ";Bullets
print "Reload=";reload
set cursor 3,3
gosub BulletHandle
rem Update screen
sync
loop
BulletHandle:
for B = 51 to 149
If Object Exist(B) = 1
move object B,40
endif
next B
return