2020-09-28

Python3 - Turtle Ping Pong Game, 'unexpected' error

To learn more about Python, i have been learning Turtle. A simple python import that can be used to make games. While there are better options like Pygame, Pglet, etc, I'm still a starter programmer. And i want to start from the ground up. I'm watching videos that teach me how to make games at a basic level, following tutorials, etc.

Anyhow, my code should be working, but the system keeps printing out an error. Is this because the online code executer that I'm using is broken...? Or is my code actually messed up. Help me please

The error message is complaining about line 38 where i say y+=20. Which doesn't make sense because that line is correct. How was the syntax invalid?

import turtle

#Setting up window
window = turtle.Screen()
window.title("Pong")
window.bgcolor("black")
window.setup(width=800, height=500)
window.tracer(0)

#First paddle
paddlea = turtle.Turtle()
paddlea.speed(0)
paddlea.color("white")
paddlea.shape("square")
paddlea.penup()
paddlea.goto(-370, 0)
paddlea.shapesize(stretch_wid=6, stretch_len = 1)

#Second paddle
paddleb = turtle.Turtle()
paddleb.speed(0)
paddleb.color("white")
paddleb.shape("square")
paddleb.penup()
paddleb.goto(370, 0)
paddleb.shapesize(stretch_wid=6, stretch_len = 1)

#Ball
ball = turtle.Turtle()
ball.speed(0)
ball.color("white")
ball.shape("circle")
ball.penup()
ball.goto(0, 0)

#Functions
def paddle_a_up():
  y = paddlea.ycor
  y += 20
  paddlea.sety(y)

window.listen()
window.onkeypress(paddle_a_up, "w")

#Game Loop
while True:
  window.update()


from Recent Questions - Stack Overflow https://ift.tt/337UKCr
https://ift.tt/eA8V8J

No comments:

Post a Comment