Skip to content

Instantly share code, notes, and snippets.

@matthewd673
Created January 7, 2017 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewd673/d50eca25a5026bc42e74cdcee375e144 to your computer and use it in GitHub Desktop.
Save matthewd673/d50eca25a5026bc42e74cdcee375e144 to your computer and use it in GitHub Desktop.
simple collision detection in c#
public static bool detectCollision(Rectangle rect1, Rectangle rect2)
{
if (rect1.X < (rect2.X + rect2.Width) &&
(rect1.X + rect1.Width) > rect2.X &&
rect1.Y < (rect2.Y + rect2.Height) &&
(rect1.Height + rect1.Y) > rect2.Y)
return true;
else
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment