very simple 2D collision detection?

Started by
2 comments, last by benutne 18 years, 11 months ago
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.
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 pointstruct 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

Thanks man. Helped quite a bit.
Whats with the "SC" thing BTW? Its defined in one of my AGB libraries as an int under "General Input/Output Control Structure."

This topic is closed to new replies.

Advertisement