Ball Bounds question

So, the && statements for the movement of the ball make sense, and feels like it is much neater when creating the list as it foregoes extra IF statements. But, while I was doing the challenge, I coded in the up and down movements as well, and because I didn’t want to have to manually change the movement speed, I coded in the up and down arrow keys to increase/decrease the movement speed. And to further test this, I added in the left and right arrow keys to increase/decrease the radius of the sphere.

This is where I ran into problems.

When I coded in the x and y upper and lower limits, it doesn’t factor in if the circle was inside the bounds of the window and then increased in size to exceed the window.

I added separate upper/lower x/y IF statements to handle all the bounds and simply referenced the radius for the lower limit and the height/width of the window - the radius as the upper limit. If it exceeds this, it sets the x/y value to the radius/width/height-radius instead.

This way, the circle can move to the edge of the window and increase without the circle ever going outside of the window.

I did run into a problem with trying to add a variable to handle X_limit and Y_limit. I wanted to add:

int circle_xlimit{widthofwindow-circle_rad};
if (circle_x>(circle_xlimit))
{
circle_x=(circle_xlimit);
}

This didn’t work. The left and upper bounds worked, because they were using the circle_rad variable, but when I referenced the circle_xlimit and circle_ylimit variables, it was as if the calculation inside the variable wasnt happening.

Is there a way to perform calculations inside variables? Or am I missing something that I did wrong?

Privacy & Terms