-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
48 lines (36 loc) · 1.19 KB
/
main.py
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
from turtle import Screen, onkeypress
from paddle import Paddle
from ball import Ball
from scoreboard import Scoreboard
screen = Screen()
screen.setup(width=800,height=550)
screen.bgcolor("black")
screen.title("Pong")
screen.tracer(0)
leftpaddle = Paddle((-380,0),"red")
rightpaddle = Paddle((375,0),"blue")
ball = Ball()
sb = Scoreboard()
screen.listen()
screen.onkeypress(rightpaddle.goup,'Up')
screen.onkeypress(rightpaddle.godown,'Down')
screen.onkeypress(leftpaddle.goup,'w')
screen.onkeypress(leftpaddle.godown,'s')
while True:
ball.move()
screen.update()
if(ball.ycor()>255 or ball.ycor()<-255):
ball.bouncey()
if((ball.xcor()>= 353 and ball.ycor()-rightpaddle.ycor()==60) or (ball.ycor()-leftpaddle.ycor()==60 and ball.xcor()<=-355) ):
ball.bouncey()
if((ball.distance(rightpaddle)<50 and ball.xcor()>=353 ) or (ball.distance(leftpaddle)<50) and ball.xcor()<=-355):
ball.bouncex()
if(ball.xcor()>375):
ball.refresh()
leftpaddle.increase()
sb.l_point()
if(ball.xcor()<-375):
ball.refresh()
rightpaddle.increase()
sb.r_point()
screen.exitonclick()