Python Forum
Trying to make a simple pong game.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to make a simple pong game.
#1
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)
Reply
#2
So i fiqured it out i feel dumb now i just had to capitalize the b in ball.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation pong paddles wont move skullkat232 5 2,285 Feb-13-2023, 03:53 PM
Last Post: Vadanane
  Problem with my pong code Than999 3 3,369 Oct-22-2021, 08:50 AM
Last Post: Qanima
Brick [PyGame] How to make collisions in isometrick game? Grigory 1 2,275 Jul-01-2021, 01:54 PM
Last Post: Windspar
  Game “Pong” I have problems with the code BenBach18 2 3,450 Jan-10-2021, 05:16 PM
Last Post: michael1789
  [PyGame] Creating Pong in Pygame Russ_CW 2 2,775 Oct-11-2020, 11:56 AM
Last Post: Russ_CW
  Simple game help jarettday 1 3,916 Sep-07-2020, 10:45 PM
Last Post: bowlofred
  Smiley Pong Help Jasmineleroy 6 4,650 May-22-2019, 11:36 AM
Last Post: metulburr
  Simple Game - Choice Based theor 3 2,880 May-10-2019, 08:41 AM
Last Post: beLIEve
  [PyGame] How do I add more balls to basic Pong game? JUtah 2 4,372 Apr-18-2019, 08:40 PM
Last Post: JUtah
  simple pygame game kinglarry0327 0 7,837 Jan-06-2019, 06:18 PM
Last Post: kinglarry0327

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020