SDL Collision Detection

Started by
9 comments, last by wyrzy 19 years, 7 months ago
I've been fooling around with SDL, I'm curious how people do Collision detection. I'm wondering if its possible to do it by color. So if player 1 runs into a color say "red" its not able to go thru it. If anyone has any ideas on how to do it. It would be greatly appreacted it. Thanks Jason
Advertisement
I'm using swept sphere / sphere for objects and swept sphere / plane to check against the level boundries.

I'm using 3d models / levels with 2d gameplay.

I'm tryin not to use 3d objects. More make a 2d game with 2d graphics. :) not that advanced to make 3d objects at the moment.
I'm tryin not to use 3d objects. More make a 2d game with 2d graphics. :) not that advanced to make 3d objects at the moment.
Why would you want to do pixel based collision detection? that would be very slow checking the color every frame, or even tedious at initization... The simplest method of 2d collision detection I usually use it checking all 4 sides of an object

x = objectLeft
y = objectTop
right = objectLeft + objectWidth
bottom = objectHeight + objectHeight

Just a simple example, it works for simple simple stuff like, pong or breakout, but depends what you are doing.
---------------------------------------------think outside the quadLogic GamesI realized I stay on the pc too long when my wireless mouse died after replacing the batteries...twice
I've done a pong game that way. I found it the best way for sure on that small of a scale game. I'm lookin to do a bigger game almost like a old school type nes racing game, with the whole track on the screen lot sof turns and things. So it would be more indepth. I'm not sure on the best way to do Collision detection on it. Thanks for the replys guys
Define bounding boxes for your sprites (sdl_rect?) and then compare those x, y, x+w, and y+h values together...of course every sprite would have to have multiple bounding boxes depending on what the sprite was, but thats easy.

gib.son
this is what I would do. run all of your images through a masking program. have that program write a data file to compliment the image you loaded. In that data file, replace the your transparent color with 0, and all of your other data with 1's.

Use bounding box collision for rough detections, then to do a refined collision, do this.
find the overlapping area and create a new box.
copy the region from each part of the overlaped area and copy it into the new box.
when doing that step, have the new box's data all set to zero to begin with, and make it += the value of the source. what happens is that if any value in that new box has a value greater than 2, there has been a collision.
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
Thanks guys for the replys. I'll give the suggestions a try and see what I get. I was told to learn vectors and usem for collision detection. So kind of lookin into that also.

i really dont see why you dont just use bounding box. unless you need pixel perfect collision and you have oddly shaped objects (like cones or triangles or something), there really is no need for anything more. what kind of game are you making?
FTA, my 2D futuristic action MMORPG

This topic is closed to new replies.

Advertisement