Question about pong with turtle tutorial in Quincy's newsletter

Hello
I enjoyed reading Shane Duggan’s tutorial on building a pong game using turtle.

However, i want to understand it before I code along, and I cant see in the code where the movement of the ball is coming from. dx and dy are not set for the ball. there is a ‘ball_speed’ value in game_rules, but it is never used. Is there a section missing, or am I missing something?

Thanks for any help!

These lines are about the ball movement


paddle1.sety(paddle1.ycor() + paddle1.dy)
    paddle2.sety(paddle2.ycor() + paddle2.dy)
    ball.setx(ball.xcor() + ball.dx)
    ball.sety(ball.ycor() + ball.dy)

I include the top two lines to help you find the context of the two bottom lines that set the ball movement .

Thanks for responding.
So paddle1.dy is set when the paddle object is defined, but ball.dy is not set when the ball is defined, so it looks like ball.sety(ball.ycor() + ball.dy) would set y to ball.ycor() + an undefined value.
I suspect it has something to do with ‘ball_speed’, which is defined under game rules but never referenced.

I am pretty new to python, so I’m happy to be told i’m misunderstanding something!
Thanks again

1 Like

I can’t find that setting either. It is possible it was missed.

1 Like

thanks Randell, I’m glad i was reading it correctly. So I can see how I could set ball.dx based on ball_speed, but I’m unclear how movement would be achieved on the y axis. Seems like the ball would just ping left to right.

I remember the original game introduced y axis movement if the paddle was moving when it made contact with the ball.

1 Like

Looks like I’m having the same issue. this is the error I’ve been getting:
AttributeError: ‘Turtle’ object has no attribute ‘dx’

yeah, annoying right! I’m sure it’s not that hard, and surely educational, to figure it out though. I dont have any spare time just now, but if you do get anywhere with it please share! setting dx would be easy i think, but see my comment abovr about introducing y movement. good luck :slightly_smiling_face:

yeah I fixed it by adding
ball.dx = 0
ball.dy = 0

and then putting all the conditionals in a while True loop. But it’s still got a lot of bugs to work out. This tutorial was not vetted at all. Now the program runs but nothing works. Github solution using Turtle Here is a much better example.

i tried to dm the author via the only deets given, but the account is a bot :slight_smile:

Thanks for sharing the other example, i really want to build this when i get a minute!

No problem! There’s also this FCC Youtube Tutorial which might be a lot more informative. I haven’t watched it yet myself.

1 Like

Haha, this tutorial bought to you by ChatGPT!

2 Likes

i think you are probably right. kind of impressive and depressing at the same time…

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