How do I detect a collision?

Asked by At

Whenever the square collides with the circle (in any direction: north, south, east, or west), my code is supposed to increase the score by one, but it is not detecting the collision. I am sure the function is being called, and the function doesn't seem to have any mistakes. What is the problem?

function collisionPoint()
{
    if (playerRight == pointX && playerLeft == pointX - playerWidth && playerTop > pointTop - playerHeight && playerBottom < pointBottom + playerWidth)
    {
        score++;
    }

    if (playerLeft == pointX && playerRight == pointX + playerWidth && playerTop > pointTop - playerHeight && playerBottom < pointBottom + playerWidth)
    {
        score++;
    }

    if (playerTop == pointY && playerBottom == pointY - playerHeight && playerRight < pointRight + playerWidth && playerLeft > pointLeft + playerWidth)
    {
        score++;
    }

    if (playerBottom == pointY && playerTop == pointY + playerHeight && playerRight < pointRight + playerWidth && playerLeft > pointLeft + playerWidth)
    {
        score++;
    }
}

0 Answers