Page 1 of 1

issue with linked list

Posted: Mon Jun 13, 2005 1:20 pm
by decoder
So I've created 5000 or so 16x16 objects on the screen and now want to see if a simple collision detection can be performed without impairing performance too much.
The piece of code below doesn't work for more or less obvious reasons. How can a collision detection be performed against members of the same linked list?

ResetList(Bacter())
While NextElement(Bacter())
ResetList(Bacter())
While NextElement(Bacter())
If SpriteCollision(Bacter()\Image, Bacter()\x, Bacter()\y, Bacter()\Image, Bacter()\x, Bacter()\y)
routines go here
EndIf

Wend

Wend

Posted: Mon Jun 13, 2005 2:22 pm
by freak
You can get a pointer to the current list element, and then loop trough the
list and still access the one element through the pointer at the same time.

Like this:

Code: Select all

ForEach Bacter()
  *Current.<structure of your list> = @Bacter()  ; get the pointer to the current element

  ForEach Bacter() ; loop through the list
    If *Current <> @Bacter()  ; avoid checking against the item itself
      If SpriteCollision(*Current\Image, *Current\x, *Current\y, Bacter()\Image, Bacter()\x, Bacter()\y)
        ; do stuff
      EndIf
    EndIf
  Next Bacter()

  ; very important, set the list to the current element again, so the outer
  ; loop continues as it should
  ChangeCurrentElement(Bacter(), *Current)

Next Bacter()

Posted: Mon Jun 13, 2005 2:39 pm
by decoder
cheers!