Last active
December 14, 2015 23:09
-
-
Save victorarias/5163882 to your computer and use it in GitHub Desktop.
Simple collision system update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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