[gameprogrammer] Re: Bounding Rectangles

  • From: Stephen Smith <gp@xxxxxxxxxxxxxxxxxxxxxxxx>
  • To: gameprogrammer@xxxxxxxxxxxxx
  • Date: Sun, 02 Sep 2007 08:18:32 +0100

A bounding rectangle is just a simple way of defining the shape of a sprite, to avoid any complex calculations that would be involved if you wanted to check each individual pixel for a collision.

The code to determine a collision would just be something like:-

|public boolean intersects(Rectangle <http://kickjava.com/src/java/awt/Rectangle.java.htm> r)
{
return r.width > 0 && r.height > 0 && this.width > 0 && ||this.||height > 0
    && r.x < x + ||this.||width && r.x + r.width > ||this.||x
    && r.y < y + ||this.||height && r.y + r.height > ||this.||y;
}|

(This is from Java BTW. I hope it makes sense out of context). You just then run this function against each sprite against each other sprite to check for collisions.

Steve



Azeem Zaheer wrote:
Hi,I want to know how to detect collision in 2D Side-Scrolling C++ game like Mario?
without using any game engine or library?
Some basics about how will i know the player is hit by the enemy?
Whats meant by the term 'Bounding Rectangles'?
------------------------------------------------------------------------
Explore the seven wonders of the world Learn more! <http://search.msn.com/results.aspx?q=7+wonders+world&mkt=en-US&form=QBRE>

---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: