Skip to content

Instantly share code, notes, and snippets.

@pedropapa
Created March 20, 2015 18:28
Show Gist options
  • Save pedropapa/ad22e39c960ab91e4c66 to your computer and use it in GitHub Desktop.
Save pedropapa/ad22e39c960ab91e4c66 to your computer and use it in GitHub Desktop.
detectCollisions: function(particle) {
var particles = document.getElementsByClassName('particle');
var particleWidth = particle.clientWidth;
var particleHeight = particle.clientHeight;
var particleTop = parseInt(particle.style.top);
var particleLeft = parseInt(particle.style.left);
var particleBottomLeftNodeX = particleLeft;
var particleBottomLeftNodeY = particleTop + particleHeight;
var particleBottomRightNodeX = particleLeft + particleWidth;
var particleBottomRightNodeY = particleBottomLeftNodeY;
var particleTopLeftNodeX = particleBottomLeftNodeX;
var particleTopLeftNodeY = particleTop;
var particleTopRightNodeX = particleBottomRightNodeX;
var particleTopRightNodeY = particleTopLeftNodeY;
for(node in particles) {
if(typeof particles[node] == 'object') {
if(particles[node].custom.id !== particle.custom.id) {
var nodeWidth = particles[node].clientWidth;
var nodeHeight = particles[node].clientHeight;
var nodeTop = parseInt(particles[node].style.top);
var nodeLeft = parseInt(particles[node].style.left);
var nodeBottomLeftNodeX = nodeLeft;
var nodeBottomLeftNodeY = nodeTop + nodeHeight;
var nodeBottomRightNodeX = nodeLeft + nodeWidth;
var nodeBottomRightNodeY = nodeBottomLeftNodeY;
var nodeTopLeftNodeX = nodeBottomLeftNodeX;
var nodeTopLeftNodeY = nodeTop;
var nodeTopRightNodeX = nodeBottomRightNodeX;
var nodeTopRightNodeY = nodeTopLeftNodeY;
if(((particleTopRightNodeX >= nodeTopLeftNodeX && particleTopRightNodeX <= nodeTopRightNodeX) && (particleBottomRightNodeX >= nodeBottomLeftNodeX && particleBottomRightNodeX <= nodeBottomRightNodeX)) && ((particleTopRightNodeY >= nodeTopLeftNodeY && particleTopRightNodeY <= nodeTopRightNodeY) && (particleBottomRightNodeY >= nodeBottomLeftNodeY && particleBottomRightNodeY <= nodeBottomRightNodeY))) {
console.log('hue')
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment