Created
November 21, 2017 12:47
-
-
Save writingdeveloper/f08cee8877401862f7cb7ac484d56f2e to your computer and use it in GitHub Desktop.
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
// Check Collision | |
var checkCollision = function(anEnemy) { | |
// check for collision between enemy and player | |
if ( | |
player.y + 131 >= anEnemy.y + 90 && | |
player.x + 25 <= anEnemy.x + 88 && | |
player.y + 73 <= anEnemy.y + 135 && | |
player.x + 76 >= anEnemy.x + 11) { | |
console.log('collided'); | |
// Position player after Collision | |
player.x = 202.5; | |
player.y = 383; | |
} | |
// check if player runs into left, bottom, or right canvas walls | |
// prevent player from moving beyond canvas wall boundaries | |
if (player.y > 383) { | |
player.y = 383; | |
} | |
if (player.x > 402.5) { | |
player.x = 402.5; | |
} | |
if (player.x < 2.5) { | |
player.x = 2.5; | |
} | |
} | |
var checkWin = function(anEnemy) { | |
// check for player reaching top of canvas and winning the game | |
if (player.y + 63 <= 0) { | |
// if player wins, add 1 to the score and level | |
player.x = 202.5; | |
player.y = 383; | |
console.log('you made it!'); | |
ctx.fillStyle = 'white'; | |
ctx.fillRect(0, 0, 505, 350); | |
// pass score as an argument to the increaseDifficulty function | |
score += 1; | |
gameLevel += 1; | |
console.log('current score: ' + score + ', current level: ' + gameLevel); | |
increaseDifficulty(score); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment