Lesson 7 - Collisions with Rectangles

This tutorial will demonstrate how to use rectangular hitboxes to detect collisions in a project.  Images used can be found at the bottom of this page.

If a Rectangle doesn't fit your shape well, you can use a List of Rectangles to better represent your collision zone.  You can also use circular hit 'boxes' (or lists of circular hit boxes) as described in the Collisions with Circles tutorial (which I haven't made yet).

Collision with Rectangular Hitboxes

Here is the solution for this tutorial:

https://github.com/AldworthClass/Monogame-Collision-with-Rectangles-Example

Here is the API for the Rectangle class used throughout the tutorial:

https://docs.monogame.net/api/Microsoft.Xna.Framework.Rectangle.html

Look at the Properties and methods available for Rectangles. 

Download the following images (name them accordingly) and add them to your project using the MGCB Tool:

pac_up.png

pac_right.png

pac_left.png

pac_down.png

hobbit_door.png

coin.png

rock_barrier.png

Collision in Monogame.pdf

Files