i believe v2 will get this.
or in tier2 you have more features through c++
in current v1 i use a function that give me a free array index.
in this you can also re dim in steps if u need more entrys.
deleting is just empty the user defined type.
i often have a spr (sprite id) property, if this 0 then this entry is free.
if i want do something with a entry i just give the function the index.
tier1 is unfortunately not object-oriented
example with fix array
rem
rem AGK Application 1.08 19
rem
//MR Laser Shot
SetPhysicsCCD( 1 )
setphysicsgravity(0,0)
dim list[10]
global listindex
listindex=0
dim listtarget[100]
Targets()
sprShip=createsprite(0)
setspritepositionbyoffset(sprShip,50,50)
do
print(screenfps())
print(GetManagedSpriteCount())
mx#=getpointerx()
my#=getpointery()
if e then e=e-1
if getpointerstate()=1 and e=0
Laser(sprShip,mx#,my#)
e=3
endif
MoveTo(sprShip,mx#,my#)
Colli()
sync()
loop
end
function Targets()
for i=1 to 100
x#=random(0,100)
y#=random(0,100)
spr=createsprite(0)
setspritepositionbyoffset(spr,x#,y#)
setspritesize(spr,1,1)
//setspritegroup(spr,10)
SetSpritePhysicsOn(spr, 1)
SetSpritePhysicsIsSensor(spr,1)
listtarget[i]=spr
next
endfunction
function MoveTo(spr,mx#,my#)
x#=getspritexbyoffset(spr)
y#=getspriteybyoffset(spr)
s#=25.0/60.0
c=0
if abs(x#-mx#)<7.5
else
if x#>mx#
x#=x#-s#
c=1
elseif x#<mx#
x#=x#+s#
c=1
endif
endif
if abs(y#-my#)<7.5 or my#<getvirtualheight()/2.0
else
if y#>my#
y#=y#-s#
c=1
elseif y#<my#
y#=y#+s#
c=1
endif
endif
if c then setspritepositionbyoffset(spr,x#,y#)
endfunction
function Laser(spr,mx#,my#)
dx#=mx# - GetSpriteXByOffset(spr)
dy#=my# - GetSpriteYByOffset(spr)
drawline(mx#,my#,GetSpriteXByOffset(spr),GetSpriteyByOffset(spr),255,255,0)
angle# = ATanfull(dx#,dy#)
l#=sqrt(dx#*dx# + dy#*dy#)
if l#<1.0 then l#=1.0
//dirx# = sin(angle#)
//diry# = -cos(angle#)
dirx# = dx# / l#
diry# = dy# / l#
startx#= GetSpriteXByOffset(spr) + (dirx# * 1.0)
starty#= GetSpriteYByOffset(spr) + (diry# * 1.0)
FORCE# = 100.0
forcex# = dirx# * FORCE#
forcey# = diry# * FORCE#
index=GetLaserIndex()
if index=>0
//print(index)
sprLaser=CreateSprite(0)
//setspritegroup(sprLaser,1)
setspritecolor(sprLaser,255,0,0,255)
setspritetransparency(sprLaser,0)
setspritesize(sprLaser,1,10)
setspriteoffset(sprLaser,0.5,5.0)
setspritepositionbyoffset(sprLaser,startx#, starty#)
setspriteangle(sprLaser,angle#)
SetSpriteDepth(sprLaser,200)
SetSpritePhysicsOn(sprLaser, 2)
SetSpritePhysicsCOM( sprLaser, 0, 0 )
SetSpritePhysicsIsBullet(sprLaser, 1 )
SetSpritePhysicsDamping(sprLaser, 0.1)
SetSpritePhysicsfriction(sprLaser, 0.1)
SetSpritePhysicsCanRotate(sprLaser,0)
//setspritephysicsmass(sprLaser,0.1)
SetSpritePhysicsIsSensor(sprLaser,1)
SetSpritePhysicsRestitution(sprLaser, 0.01)
//SetSpritePhysicsImpulse(sprLaser, startx#, starty#, forcex#,forcey# )
SetSpritePhysicsangularVelocity(sprLaser,0)
SetSpritePhysicsVelocity(sprLaser,forcex#, forcey#)
list[index]=sprLaser
endif
endfunction
function GetLaserIndex()
ret=-1
for i=0 to 10
if list[i]=0
ret=i
exit
endif
next
endfunction ret
function Colli()
for i=0 to 10
spr=list[i] //Laser
if getspriteexists(spr)
c=GetSpriteFirstContact(spr)
do
if c=0 then exit
sprHit=GetSpriteContactSpriteID2()
//if getspritegroup(sprHit)=xy
if sprHit<>0
if DeleteTarget(sprHit)=1
endif
endif
c=GetSpritenextContact()
loop
//in Screen? in welt coordinaten!
if IsSpriteinScreen( spr ) =0
DeleteLaser(i)
endif
endif
next
endfunction
function IsSpriteinScreen(spr)
x1# = screenToWorldX(0)
y1# = screenToWorldY(0)
x2# = screenToWorldX(getVirtualWidth())
y2# = screenToWorldY(getVirtualHeight())
ret = getSpriteInBox(spr,x1#,y1#,x2#,y2#)
endfunction ret
function DeleteLaser(i)
deletesprite(list[i])
list[i]=0
endfunction
function DeleteTarget(spr)
ret=0
for i=1 to 100
sprTarget=listtarget[i] //Target
if sprTarget=spr
deletesprite(sprTarget)
listtarget[i]=0
ret=1
exit
endif
next
endfunction ret
AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670