Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+3 votes

I am trying to get my circle object to go up once it hits the bar object. I have a function for it, but once the ball hits the bar object it just shakes back and forth on the bar
20 is the radius of the circle object.
I have a class for the circle and the .getYVal() returns the Y value of the centerPoint
The .getY() for the bar is in the bar class and returns the top left y value.

This is what I have for the function so far:

def checkBallAndBar(ball1, bar):

       if ball1.getYVal() + 20 > bar.getY():
             ball1.moveUp()
       else:
             ball1.moveDown()

Does anyone have any suggestions?

asked in CSC201 Spring 2021 by (1 point)

1 Answer

+2 votes

Maybe instead of using an if / else statement, you could create a while statement. The while statement could move the ball up until it hits the bar then outside of the while statement you could move it down. Not sure if this would work the way you want, but it was the first thing that came into my mind!

answered by (1 point)
+1

Ok thank you! I will try it!

...