Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copy #5

Open
wants to merge 12 commits into
base: add-jeongwoo
Choose a base branch
from
31 changes: 24 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import turtle
import winsound


window = turtle.Screen()
window.title("Ping Pong")
window.bgcolor("black")
Expand All @@ -15,6 +16,7 @@
paddle_one.shapesize(stretch_wid=5, stretch_len=1) # 20*5 height
paddle_one.penup()
paddle_one.goto(-350, 0) # (0, 0) is in middle
wid_one = 5

# 2nd Paddle
paddle_two = turtle.Turtle()
Expand All @@ -24,6 +26,7 @@
paddle_two.shapesize(stretch_wid=5, stretch_len=1)
paddle_two.penup()
paddle_two.goto(350, 0) # (0, 0) is in middle
wid_two = 5

# Ball
ball = turtle.Turtle()
Expand Down Expand Up @@ -53,25 +56,25 @@
# movement of paddle
def paddle_one_up():
y = paddle_one.ycor() # coordinates
y += 30
y += 50
paddle_one.sety(y)


def paddle_one_down():
y = paddle_one.ycor() # coordinates
y -= 30
y -= 50
paddle_one.sety(y)


def paddle_two_up():
y = paddle_two.ycor() # coordinates
y += 30
y += 50
paddle_two.sety(y)


def paddle_two_down():
y = paddle_two.ycor() # coordinates
y -= 30
y -= 50
paddle_two.sety(y)


Expand All @@ -91,6 +94,11 @@ def paddle_two_down():
# Ball Movement
ball.setx(ball.xcor() + ball.dx)
ball.sety(ball.ycor() + ball.dy)

if score_one == 5:
exit()
elif score_two == 5:
exit()

# Ball's Border checking
if ball.ycor() > 290:
Expand All @@ -114,6 +122,12 @@ def paddle_two_down():
write_score.clear()
write_score.write("Player One: {} Player Two: {}".format(score_one, score_two), align="center",
font=("Courier", 24, "normal"))

if (wid_one != 1) :
wid_one -= 1
wid_two += 1
paddle_one.shapesize(stretch_wid=wid_one, stretch_len=1)
paddle_two.shapesize(stretch_wid=wid_two, stretch_len=1)

if ball.xcor() < -390: # past the paddle
ball.goto(0, 0)
Expand All @@ -126,6 +140,11 @@ def paddle_two_down():
write_score.clear()
write_score.write("Player One: {} Player Two: {}".format(score_one, score_two), align="center",
font=("Courier", 24, "normal"))
if (wid_two != 1) :
wid_two -= 1
wid_one += 1
paddle_two.shapesize(stretch_wid=wid_two, stretch_len=1)
paddle_one.shapesize(stretch_wid=wid_one, stretch_len=1)

# Collisions b/w ball & paddle

Expand All @@ -140,6 +159,4 @@ def paddle_two_down():
ball.setx(-340)
ball.dx *= -1.05
ball.dy *= 1.05
winsound.PlaySound("bounce.wav", winsound.SND_ASYNC)


winsound.PlaySound("bounce.wav", winsound.SND_ASYNC)