Skip to content

Commit 0ae4205

Browse files
authored
ping_pong part 1 uploaded
1 parent afeb166 commit 0ae4205

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

ping_pong/main.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from turtle import Turtle,Screen
2+
from paddle import Paddle
3+
from ball import Ball
4+
from scoreboard import Scoreboard
5+
import time
6+
screen=Screen()
7+
tim=Turtle()
8+
k=.1
9+
is_ = True
10+
scoreboard=Scoreboard()
11+
screen.tracer(0)
12+
screen.setup(900,600)
13+
screen.bgcolor("black")
14+
screen.title("PING PONG")
15+
paddle_r=Paddle()
16+
paddle_l=Paddle()
17+
ball=Ball()
18+
screen.listen()
19+
paddle_r.create_bars((420,0))
20+
paddle_l.create_bars((-420,0))
21+
game_on=True
22+
def resume():
23+
if ball.xcor() > 460:
24+
scoreboard.total_l += 1
25+
if ball.xcor() < -460:
26+
scoreboard.total_r += 1
27+
scoreboard.update()
28+
tim.clear()
29+
global k
30+
k = .1
31+
ball.refresh()
32+
33+
34+
while game_on:
35+
scoreboard.update()
36+
time.sleep(k)
37+
screen.update()
38+
screen.onkey(fun=paddle_r.up,key="Up")
39+
screen.onkey(fun=paddle_l.up, key="w")
40+
screen.onkey(fun=paddle_r.down,key="Down")
41+
screen.onkey(fun=paddle_l.down, key="s")
42+
ball.move()
43+
if ball.ycor()>279 or ball.ycor()<-275:
44+
ball.bounce()
45+
if ball.xcor()>390 and ball.distance(paddle_r)<50 or ball.xcor()<-390 and ball.distance(paddle_l)<50:
46+
ball.bounce_pad()
47+
k/=1.2
48+
if ball.xcor()>460 or ball.xcor()<-460:
49+
tim.color("white")
50+
tim.hideturtle()
51+
tim.write("Press Space to Resume",align="center",font=("Algerian",30,"normal"))
52+
screen.onkey(fun=resume, key="space")
53+
54+
screen.exitonclick()

0 commit comments

Comments
 (0)