pon

Made with Python

import turtle
import playsound  # pip install playsound

score_a = 0
score_b = 0
canvas = turtle.Screen()
canvas.title("The Greatest Pong Game Ever")
canvas.bgcolor("#0B5345")
canvas.screensize(600,400)

pa = turtle.Turtle()
pa.color('#48C9B0')
pa.penup()
pa.goto(-250,0)
pa.pendown()
pa.shape('square')
pa.shapesize(stretch_wid=5, stretch_len=1)

pb = turtle.Turtle()
pb.color('#48C9B0')
pb.penup()
pb.goto(250,0)
pb.pendown()
pb.shape('square')
pb.shapesize(stretch_wid=5, stretch_len=1)

ball=turtle.Turtle()
ball.color('#abc123')
ball.penup()
ball.goto(0,0)
ball.pendown()
ball.shape('circle')
ball.penup()

text = turtle.Turtle()
text.penup()
text.goto(0,150)
text.pendown()
text.color("blue")
text.write("READY",align="center",font=("Arial",24,"normal"))
text.hideturtle()
canvas.delay(1000)
text.clear()
text.write("GO!",align="center",font=("Arial",24,"normal"))
canvas.delay(1000)
text.clear()
text.write("Paddle A: {}  Paddle B: {}".format(score_a,score_b),align="center",font=("Arial",24,"normal"))
canvas.delay(1)
speedx=4
speedy=4

def pa_mov_up():
    pa.sety(pa.ycor()+20)
def pa_mov_down():
    pa.sety(pa.ycor()-20)

def pb_mov_up():
    pb.sety(pb.ycor()+20)
def pb_mov_down():
    pb.sety(pb.ycor()-20)

canvas.listen() ## screen will start listening to the keyboard
canvas.onkeypress(pa_mov_up,"w")
canvas.onkeypress(pa_mov_down,"e")
canvas.onkeypress(pb_mov_up,"i")
canvas.onkeypress(pb_mov_down,"o")

while True:
    ball.setx(ball.xcor()+speedx)  #take the current x cor of ball and add 2 pixels to it
    ball.sety(ball.ycor()+speedy)

    if ball.xcor() > 300:
        ball.goto(0,0)
        speedx *= -1
        score_a+=1
        text.clear()
        text.write("Paddle A: {}  Paddle B: {}".format(score_a,score_b),align="center",font=("Arial",24,"normal"))

    elif ball.xcor()< -300:
        ball.goto(0,0)
        speedx *= -1
        score_b+=1
        text.clear()
        text.write("Paddle A: {}  Paddle B: {}".format(score_a,score_b),align="center",font=("Arial",24,"normal"))
    
    if ball.ycor() > 200:
        speedy *= -1
    
    elif ball.ycor() <-200:
        speedy *= -1
    
    if ball.xcor()>240 and (pb.ycor()+50> ball.ycor()> pb.ycor()-50):
        ball.setx(240)
        speedx *= -1
        playsound.playsound("bounce.wav")
    elif ball.xcor()<-240 and (pa.ycor()+50> ball.ycor() > pa.ycor()-50):
        ball.setx(-240)
        speedx *= -1
        playsound.playsound("bounce.wav")
turtle.done()