I wrote a code for something similar some time ago.
Here's a modified code which may help you.
#renderer "Basic"
#option_explicit
SetDisplayAspect ( -1 )
SetSyncRate ( 60, 0 )
type shotType
ID as integer
x as float
y as float
speed as float
angle as float
endtype
global shot as ShotType[0] // create list which holds all shots
do
if GetRawMouseLeftReleased()
FireShot(5)
endif
if GetRawMouseRightReleased()
FireShot(1)
endif
Shots()
Print ( "Active Shots: " + str ( shot.length ) )
print ( "LMB to fire 5 shots, RMB to fire 1 shot" )
Sync()
loop
function FireShot ( s as integer )
local i as integer
for i=1 to s
shot.length = shot.length + 1
shot[shot.length].x = 50
shot[shot.length].y = 50
shot[shot.length].ID = CreateSprite ( 0 )
shot[shot.length].angle = random ( 0, 359 )
shot[shot.length].speed = random ( 1, 9 ) / 10.0
SetSpriteAngle ( shot[shot.length].ID, shot[shot.length].angle )
SetSpriteSize ( shot[shot.length].ID, random ( 1, 3 ), -1 )
SetSpriteColor ( shot[shot.length].ID, random ( 0, 255 ), random ( 0, 255 ), random ( 0, 255 ), 255 )
SetSpritePositionByOffset ( shot[shot.length].ID, shot[shot.length].x, shot[shot.length].y )
next i
endfunction
function Shots()
local i as integer
for i=1 to shot.length
if shot[i].x > 100 or shot[i].x < 0 or shot[i].y > 100 or shot[i].y < 0 // shot outside screen?
DeleteSprite ( shot[i].ID ) // yeah, so delete the sprite
shot.remove(i) // and remove the shot from the list
dec i // THIS ONE IS IMPORTANT, BECAUSE WE ARE KILLING LIST ENTRIES WHILE ITERATING THROUGH THE LIST
endif
// calculate new position and move the shot
shot[i].x = shot[i].x + shot[i].speed * cos ( shot[i].angle )
shot[i].y = shot[i].y + shot[i].speed * sin ( shot[i].angle )
SetSpritePositionByOffset ( shot[i].ID, shot[i].x, shot[i].y )
next i
endfunction