Pong / main.py
schen357's picture
Create main.py
f51af13
Raw
History Blame Contribute Delete
1.41 kB
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()