Skip to content

Instantly share code, notes, and snippets.

@sax1johno
Created April 22, 2016 00:49
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 sax1johno/63079f2bea08b60cb712d49962a5feed to your computer and use it in GitHub Desktop.
Save sax1johno/63079f2bea08b60cb712d49962a5feed to your computer and use it in GitHub Desktop.
this.collidesWith = function(otherObject) {
var width = 2*this.radius;
var height = 2*this.radius;
var translatedX = this.x - radius;
var translatedY = this.y - radius;
if (translatedX < otherObject.x + otherObject.width &&
translatedX + width > otherObject.x &&
translatedY < otherObject.y + otherObject.height &&
height + translatedY > otherObject.y) {
// collision detected!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment