# Pong game issue with ball randomly accelerating

I am currently following a tutorial for a pong game. The code is the same but my ball is randomly changing its speed and the left paddle does not work correctly. I can’t find any solution to it.
Here is the code

`````` #Pong game

import turtle

wn = turtle.Screen()
wn.title("Pong game")
wn.bgcolor("green")
wn.setup(width=800, height=600)
wn.tracer(0)

#object

#object

# Ball
#object
ball = turtle.Turtle()
ball.speed(0)
ball.shape("square")
ball.color("white")
ball.penup()
ball.goto(0, 0)
ball.dx = 0.2
ball.dy = -0.2

y += 20
paddle_a.sety(y) #setting y to the new y

y -= 20
paddle_a.sety(y) #setting y to the new y

y += 20
paddle_b.sety(y)  # setting y to the new y

y -= 20
paddle_b.sety(y)  # setting y to the new y

#keyboard binding
wn.listen()

# Maing game loop
while True:
wn.update()

# Move the ball
ball.setx(ball.xcor() + ball.dx)
ball.sety(ball.ycor() + ball.dy)

# Border checking

# Top and bottom
if ball.ycor() > 290:
ball.sety(290)
ball.dy *= -1

elif ball.ycor() < -290:
ball.sety(-290)
ball.dy *= -1

# Left and right
if ball.xcor() > 350:
ball.goto(0, 0)
ball.dx *= -1

elif ball.xcor() < -350:
ball.goto(0, 0)
ball.dx *= -1

if (ball.xcor() > 340 and ball.xcor() < 350)  and (ball.ycor() < paddle_b.ycor() + 40 and ball.ycor() > paddle_b.ycor() -40):
ball.setx(340)
ball.dx *= -1

if (ball.xcor() < -340 and ball.xcor() > -350)  and (ball.ycor() < paddle_a.ycor() + 40 and ball.ycor() > paddle_a.ycor() -40):
ball.setx(340)
ball.dx *= -1

``````

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.