Created
December 27, 2017 13:10
-
-
Save drFabio/119d3d77fecd6253ca888e6e2628c58b 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
_checkColision(playerLeft, playerTop, obstacleData, newLeft) { | |
let isWithingHeight = false | |
const wrapperHeight = this._wrapper.offsetHeight | |
const obstacleHeight = wrapperHeight / 2 | |
if (obstacleData.onTop) { | |
if (playerTop <= obstacleHeight) { | |
isWithingHeight = true | |
} | |
} else { | |
if ((playerTop + PLAYER_HEIGHT) >= wrapperHeight - obstacleHeight) { | |
isWithingHeight = true | |
} | |
} | |
if (!isWithingHeight) { | |
return false | |
} | |
if (playerLeft >= newLeft && | |
(playerLeft + PLAYER_WIDTH) <= obstacleData.left + OBSTACLE_WIDTH | |
) { | |
return true | |
} | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment