Skip to content

Instantly share code, notes, and snippets.

@drFabio
Created December 27, 2017 13:10
Show Gist options
  • Save drFabio/119d3d77fecd6253ca888e6e2628c58b to your computer and use it in GitHub Desktop.
Save drFabio/119d3d77fecd6253ca888e6e2628c58b to your computer and use it in GitHub Desktop.
_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