Depends
Do you plan the array size to be static or dynamic?
Here's a code sample for a dynamic array ( list ), which simulates 'bullets'
#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
local toggle as integer = 0
local lastShot as float
do
if GetRawKeyPressed ( 32 ) then toggle = 1 - toggle // [SPACE] toggles shot emitter
if timer() - lastShot > 0.01 and toggle = 0
FireShot()
lastShot = timer()
endif
Shots()
Print ( ScreenFPS() )
Print ( "Active Shots: " + str ( shot.length ) )
print ( "PRESS SPACE TO TOGGLE BULLETS" )
Sync()
loop
function FireShot()
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 )
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
shot[i].x = shot[i].x + shot[i].speed * cos ( shot[i].angle ) // calculate new position and move the shot
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