used from my own experience of coding.

import turtle

Window

wind = turtle.Screen() wind.title('Ping Pong Classics') wind.bgcolor('violet') wind.setup(width=800, height=600) wind.tracer(0)

Bar A

bar_A = turtle.Turtle() bar_A.shape('square') bar_A.color('orange') bar_A.shapesize(stretch_wid=5, stretch_len=1) bar_A.penup() bar_A.goto(-350,0)

Bar B

bar_B = turtle.Turtle() bar_B.shape('square') bar_B.color('blue') bar_B.shapesize(stretch_wid=5, stretch_len=1) bar_B.penup() bar_B.goto(350,0)

Ball

ball = turtle.Turtle() ball.shape('circle') ball.color('black') ball.penup() ball.goto(0, 0) ball_x = 0.3 ball_y = 0.3

Score Board

sboard = turtle.Turtle() sboard.shape('square') sboard.color('black') sboard.penup() sboard.hideturtle() sboard.goto(0, 260) sboard.write("Player A: 0 Player B: 0", align="center", font=("Courier", 24, 'normal')) score_a = 0 score_b = 0

Functions

def bar_A_up(): y = bar_A.ycor() y += 30 bar_A.sety(y) def bar_A_down(): y = bar_A.ycor() y -= 30 bar_A.sety(y) def bar_B_up(): y = bar_B.ycor() y += 30 bar_B.sety(y) def bar_B_down(): y = bar_B.ycor() y -= 30 bar_B.sety(y)

Keyboard Bindings

wind.listen() wind.onkeypress(bar_A_up, 'w') wind.onkeypress(bar_A_down, 's') wind.onkeypress(bar_B_up, 'Up') wind.onkeypress(bar_B_down, 'Down')

while True: wind.update()

# Ball Movement
ball.setx(ball.xcor() + ball_x)
ball.sety(ball.ycor() + ball_y)

# Border
if ball.ycor() > 290:
    ball.sety(290)
    ball_y *= -1
elif ball.ycor() < -290:
    ball.sety(-290)
    ball_y *= -1

# Score
if ball.xcor() > 350:
    score_a += 1
    sboard.clear()
    sboard.write("Player A: {} Player B: {}".format(score_a, score_b), align='center', font=('Courier', 24, 'normal'))
    ball.goto(0, 0)
    ball_x *= -1
elif ball.xcor() < -350:
    score_b += 1
    sboard.clear()
    sboard.write("Player A: {} Player B: {}".format(score_a, score_b), align='center', font=('Courier', 24, 'normal'))
    ball.goto(0, 0)
    ball_x *= 1

# Collision with bars
if ball.xcor() < -340 and ball.ycor() < bar_A.ycor() + 50 and ball.ycor() - 50:
    ball_x *= -1
elif ball.xcor() > 340 and ball.ycor() < bar_B.ycor() + 50 and ball.ycor() > bar_B.ycor() - 50:
    ball_x *= -1

// this is my coding. since i dont know how to add my project here, please download pycharm or any other IDE, and select a new project and file and execute this code. there you can play my game either multiplayer, or for one player. this project was made by myself. even if you go to youtube, you can see ping pong tutorials, but mine is a little different from theirs. i used colors and text changes. i know my project may not seem original. i know my project isnt that good, this is my first hackathon. please excuse, and yes i have used coding during school form my hubble space telescope project as well. so i have a basic knowledge of java, html, css, python. all coding was made by myself.

What it does

How we built it

Challenges we ran into

Accomplishments that we're proud of

What we learned

What's next for Python Ping Pong Game

Built With

Share this project:

Updates