Rectangle Collision Detection

This is a simple article on how we can detect if two rectangles are in collision.

You must check this with every frame that is drawn – so it will be part of your main loop.

The based approach is say to have  a rectangular player shape and a rectangular object.

You could take each point of the player rectangle and simply check if it inside the object rectangle.  That will work.

If you remember your coordinate space

These are the rectangles we want to detect.

So you can use a single call to determine if they are in collision:

 * Check if two rectangles collide
 * x_1, y_1, width_1, and height_1 define the boundaries of the first rectangle
 * x_2, y_2, width_2, and height_2 define the boundaries of the second rectangle
boolean rectangle_collision(float x_1, float y_1, float width_1, float height_1, float x_2, float y_2, float width_2, float height_2)
  return !(x_1 > x_2+width_2 || x_1+width_1 < x_2 || y_1 > y_2+height_2 || y_1+height_1 < y_2);

Code Club – Ideas

We now have some initial designs and ideas for the first apps for the code clubs

1 – Platform game – dodgeblock – a working app that will have blocks moving and a player trying to avoid them.

2 – A game thats like the iPhone app – most addictive app.  It should be easy enough to do

3 – A horizontal platform game – the objective is to move from one size left to right

4 – Snake dodge game – using the snake to avoid bubbles or blocks.

All great ideas – we’ll do the development in January – but we need them done!!!! – Homework