Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PING PONG GAME
#1
Hello.i wrote a ping pong game by using turtle with multithreading. The code shows no error in the editor but mutltyhreading isnot working probably and i believe i have so many mistakes.Can u make it better somehow pls. Thank you
import turtle

wn = turtle.Screen()
wn.title("Ping pong by Cagatay em")
wn.bgcolor("blue")
wn.setup(width=900, height=600)
wn.tracer(0)  #oyunu hizlandirir silersen cok yavaslar


class PaddleFirst():
    def __init__(self):
        self.pen = turtle.Turtle()
        self.pen.penup()
        self.pen.speed(0)
        self.pen.shape("square")
        self.pen.shapesize(stretch_wid=5, stretch_len=1)
        self.pen.penup()
        self.pen.goto(-350, 0)

    def up(self):
        y = self.pen.ycor()
        y += 20
        self.pen.sety(y)

    def down(self):
        y = self.pen.ycor()
        y -= 20
        self.pen.sety(y)


class PaddleSecond():
    def __init__(self):
        self.pen = turtle.Turtle()
        self.pen.penup()
        self.pen.speed(0)
        self.pen.shape("square")
        self.pen.shapesize(stretch_wid=5, stretch_len=1)
        self.pen.penup()
        self.pen.goto(350, 0)

    def up(self):
        y = self.pen.ycor()
        y += 20
        self.pen.sety(y)

    def down(self):
        y = self.pen.ycor()
        y -= 20
        self.pen.sety(y)



class Ball():
    def __init__(self):

        self.pen = turtle.Turtle()
        self.pen.penup()
        self.pen.speed(0)
        self.pen.shape("circle")
        self.pen.color("Red")
        self.pen.penup()
        self.pen.goto(0, 0)
        self.pen.dx = 00.1
        self.pen.dy = 00.1

    def letsgo(self):
        self.pen.setx(self.pen.xcor() + self.pen.dx)
        self.pen.sety(self.pen.ycor() + self.pen.dy)

    def move(self):
        if self.pen.ycor() > 290:
            self.pen.sety(290)
            self.pen.dy *= -1

        if self.pen.ycor() < -290:
            self.pen.sety(-290)
            self.pen.dy *= -1

        if self.pen.xcor() > 390:
            self.pen.goto(0, 0)
            self.pen.dx *= -1

        if self.pen.xcor() < -390:
            self.pen.goto(0, 0)
            self.pen.dx *= -1


class Wall():
   def moving(self):
        if ball.pen.xcor() > 340 and (ball.pen.ycor() < paddle2.pen.ycor() + 40 and ball.pen.ycor() > paddle2.pen.ycor() - 40):
           ball.pen.dx *= -1
        if ball.pen.xcor() < -340 and (ball.pen.ycor() < paddle1.pen.ycor() + 40 and ball.pen.ycor() > paddle1.pen.ycor() - 40):
            ball.pen.dx *= -1


paddle1 = PaddleFirst()
print(paddle1)
paddle2 = PaddleSecond()
print(paddle2)
ball = Ball()
print(ball)
wall = Wall()


wn.listen()
wn.onkeypress(paddle1.up, "w")
wn.onkeypress(paddle1.down, "s")
wn.onkeypress(paddle2.up, "Up")
wn.onkeypress(paddle2.down, "Down")



while True:
    wn.update() # everytime uptades the screen
    ball.letsgo()
    ball.move()
    wall.moving()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need some guidance on a script to ping a list of ip's cubangt 11 1,822 Aug-10-2023, 02:39 PM
Last Post: snippsat
  non-stop ping script kucingkembar 1 1,355 Aug-23-2022, 06:29 AM
Last Post: menator01
  How to send a pong on websocket-client tomtom 0 3,626 Aug-15-2022, 05:58 AM
Last Post: tomtom
  Problem with my pong game code Than999 8 3,836 May-15-2022, 06:40 AM
Last Post: deanhystad
  Win32\ping.exe windows pops up -very annoying... tester_V 9 3,204 Aug-12-2021, 06:54 AM
Last Post: tester_V
  Looking for discord bot to make loop ping for address ip tinkode 0 1,822 Jul-26-2021, 03:51 PM
Last Post: tinkode
  Ping command using python 3.6.5 Martin2998 6 17,384 Apr-19-2021, 06:24 PM
Last Post: blazejwiecha
  Pong game buss0140 7 4,075 Dec-27-2020, 07:04 AM
Last Post: ndc85430
  GPIO high if network IP has good ping duckredbeard 3 2,328 Oct-12-2020, 10:41 PM
Last Post: bowlofred
  Create a program that PING a list of IPs skaailet 7 6,305 Mar-26-2020, 10:46 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020