Jump to content
  • Advertisement
Sign in to follow this  

very simple 2D collision detection?

This topic is 4757 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm looking to write a collision detection system for a cheap 2D scroller game. So far, I've got an entity that has a bounding box which consists of ints for top, left, bottom, and right. Rectangular bounding boxes are all I'm going to need. And thats about as far as I've made it so far. I need help with the actual "collision" part now.

Share this post


Link to post
Share on other sites
Advertisement

Hmmmm? I think collision between two axis oriented bounding boxes (that is: rectangles) is the simplest thing on earth :-)

In my last techdemo I've done it that way:


// single point
struct TScrPoint
{
int x, y;
};


// rectangle defined by:
// v1: left down vertex
// v2: right up vertex
struct TRectangle
{
TScrPoint v1, v2;
};

// returns true if they overlap
// you may wish to change ">" and "<" to ">=" and "<="
// you should be able to figure out how does it work :-)
// just draw two rectangles on paper...

bool RectanglesOverlap(const SC :: TRectangle & _first, const SC :: TRectangle & _second)
{
return ( (_first.v1.x < _second.v2.x) && (_first.v2.x > _second.v1.x ) &&
(_first.v2.y > _second.v1.y) && (_first.v1.y < _second.v2.y) );
}




IMHO the hardest part is collision response...


Anyway, I would suggest visiting:

2d game tutorial
Jump n run

Share this post


Link to post
Share on other sites
Whats with the "SC" thing BTW? Its defined in one of my AGB libraries as an int under "General Input/Output Control Structure."

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!