I am trying to make the game Pong. I have everything (except moving the ball) set up but when I run it I can't move both paddles at the same time. Does anybody know what I need to do?
import time
import turtle
#window
Wn_width = 800
Wn_height = 600
Wn = turtle.Screen()
Wn.setup(Wn_width, Wn_height)
Wn.tracer(0)
Title = turtle.title("Pong")
Background_color = turtle.bgcolor("black")
#bats and ball
bat1 = turtle.Turtle("square")
bat1.color("white")
bat1.shapesize(3, 1)
bat1.penup()
bat1.setpos(360,0)
bat2 = turtle.Turtle("square")
bat2.color("white")
bat2.shapesize(3, 1)
bat2.penup()
bat2.setpos(-360, 0)
bal = turtle.Turtle("circle")
bal.color("white")
bal.penup()
#up down
def up():
bat1.sety(bat1.ycor() + 5)
if bat1.ycor() > 260:
bat1.sety(bat1.ycor() -5)
def down():
bat1.sety(bat1.ycor() - 5)
if bat1.ycor() < -250:
bat1.sety(bat1.ycor() + 5)
def up2():
bat2.sety(bat2.ycor() + 5)
if bat2.ycor() > 260:
bat2.sety(bat2.ycor() - 5)
def down2():
bat2.sety(bat2.ycor() - 5)
if bat2.ycor() < -250:
bat2.sety(bat2.ycor() + 5)
Wn.onkeypress(up, "Up")
Wn.onkeypress(down, "Down")
Wn.onkeyrelease(up, "Up")
Wn.onkeyrelease(down, "Down")
Wn.onkeypress(up2, "w")
Wn.onkeypress(down2, "s")
Wn.onkeyrelease(up2, "w")
Wn.onkeyrelease(down2, "s")
Wn.listen()
#main loop
while True:
Wn.update()
time.sleep(0.01)
Each paddle moves perfectly fine on its own, but when I try to move them simultaneously, for example while holding the "up" button, pressing the "w" button - the first paddle will just stop and the second will start moving. How can I be able to press both "up" (or "down") and "w" (or "s") at the same time and have both paddles move?