Okay, this goes into the beginners forum because it's probably me being very stupid. ;-)
I'm trying to generate a set of coordinates that doesn't overlap with any existing coordinates, but I've been rewriting it far too many times now, and it may just be because it's late, but it doesn't work and I just can't figure out what the devil I'm doing wrong.
I'm sure it can be a lot more efficient, but right now I just want the damn thing to work. Can anyone point out to me what the **** I'm doing wrong? :-)
Function AddEnemies(enemy)
Collission = 1
While Collission = 1
x = Rand(EnemyMinX, EnemyMaxX)
y = Rand(500, 700)
For Local test:Enemies = EachIn Enemies_list
If Not RadiusCollision(x, y, test.x, test.y, 100) And Collission = 1 Then Collission = 0
Next
Wend
Local en:Enemies = New Enemies
Enemies_list.AddLast en
en.enemy = enemy
en.x = x
en.y = y
End Function
Function RadiusCollision:Int(x1, y1, x2, y2, r0)
Local dx = Abs(x1 - x2)
Local dy = Abs(y1 - y2)
Return(Sqr(dX * dX + dy * dy) < r0)
End Function
|