-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
45 lines (37 loc) · 1.04 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
from turtle import Turtle, Screen
from paddle import Paddle
from ball import Ball
import time
from score import Score
screen = Screen()
screen.bgcolor("black")
screen.setup(width=800, height=600)
screen.title("Pong")
screen.tracer(0)
r_paddle = Paddle((380, 0))
l_paddle = Paddle((-380, 0))
ball = Ball()
score = Score()
screen.listen()
screen.onkeypress(r_paddle.go_up, "Up")
screen.onkeypress(r_paddle.go_down, "Down")
screen.onkeypress(l_paddle.go_up, "w")
screen.onkeypress(l_paddle.go_down, "s")
game_is_on = True
while game_is_on:
screen.update()
ball.move()
time.sleep(ball.move_speed)
# Detecting collision with wall
if ball.ycor() > 280 or ball.ycor() < -280:
# needs to bounce
ball.wall_bounce()
if ball.distance(r_paddle) <= 30 or ball.distance(l_paddle) <= 30:
ball.paddle_bounce()
if ball.xcor() > 400:
ball.reset_pos()
score.le_score()
if ball.xcor() < -400:
ball.reset_pos()
score.ri_score()
screen.exitonclick()