Created
March 10, 2020 00:19
-
-
Save jason-enstedt/48edf20c7617a368413b7362db6e0314 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 circleCollison(p1x, p1y, r1, p2x, p2y, r2){ | |
let radiusSum; | |
let xDiff; | |
let yDiff; | |
radiusSum = r1 + r2; | |
xDiff = p1x - p2x; | |
yDiff = p1y - p2y; | |
if(radiusSum > Math.sqrt((xDiff * xDiff) + (yDiff * yDiff)) ){ | |
console.log('Player Coord: ' + p1x + ':' + p1y); | |
console.log('Enemy Coord: ' + p2x + ':' + p2y); | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
if(asteroids.length !== 0){ | |
for(let k = 0; k < asteroids.length; k++){ | |
if(circleCollison(ship.x, ship.y, 25, asteroids[k].x, asteroids[k].y, asteroids[k].collisionRadius)){ | |
ship.x = canvasWidth / 2; | |
ship.y = canvasHeight / 2; | |
ship.velX = 0; | |
ship.velY = 0; | |
lives -= 1; | |
console.log(lives); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment