# Pong Game Why it doesn´t function the collision with the ball

Hi i´m very new with programming, and i´m starting doing projects in python:

``````# pong game
#Part 1:window

import turtle
window= turtle.Screen()
window.title("Ping PoNG")
window.bgcolor("black")
window.setup(width=800, height=600)
window.tracer(0)

# Score
score_A = 0
score_B = 0

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

#pen
pen= turtle.Turtle()
pen.speed(0)
pen.color("white")
pen.penup()
pen.hideturtle()
pen.goto (0, 260)
pen.write ("Player A:0 Player B: 0", align="center", font=("Courier", 24, "normal"))

#Functions
y += 25

y -=25

y += 25

y -= 25

#Keyboard binding
window.listen()

#Main game loop
while True:
window.update()

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

#Border checking
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
score_A += 1
pen.clear()
pen.write ("Player A:{} Player B: {}".format(score_A, score_B), align="center", font=("Courier", 24, "normal"))

if Ball.xcor() < -390:
Ball.goto(0, 0)
Ball.dx *= -1
score_B += 1
pen.clear()
pen.write ("Player A:{} Player B: {}".format(score_A, score_B), align="center", font=("Courier", 24, "normal"))

if Ball.xcor() > 330 and (Ball.ycor() < paddle_B.ycor() + 50 and Ball.ycor() > paddle_B.ycor() - 50):
Ball.dx *= -1
``````

Hi Augusto, you did a good job.
Let’s see why the ball does not bounce off the paddle:
If you notice, the section of the code that handles the collision with paddle is within another condition that has nothing to do with it!

``````    if Ball.xcor() < -390:
Ball.goto(0, 0)
Ball.dx *= -1
score_B += 1
pen.clear()
pen.write("Player A:{} Player B: {}".format(score_A, score_B), align="center", font=("Courier", 24, "normal"))

if Ball.xcor() > 330 and (Ball.ycor() < paddle_B.ycor() + 50 and Ball.ycor() > paddle_B.ycor() - 50):
Ball.dx *= -1
``````

You’ll have to untab this section so it is not dependable on the other, just like this:

``````    if Ball.xcor() < -390:
Ball.goto(0, 0)
Ball.dx *= -1
score_B += 1
pen.clear()
pen.write("Player A:{} Player B: {}".format(score_A, score_B), align="center", font=("Courier", 24, "normal"))