Main.py:
from turtle import Screen
from Paddle import Paddle
#creating screen
screen = Screen()
screen.screensize(1000, 600)
screen.bgcolor('black')
screen.title('Pong')
screen.tracer(0)
#paddle objects: rPaddle is for the paddle in the right and lPaddle for the left one
rPaddle = Paddle((350, 0)) #the tuple is for the starting position of the paddle object
lPaddle = Paddle((-350, 0))
#screen listeners
screen.listen()
screen.onkey(lPaddle.up, 'w')
screen.onkey(lPaddle.down, 's')
screen.onkey(rPaddle.up, 'Up')
screen.onkey(rPaddle.down, 'Down')
game_on = True
while game_on:
screen.update()
screen.exitonclick()
Paddle.py:
from turtle import Turtle
class Paddle(Turtle):
def __init__(self, starting_coords): #creates the paddles
super().__init__()
self.paddle = Turtle("square")
self.paddle.color('white')
self.paddle.shapesize(5, 1)
self.paddle.penup()
self.paddle.goto(starting_coords)
def up(self):
new_y = self.paddle.ycor() + 40 #makes the paddle move 40 pixels up
self.goto(self.xcor(), new_y)
print("up")
def down(self):
new_y = self.paddle.ycor() - 40 # moves the paddle 40 pixels down
self.goto(self.xcor(), new_y)
print('down')
I left some print statements to make sure the key is being pressed, but still the paddle would not move even if it shows the print statements, so I am very confused about what to do as I am following a tutorial.