Bottom Page

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()
Yoriz wrote May-08-2019, 04:36 PM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  scoring issues in pong wildbill 1 178 Aug-05-2019, 01:48 AM
Last Post: metulburr
  Ping command using python 3.6.5 Martin2998 5 6,128 Dec-05-2018, 06:55 PM
Last Post: wavic
  Ping Code Problem MTom5 1 641 Sep-04-2018, 09:58 PM
Last Post: MTom5
  Python project "pong" without any makefile sylas 5 1,509 Nov-28-2017, 05:55 PM
Last Post: Larz60+
  ping and pong run both well sylas 1 1,056 Sep-24-2017, 05:14 PM
Last Post: sylas
  Ping Sweep help The501stOfNoobPy 5 2,928 Jun-26-2017, 10:22 AM
Last Post: DeaD_EyE

Forum Jump:


Users browsing this thread: 1 Guest(s)