File size: 1,405 Bytes
f51af13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
65
66
from turtle import Screen
from net import make_net
from paddle import Paddle
from ball import Ball
from scoreboard import Scoreboard
import time


SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_COLOR = "black"
COORDINATES = [(350, 0), (-350, 0)]
SPEED = 0.09

screen = Screen()
screen.setup(width=SCREEN_WIDTH, height=SCREEN_HEIGHT)
screen.title("That's right, PONG!!! (with SUPER SHOT)")
screen.bgcolor(SCREEN_COLOR)
screen.tracer(0)
make_net()

paddle_1 = Paddle(coordinates=COORDINATES[0])
paddle_2 = Paddle(coordinates=COORDINATES[1])
ball = Ball()
score = Scoreboard()

screen.listen()
screen.onkey(paddle_1.up, "Up")
screen.onkey(paddle_1.down, "Down")

screen.onkey(paddle_2.up, "w")
screen.onkey(paddle_2.down, "s")

game_is_on = True

while game_is_on:
    screen.update()
    time.sleep(SPEED)
    ball.move()

    if ball.ycor() > 280 or ball.ycor() < -280:
        ball.bounce_y()

    if paddle_1.distance(ball) < 50 and ball.xcor() > 320 or paddle_2.distance(ball) < 50 and ball.xcor() < -320:
        ball.bounce_x()
        if SPEED >= .01:
            SPEED -= .009

    if ball.xcor() > 400:
        score.add_point_p2()
        ball.reset()
        SPEED = .09

    if ball.xcor() < -400:
        score.add_point_p1()
        ball.reset()
        SPEED = .09

    if score.score_p1 == 5 or score.score_p2 == 5:
        score.end_game()
        game_is_on = False



screen.exitonclick()