Reputation: 43
I'm trying to create a sort of ping pong in python using turtle game where each player drags his paddle by sliding his finger on the screen. I have succeeded to make each player to be able to move his paddle but the players can't move their paddles at the same time, only 1 player can move at a time. Below is my code any help will be appreciated
import turtle
#screen
scn = turtle.Screen()
scn.setup(width = 500, height =1000)
scn.bgcolor("black")
#bar_a
bar_a = turtle.Turtle()
bar_a.color("blue")
bar_a.speed('fastest')
bar_a.penup()
bar_a.goto(-320, 600)
bar_a.right(90)
bar_a.width(20)
bar_a.pendown()
bar_a.forward(1200)
#bar_b
bar_b = turtle.Turtle()
bar_b.color("blue")
bar_b.speed('fastest')
bar_b.penup()
bar_b.goto(320, 600)
bar_b.right(90)
bar_b.width(20)
bar_b.pendown()
bar_b.forward(1200)
#middle
mid =turtle.Turtle()
mid.color('blue')
mid.speed('fastest')
mid.penup()
mid.goto(-320, 0)
mid.pendown()
mid.width(5)
mid.forward(640)
#paddle A
pad_A= turtle.Turtle()
pad_A.shape("square")
pad_A.shapesize(stretch_len =7, stretch_wid =2.5)
pad_A.penup()
pad_A.goto(0, -700)
pad_A.color('grey')
#Drag the paddles
def fxn(x, y):
pad_A.ondrag(None)
pad_A.goto(x, y)
pad_A.ondrag(fxn, 5, True)
def bxn(x, y):
pad_B.ondrag(None)
pad_B.goto(x, y)
pad_B.ondrag(bxn, 5, True)
#paddle B
pad_B= turtle.Turtle()
pad_B.shape("square")
pad_B.shapesize(stretch_len =7, stretch_wid =2.5)
pad_B.penup()
pad_B.goto(0, 700)
pad_B.color('grey')
while True:
scn.update()
pad_A.ondrag(fxn)
pad_B.ondrag(bxn)
Upvotes: 1
Views: 74
Reputation: 15
Maybe you could make it desktop-only with WASD and cursor keys?
If you want to make it mobile-friendly maybe you could make it multiplayer so that you play on different screens but same match?
Upvotes: -1