-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
40 lines (32 loc) · 921 Bytes
/
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
from turtle import Screen
from paddle import Paddle
from ball import Ball
import time
PADDLE_RIGHT_ORG_POS = (560,0)
PADDLE_LEFT_ORG_POS = (-570,0)
screen = Screen()
screen.setup(width=1200,height=600)
screen.bgcolor('black')
screen.title('Pong')
screen.tracer(0)
paddle_right = Paddle(PADDLE_RIGHT_ORG_POS)
paddle_left = Paddle(PADDLE_LEFT_ORG_POS)
ball = Ball()
screen.listen()
screen.onkey(key='Up',fun=paddle_right.go_up)
screen.onkey(key='Down',fun=paddle_right.go_down)
screen.onkey(key='w',fun=paddle_left.go_up)
screen.onkey(key='s',fun=paddle_left.go_down)
game_is_on = True
while game_is_on:
screen.update()
time.sleep(0.1) #pause tenscreen to see the ball
ball.ball_move()
#detect collision with top and bottom and boucing
# the top
if ball.ycor() >= 280:
ball.wall_bounce()
# the bottom
if ball.ycor() <= -280 :
ball.wall_bounce()
screen.exitonclick()