Python Forum

Full Version: Newbie Turtle if/then coordinates Problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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"))
The second if block will never be executed. If ball.xcor () returns anything greater that 390 then ball.setx () will reset it to 390. So, when you get to the second if then xcor will always be exactly 390 or below.