Collision detection in SDL...

Started by
2 comments, last by SwindIer 19 years, 6 months ago
Ok I'm making a top view game in SDL. (Similar look to the old RPG's for NES and such but an action game) Well I need help w/ collision detection. Is there anyway in SDL to make it so that if the player sprite hits a certain color on another sprite (ex: color 255, 0, 255 on the background) it will stop? Like not make it so that it stops when it hits the whole sprite.. Just areas of it. (certain colors of it would probably be the easiest way right?) Thanks.
...if you get a penny for your thoughts you're just left w/ a huge pile of useless change.
Advertisement
That is certainly possible, but there are a thousand other ways to do collision detection and pixel collisions are a tad bit expensive all things considered. Have you considered some kind of simple bounding geometry yet (circles, boxes, polygons) ?
What that dude said.

The other way to do it, and it is fairly expensive, is to test each pixel color against each other and when you get the one you want (or should i say dont want), stop the sprite.

Click Here for the getpixel function..so you would getpixel the two pixels you are checking and compare them.

Peice of pie.
gib.son
The getPixel() way seems like it would be the easiest to do. You see I could do boundries, but I have many different backgrounds when you walk around. So I would have to define each boundry for each screen. Doing that would be probably just as taxing on the CPU as the pixel way.. :-\
...if you get a penny for your thoughts you're just left w/ a huge pile of useless change.

This topic is closed to new replies.

Advertisement