Was following this tutorial but the ball has a strange behaviour when it gets to the top of the screen (it just hangs along the top border).
But also this like has been throwing errors ball.setx(ball.xcor() + ball.dx)
import turtle
wn = turtle.Screen()
wn.title("pong")
wn.bgcolor("white")
wn.setup(width=800, height=600)
wn.tracer(0)
ball = turtle.Turtle()
ball.speed(10)
ball.shape("circle")
ball.color("black")
ball.penup()
ball.goto(100, 0)
ball.dx = 2
ball.dy = -4
while True:
wn.update()
ball.setx(ball.xcor() + ball.dx)
ball.sety(ball.ycor() + ball.dy)
if ball.ycor() > 290:
ball.sety(290)
ball.dy *= 1
if ball.ycor() < -290:
ball.sety(-290)
ball.dy *= -1
if ball.xcor() > 390:
ball.goto(0, 0)
ball.dx *= -1
if ball.xcor() < -390:
ball.goto(0, 0)
ball.dx *= -1