Keeping the Whole Circle on the Screen

When we limit the circle to stay within the bounds of the screen, we are not taking the radius into consideration which causes half of the circle to move out of the bounds of our screen. The fix for this is very simple! All we need to do is add/subtract our radius from statement and now the entire circle will always stay on the screen!

        if ((IsKeyDown(KEY_W) || IsKeyDown(KEY_UP)) && circleY > 0 + radius) {
            circleY -= moveSpeed;
        } 
        else if ((IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN)) && circleY < HEIGHT - radius) {
            circleY += moveSpeed;
        }

        if ((IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT)) && circleX > 0 + radius) {
            circleX -= moveSpeed;
        } 
        else if ((IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT)) && circleX < WIDTH - radius) {
            circleX += moveSpeed;
        }
1 Like

I did something like that already for the last lesson, too :slight_smile:

Nice work! It’s great seeing folks take things a step further.

Privacy & Terms