Skip to content

Commit 7cfcd6f

Browse files
authored
Create scoreboard.py
1 parent bafd0bb commit 7cfcd6f

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from turtle import Screen
2+
from orbit import Orbit
3+
from ball import Ball
4+
from scoreboard import Scoreboard
5+
import time
6+
7+
window = Screen()
8+
window.setup(width=800, height=600)
9+
window.bgcolor("black")
10+
window.title("Ping Pong Game")
11+
12+
#controlls animation
13+
14+
window.tracer(0)
15+
16+
rorbit = Orbit((350, 0))
17+
lorbit = Orbit((-350, 0))
18+
#ball object
19+
ball = Ball()
20+
scoreboard = Scoreboard()
21+
22+
window.listen()
23+
24+
window.onkey(rorbit.goUp, "Up")
25+
window.onkey(rorbit.goDown, "Down")
26+
27+
window.onkey(lorbit.goUp, "w")
28+
window.onkey(lorbit.goDown, "s")
29+
30+
game_is_on = True
31+
while game_is_on:
32+
time.sleep(ball.Xspeed)
33+
window.update()
34+
ball.move()
35+
36+
#collision detection
37+
if ball.ycor() > 280 or ball.ycor() < -280:
38+
#bounching nature
39+
ball.bounceY()
40+
41+
#detect collison with rorbit
42+
if ball.distance(rorbit) < 50 and ball.xcor() > 320 or ball.distance(lorbit) < 50 and ball.xcor() < -320:
43+
ball.bounceX()
44+
45+
#detect when orbit loses
46+
if ball.xcor() > 380:
47+
ball.resetPosition()
48+
scoreboard.Lpoint()
49+
50+
if ball.xcor() < -380:
51+
ball.resetPosition()
52+
scoreboard.Rpoint()
53+
54+
window.exitonclick()

0 commit comments

Comments
 (0)