Explore what CodeHS has to offer for districts, schools, and teachers.
Click on one of our programs below to get started coding in the sandbox!
View All
Consider a game that has a ball colliding with a rectangle. The logic that checks for the collision is the following:
if (ball.getX() >= rect.getX() && ball.getX() <= rect.getX() + rect.getWidth()) { if (ball.getY() + ball.getRadius() >= rect.getY()) { // A collision has occurred! } }
At what points on the ball and rectangle does this logic check for a collision?
The center point on the bottom of the ball and anywhere on the top of the rectangle.
Anywhere on the bottom of the ball and anywhere on the top of the rectangle.
The center point on the top of the ball and anywhere on the bottom of the rectangle.
Anywhere on the ball and anywhere on the rectangle.