Python Forum
Trying to make a simple pong game. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: Trying to make a simple pong game. (/thread-20321.html)



Trying to make a simple pong game. - kevindadmun - Aug-05-2019

I wanted to try to make a simple pong game so far it looks good. but i keep getting an error first here is the code. the error that i am getting is (ball.dy = 2) it says that it is not defined i thought it was. am i missing something here.


# noinspection PyUnresolvedReferences
import turtle

wn = turtle.Screen()
wn.title("Pong by kevindadmun9")
wn.bgcolor("black")
wn.setup(width=800, height=600)
wn.tracer(0)

# Paddle A

paddle_a = turtle.Turtle()
paddle_a.speed(0)
paddle_a.shape("square")
paddle_a.color("white")
paddle_a.shapesize(stretch_wid=5, stretch_len=1)
paddle_a.penup()
paddle_a.goto(-350, 0)

# Paddle B
paddle_b = turtle.Turtle()
paddle_b.speed(0)
paddle_b.shape("square")
paddle_b.color("white")
paddle_b.shapesize(stretch_wid=5, stretch_len=1)
paddle_b.penup()
paddle_b.goto(350, 0)
# Ball
Ball = turtle.Turtle()
Ball.speed(0)
Ball.shape("square")
Ball.color("white")
Ball.penup()
Ball.goto(0, 0)
ball.dx = 2
ball.dy = 2

# Function
def paddle_a_up():
y = paddle_a.ycor()
y += 20
paddle_a.sety(y)

def paddle_a_down():
y = paddle_a.ycor()
y -= 20
paddle_a.sety(y)

def paddle_b_up():
y = paddle_b.ycor()
y += 20
paddle_b.sety(y)

def paddle_b_down():
y = paddle_b.ycor()
y -= 20
paddle_b.sety(y)

# Keyboard binding
wn.listen()
wn.onkeypress(paddle_a_up, "w")
wn.onkeypress(paddle_a_down, "s")
wn.onkeypress(paddle_b_up, "Up")
wn.onkeypress(paddle_b_down, "Down")


while True:
wn.update()

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


RE: Trying to make a simple pong game. - kevindadmun - Aug-05-2019

So i fiqured it out i feel dumb now i just had to capitalize the b in ball.