Skip to content

Instantly share code, notes, and snippets.

@FredrikL
Last active December 23, 2015 04:29
Show Gist options
  • Save FredrikL/6580773 to your computer and use it in GitHub Desktop.
Save FredrikL/6580773 to your computer and use it in GitHub Desktop.
Collision detection!?
for(var i= 0; i < entites.length; i++) {
if(py > (entites[i].y)) {
if(pw > entites[i].x &&
pw < (entites[i].x+10)){
player.x = entites[i].x -player.width;
} else if(player.x >= (entites[i].x+10) &&
player.x < (entites[i].x+20)) {
player.x = entites[i].x + 20;
}
} else {
if(Math.round(py) === Math.round(entites[i].y) &&
pw > entites[i].x &&
player.x < (entites[i].x + 20)) {
player.y = entites[i].y - player.height;
applyPlayerGravity = false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment