Another way to do it is to have all of your sprites in X-sorted and Y-sorted
linked lists. The list only changes when one sprite moves past another one,
or when you add/remove a sprite, and you only have to change a couple of
pointers when that happens. But the big benefit it gives you is that you
know exactly what the closest sprite in the X and Y direction is, so you
only have to look at the closest couple of sprites in each direction, and
only when a sprite is moving.
> -----Original Message-----
> From: Phantasm4489 [mailto:
phantasm4489@...]
> Sent: Sunday, October 03, 2004 6:15 AM
> To:
gbadev@yahoogroups.com
> Subject: RE: [gbadev] Character collision systems
>
>
>
> You could use the two techniques you describe at the same time, by having
> a
> collision map which is of a lower resolution than the spite movement.
>
>
>
> so have a collision map which is say on eight pixel boundaries and each
> time
> an object moves you write the object number into the collision map at the
> relevant place.
>
> Then you will know which sprites you need to check rather than looping
> through all of them.
>
>
>
> Depending on the size of the collision you choose, you may also have to
> consider that there could be more than 1 object in any location.
>
> _____
>
> From: Palamon 3 [mailto:
palamon_3@...]
> Sent: 03 October 2004 04:37
> To:
gbadev@yahoogroups.com
> Subject: [gbadev] Character collision systems
>
>
>
>
> Hi,
>
> I've been trying to figure out a good way to detect if
> two objects touch each other in an action game like
> mario brothers.
>
> The first game I am making, I wanted to take the easy
> road so I have the sprite characters simply move in 8
> pixel increments, so they always stop aligned with the
> background tiles, just like in the Pokemon games. I
> keep track of the different sprite characters through
> creating a big 2d array about the size of the
> background array, and I simply keep track of where the
> different sprite characters are by putting markers on
> the game map based on their xy coordinates so is is
> easy to see if they collide with anything by simply
> checking the xy coordinates in the map array that is
> right next to the other sprite character.
>
> It's an easy and quick way to keep track of the
> different locations and see if the different sprite
> characters collide with each other, etc.
>
> However this only works for games that have only a few
> set spots where the sprite characters can be, not
> games like mario and other action games where your
> character can move pixel by pixel. I'm afraid the map
> array becomes too big to be the best option for the
> job, plus you have to fill up every pixel of the map
> array that the sprite takes up, which will slow it
> down.
>
> The only other option I can think of is to scroll
> through a list of all the sprites on screen and check
> their xy coordinates and the sprite width/height to
> see if it overlaps the sprite character you are
> checking to see if those sprites collide or not. I'm
> hesitant to do this because I'm afraid it will be too
> slow when the sprite list is a little large since it
> has to run though all the sprite characters and their
> positions every time something moves.
>
>
> I was wondering what programming techniques you all use.