Greetings,
How might one, after clicking a sprite to randomly change its position on the screen to check whether it is colliding with another object and if so, randomly change its position on the screen until it's not.
if GetPointerPressed() = 1
xP = GetPointerX()
yP = GetPointerY()
for i = 0 to 4
if GetSpriteHit( xP, yP ) = SpriteArray[i]
SetSpritePositionByOffset( SpriteArray[i], Random( 20, GetDeviceWidth()-20 ), Random( 100, GetDeviceHeight()-100 ) )
Score = Score + 1
endif
next
Endif
Something like this I presume?
// Create Sprites
// Array of Sprites
Dim SpriteArray[4]
for i = 0 to 4
SprEi = CreateSprite(sprEnemy)
SetSpriteSize( SprEi, 100, -1 )
// Random Position On Screen
SetSpritePositionByOffset( SprEi, Random( 0, GetDeviceWidth() ), Random( 100, GetDeviceHeight()-100 ) )
if GetSpriteCollision( SpriteArray[i], SpriteArray[i] ) = 1
SetSpritePositionByOffset( SprEi, Random( 100, GetDeviceWidth()-100 ), Random( 100, GetDeviceHeight()-100 ) )
else
SetSpritePositionByOffset( SprEi, Random( 100, GetDeviceWidth()-100 ), Random( 100, GetDeviceHeight()-100 ) )
endif
// Add to the array
SpriteArray[i] = SprEi
next
Above is the code used to create the array.
Cheers for any help
DividedV -- YouTube Channel