Advertisement
zuramai

Untitled

May 8th, 2024 (edited)
1,085
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. checkPlayerHitBall(player) {
  2.         let playerLeft = player.el.offsetLeft + 32
  3.         let playerRight = player.el.offsetLeft + player.el.offsetWidth - 32
  4.         let playerTop = player.el.offsetTop + 32
  5.         let playerBottom = player.el.offsetTop + player.el.offsetHeight - 32
  6.  
  7.         let ballLeft = this.ball.ballEl.offsetLeft
  8.         let ballRight = this.ball.ballEl.offsetLeft + this.ball.ballEl.offsetWidth
  9.         let ballTop = this.ball.ballEl.offsetTop
  10.  
  11.         if(ballRight > playerLeft &&
  12.             ballLeft < playerRight &&
  13.             ballTop > playerTop &&  
  14.             ballTop < playerBottom
  15.         ) {
  16.             if(ballRight > playerLeft && ballRight < playerRight) {
  17.                 this.ball.dx = -10
  18.             }
  19.             if(ballLeft < playerRight && ballLeft > playerLeft) {
  20.                 this.ball.dx = 10
  21.             }
  22.            
  23.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement