If I did this Forum Post Right on that code part, maybe you can get a idea on shooting bullets. It is a stick gun (rectangular box) shooting round spheres like a fully automatic machine gun. It has 90 bullet capacity before it reloads.
sync rate 0 : sync on : autocam off : hide mouse
dim bullet#(40,40)
dim gpx#(2) : dim gpy#(2) : dim gpz#(2)
make matrix 1,10000,10000,65,65 : position matrix 1,0,0,0
gosub _create_player
bilbul=0
rem ----------- Main Loop
Do
center text 320,20,"Bullets: "+str$(95-bilbul-5)
text 10,10,"Left or Right MOUSECLICK= fire"
text 10,30,"Use MOUSE To Move Camera View"
text 10,50,"Use ARROW KEYS to move player position"
gosub _control_player
gosub _control_camera
gosub _weapon_control
Sync : Loop
rem ----------- End Of Main Loop
rem ------------ PLAYER CONTROL
_control_player:
olx#=x# : olz#=z#
stage=0 : gunlag#=5.0
if upkey()=1
x#=newxvalue(x#,cya#,10.0) : z#=newzvalue(z#,cya#,10.0)
gunlag#=1.1
stage=1
endif
if downkey()=1
x#=newxvalue(x#,cya#,-10.0) : z#=newzvalue(z#,cya#,-10.0)
gunlag#=1.1
stage=1
endif
if leftkey()=1
x#=newxvalue(x#,wrapvalue(cya#-90.0),15.0)
z#=newzvalue(z#,wrapvalue(cya#-90.0),15.0)
gunlag#=1.1
endif
if rightkey()=1
x#=newxvalue(x#,wrapvalue(cya#+90.0),15.0)
z#=newzvalue(z#,wrapvalue(cya#+90.0),15.0)
gunlag#=1.1
endif
return
rem ---------- CAMERA CONTROL
_control_camera:
cya#=wrapvalue(cya#+(mousemovex()/3.0))
cxa#=cxa#+(mousemovey()/3.0)
if cxa#<-45.0 then cxa#=-45.0
if cxa#>45.0 then cxa#=45.0
cx#=newxvalue(x#,cya#,sin(cxa#)*10)
cz#=newzvalue(z#,cya#,sin(cxa#)*10)
position camera cx#,y#+30+walkh#,cz#
rotate camera wrapvalue(cxa#),cya#,0
return
rem ------------ WEAPON CONTROL
_weapon_control:
gga#=wrapvalue((cya#-20))
ggx#=newxvalue(x#,gga#,-1)
ggz#=newzvalue(z#,gga#,-1)
gpdx#=newxvalue(ggx#,wrapvalue((cya#-20)),10)
gpdy#=y#-(sin(cxa#)*10)
gpdz#=newzvalue(ggz#,gga#,10)
gpx#(0)=curvevalue(gpdx#,gpx#(0),gunlag#)
gpy#(0)=curvevalue(gpdy#,gpy#(0),gunlag#)
gpz#(0)=curvevalue(gpdz#,gpz#(0),gunlag#)
position object 2,gpx#(0),gpy#(0)+25,gpz#(0)
xrotate object 2,wrapvalue(0-cxa#)
yrotate object 2,wrapvalue(cya#+180)
rem Control Weapon Firing
if mouseclick()=1 or mouseclick()=2
gunpressed=0
gunobj=2
gunpressed=1
rem -------------- RELOAD FUNCTION
if bilbul>89
wait 10 : bilbul=0 : endif
rem Find free bullet
bf=-1
for b=0 to 40
if bullet#(b,1)=0 then bf=b
next b
rem Trigger bullet
if bf>0
rem ------ BULLET VARIABLE
bilbul= bilbul+1
objid=4+(bf*2)+0
bullet#(bf,1)=1
bullet#(bf,2)=0
tx#=object position x(gunobj)
ty#=object position y(gunobj)
tz#=object position z(gunobj)
txa#=object angle x(gunobj)
tya#=object angle y(gunobj)
position object objid,tx#,ty#,tz#
rotate object objid,txa#,wrapvalue(tya#+90),0
move object objid,0.0
rotate object objid,txa#,tya#,0
move object objid,10
show object objid+0
if object exist(objid+1)=1 then show object objid+1
endif
for adv=1 to 40
objid=3+(adv*2)+0
if adv<>rp and bullet#(adv,1)=1 then move object objid,-25.0
next adv
endif
rem Control bullet movement
for b=0 to 40
rem Bullet alive
if bullet#(b,1)=1
rem Move bullet
objid=4+(b*2)+0
move object objid,-40.0
ex#=object position x(objid)
eh#=object position y(objid)
ez#=object position z(objid)
position object objid+1,ex#,-50-(eh#+50),ez#
rotate object objid+1,wrapvalue(0-object angle x(objid)),object angle y(objid),0
rem Out of Steam
killbullet=0
bullet#(b,2)=bullet#(b,2)+1
if bullet#(b,2)>60 then killbullet=1
rem Kill bullet
if killbullet=1
move object objid,50.0
ex#=object position x(objid)
ez#=object position z(objid)
hide object objid+0
hide object objid+1
bullet#(b,1)=0
endif
endif
next b
return
_create_player:
rem Create Player
make object cube 1,15
hide object 1
rem Create Guns
make object box 2,1,1,50
yrotate object 2,180
fix object pivot 2
set object rotation zyx 2
gpx#(1)=x# : gpy#(1)=y#-100 : gpz#(1)=z#
rem Create Bullet
for l=0 to 40
for b=0 to 1
ll=4+(l*2)+b
make object sphere ll,1
set object rotation zyx ll
hide object ll
next b
next l
rem Set initial player angle
cya#=90.0
return