Game Development Reference
In-Depth Information
tures such as the Quad-Trees mentioned in the renderer section, but remember
there are just as many structures and techniques out there to make the best collision
system possible.
I also mentioned that collision is part of physics. As a great benefit, most physics
middleware packages contain collision libraries that will handle the complicated stuff
for you, so as long as you understand what is happening and what you need, you
can easily add in realistic collisions and physical reactions with minimal effort using
libraries such as box2d or Havok .
In the case of this game, we need to consider which collision shapes will be ne-
cessary to implement the system. Thankfully we only need one type, the rectangle,
which simplifies the work needed.
Rectangle collision
Rectangle collision in 2D involves checking if two rectangles overlap or contain each
other. As shown in the following diagram, there are three different scenarios that
need to be detected, and simpler checks will simply combine them all into a single
true/false value; however, collision detection can be extended to specify which state
the collision is (or isn't) in.
So let's create the RectangleCollider class that will handle the collision detec-
tion.
Search WWH ::




Custom Search