Jun-22-2021, 08:32 AM
(This post was last modified: Jun-22-2021, 09:09 AM by Yoriz.
Edit Reason: Added code tags
)
I'm new to Python & I'm making a Pong-style hockey game and have a problem with the (goal scoring OR puck bouncing) coordinates. When I code the following (see below), the only thing that happens is the puck bounces no matter what the y-coordinate is. I have tried changing the y-coordinates to <= for one or the other; changed the parens placements; (unsuccessfully) tried if/else instead of two if statements; changed the order of the two conditions. In all cases (excepting the if/else which just didn't work at all), the puck bounced, never scored. I am at a loss. Everything else works fine. Thanks for any help! (Problem area highlighted)
if ball.xcor() > 390 and ball.ycor() < 200: # Problem area ball.setx(390) ball.dx *= -1 winsound.PlaySound("puck.wav", winsound.SND_ASYNC) if ball.xcor() > 390 and ball.ycor() > 200: # Problem area winsound.PlaySound("horn.wav ", winsound.SND_ASYNC) ball.goto(0, 0) time.sleep(2) ball.dx *= -1 score_a += 1 pen.clear() pen.write(f"Habs: {score_a} Leafs: {score_b}", align="center", font=("Lucida Console", 24, "bold"))