Skip to content

Instantly share code, notes, and snippets.

@victorarias
Last active December 14, 2015 23:09
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 victorarias/5163882 to your computer and use it in GitHub Desktop.
Save victorarias/5163882 to your computer and use it in GitHub Desktop.
Simple collision system update
function SimpleCollisionSystem() {
this.update = function update() {
for(var a = 0; a < this.circles.length; a++) {
var circle1 = this.circles[a];
//n * n/2 loop to check for collisions on every other particle
for(var b = a + 1; b < this.circles.length; b++) {
var circle2 = this.circles[b];
circle1.checkCollisionOnAnotherCircle(circle2);
}
circle1.move(); //"walk" the particle
//check for collisions on the canvas border
circle1.checkCollisionOnX(this.canvas.width);
circle1.checkCollisionOnY(this.canvas.height);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment