0
嗨我想做一個簡單的pong遊戲,我遇到了碰撞檢測的麻煩。球沒有登記槳。碰撞檢測不註冊球
function moveBall() {
var rightRadius = ballX + radius;
var leftRadius = ballX -radius;
if (ballX + radius > canvas.width || ballX - radius < 0) {
ballOffX = -ballOffX;
}
/*
The following code is handling the collision of the ball with the plate
*/
if((rightRadius <= (player1.x + paddleWidth))&&(leftRadius >= player1.x) &&(player1.y == ballY + 10)){
ballOffY = -ballOffY;
}
ballX += ballOffX;
ballY += ballOffY;
}
球員球盤?你能展示一個示例圖片嗎? –
我重命名板,希望這有助於。謝謝 – Muffin
您應該使用矢量來檢測碰撞。 – kollein