-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
64 lines (55 loc) · 1.54 KB
/
main.py
File metadata and controls
64 lines (55 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from scoreboard import Scoreboard
from turtle import Screen, Turtle
from paddle import Paddle
from ball import Ball
import time
screen = Screen()
screen.bgcolor("black")
screen.setup(800, 600)
screen.title("Pong")
screen.tracer(0)
paddle_right = Paddle()
paddle_left = Paddle()
scoreboard= Scoreboard()
paddle_left.goto(-350, 0)
paddle_right.goto(350,0)
ball = Ball()
ball.goto(0,0)
ball.setheading(45)
screen.listen()
screen.onkey(paddle_right.moveUp, "Up")
screen.onkey(paddle_right.moveDown, "Down")
screen.onkey(paddle_left.moveUp, "w")
screen.onkey(paddle_left.moveDown, "s")
game_over = False
while game_over == False:
screen.update()
ball.move()
time.sleep(0.05)
if(ball.ycor() > 200 > 0):
ball.bouncetop()
elif(ball.ycor() < -200):
ball.bouncetop()
if(ball.distance(paddle_right) <= 20):
ball.bouncepaddle()
if(ball.distance(paddle_left) <= 20):
ball.bouncepaddle()
if(ball.xcor() >= 400):
scoreboard.score("left")
ball.bouncepaddle()
ball.goto(0,0)
if(ball.xcor() <= -400):
scoreboard.score("right")
ball.bouncepaddle()
ball.goto(0,0)
if(scoreboard.left >=10):
game_over = True
scoreboard.goto(0,0)
scoreboard.clear()
scoreboard.write(f"Left wins!",False, "center", ("Arial",24,"normal"))
if(scoreboard.right >=10):
game_over = True
scoreboard.goto(0,0)
scoreboard.clear()
scoreboard.write(f"Right wins!",False, "center", ("Arial",24,"normal"))
screen.exitonclick()