Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- checkPlayerHitBall(player) {
- let playerLeft = player.el.offsetLeft + 32
- let playerRight = player.el.offsetLeft + player.el.offsetWidth - 32
- let playerTop = player.el.offsetTop + 32
- let playerBottom = player.el.offsetTop + player.el.offsetHeight - 32
- let ballLeft = this.ball.ballEl.offsetLeft
- let ballRight = this.ball.ballEl.offsetLeft + this.ball.ballEl.offsetWidth
- let ballTop = this.ball.ballEl.offsetTop
- if(ballRight > playerLeft &&
- ballLeft < playerRight &&
- ballTop > playerTop &&
- ballTop < playerBottom
- ) {
- if(ballRight > playerLeft && ballRight < playerRight) {
- this.ball.dx = -10
- }
- if(ballLeft < playerRight && ballLeft > playerLeft) {
- this.ball.dx = 10
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement