Do you means something like this?
dim enemies[9] //enemy sprites
for k=1 to 9
enemies[k]=CreateSprite(0)
SetSpriteSize(enemies[k],10,10)
SetSpritePosition(enemies[k],random(0,200),random(0,200))
next
hero=CreateSprite(0)
SetSpriteSize(hero,10,10)
SetSpritePosition(hero,50,50)
gotoX as float
gotoY as float
gotoX=50
gotoY=50
do
if GetPointerPressed()
gotoX=GetPointerX()
gotoY=GetPointerY()
endif
if MoveSpriteToPosition(hero,gotoX,gotoY,1.0)
for k=1 to 9
if GetSpriteColision(hero,enemies[k])
print("COLLISION WITH "+str(k)+"!!!")
endif
next
endif
sync()
loop
function MoveSpriteToPosition(sprite,x#,y#,speed#)
ret=0
cx#=GetSpriteX(sprite)
cy#=GetSpriteY(sprite)
len#=sqrt((x#-cx#)*(y#-cy#)) //length of vector
nx#=((x#-cx#)/len#)*speed# //normalised vectors
ny#=((y#-cy#)/len#)*speed#
SetSpritePosition(sprite,cx#+nx#,cy#+ny#)
//MUST ADD CODE TO DETECT IF THE SPRITE HAS GONE PAST THE FINAL POSITION AND IF SO, SET IT TO THE FINAL POSITON
//THE, IF IT'S AT THE FINAL POSITION, RETURN 1
endfunction ret
Note: This code is completely untested, and it won't even work properly, see the last couple of lines for why.
Bascially this is what it theoretically should do though:
1. Create 9 enemy sprites
2. Create player (Hero)
3. in loop, if user clicks, move hero to that position via function
4. function will return 1 if the sprite has reached target location
5. if it has, then scan through all 9 enemies for collision
the only part that definitely doesn't work, is the function checking if you've reached the target location. I also don't know if the function will even work, it's meant to calculate the length of the vector, normalise it and multiply it by the speed, but I don't know if it'll work properly. I don't have time to check it at the moment, but if nobody's got it sorted out my this afternoon, I'll fix it for you