Basically, I’m recreating the game Pong in Turtle. I’m aware there’s 1000 better languages, modules (I think it’s called interfaces), basically ways to do it but I wanted to take on this challenge.
The first problem I got is that when 1 stick moves up or down, the second can’t and vice versa.
My first thought was to fix it with a thread/process, however since I am pretty new to programming altogether I couldn’t do it.
import turtle
from multiprocessing import Process
ekran = turtle.Screen()
ekran2 = turtle.Screen()
def go_up1():
if palica1.ycor() <= 525 / 3 -5:
palica1.goto(palica1.xcor(), palica1.ycor() + 5)
def go_down1():
if palica1.ycor() >= -525 / 3 + 5:
palica1.goto(palica1.xcor(), palica1.ycor() - 5)
def go_up2():
if palica2.ycor() <= 525 / 3 + -4:
palica2.goto(palica2.xcor(), palica2.ycor() + 5)
def go_down2():
if palica2.ycor() >= -525 / 3 + 4:
palica2.goto(palica2.xcor(), palica2.ycor() - 5)
def prva():
ekran.onkeypress(go_up1, "w")
ekran.onkeypress(go_down1, "s")
ekran.listen()
def druga():
ekran2.onkeypress(go_up2, "o")
ekran2.onkeypress(go_down2,"l")
ekran2.listen()
palica1 = turtle.Turtle()
palica2 = turtle.Turtle()
a = Process(target = prva)
b = Process(target = druga)
a.start()
b.start()
turtle.mainloop()
#this code is partially in my language so don't mind the weird names
I tried the same thing using threads instead of processes and got a not working result but at least there wasn’t any errors lol.
p.s. this is a very shortened and simplified version of everything I did already
Thanks for reading!
2