Making a ball fall in PYTHON 3, PYTHON HELP I dont understand how im supposed to
ID: 3740286 • Letter: M
Question
Making a ball fall in PYTHON 3, PYTHON HELP
I dont understand how im supposed to get the ball to continuously fall, and how to make it move when i click in it? I only get it to move every time I click
Question 2a: Write a function named q2a) that creates a simple game where the user tries to keep a red Circle object from falling down to the bottom of a window based on the following parameters: The game is drawn in a 400 x 400-pixel Graphics window with a light grey background A Circle, (filled with red), is drawn in the Graphics window with a radius of 30 and center coordinates:x -200, y-100 Text object containing "Click Anywhere to Begin" centered in the Graphics window Once a mouse click is detected anywhere in the Graphics window, the Text object is removed and using a loop the Circle is animated and starts to fall' and accelerate straight towards the bottom of the window as if affected by gravity. If a mouse click is detected inside the radius of the Circle object: Set the dx movement of the Circle to the difference between the x coordinate of the Circle and the x coordinate mouse click Set the dy movement to -1.1 times the absolute value of the difference between the y coordinate of the Circle and Y coordinate the mouse click o o If the Circle reaches the bottom of the window, the game is over When the game is over, a Text object containing "Game Over - Click to Close" appears centered in the window and the function waits for a mouse click before closing the Graphics window and endingExplanation / Answer
Seems you have created click event inside a while loop which is running infinitely. Can you put the click event outside while loop and try as below
from graphics import *
def q2a():
win = GraphWin("window",400,400)
win.setCoords(0,0,400,400)
win.setBackground("light grey")
#drawing circle
circle = Circle(Point(200,100),30)
circle.setFill("red")
circle.draw(win)
#text
message = Text(Point(200,200),"Click Anywhere to Begin")
message.draw(win)
#clicking
click = win.checkMouse()
message.undraw()
while True:
# click = win.checkMouse()
if click:
#message.undraw()
dy=1
dx = 0
dy *=-9
circle.move(dx,dy)
q2a()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.