-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
51 lines (42 loc) · 1.22 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
49
50
51
import time
from turtle import Screen, Turtle
from paddle import Paddle
from ball import Ball
from scoreboard import Scoreboard
screen = Screen()
screen.bgcolor("black")
screen.setup(width=800, height=600)
screen.title("Pong Game")
screen.tracer(0)
player_right = Paddle(350, 0)
player_left = Paddle(-350, 0)
ball = Ball(0, 0)
score = Scoreboard()
screen.listen()
screen.onkey(player_right.move_up, "Up")
screen.onkey(player_right.move_down, "Down")
screen.onkey(player_left.move_up, "w")
screen.onkey(player_left.move_down, "s")
game_is_on = True
start_speed = 0.1
while game_is_on:
screen.update()
time.sleep(start_speed)
ball.move()
if ball.ycor() > 280 or ball.ycor() < -280:
ball.bounce_y()
if ball.distance(player_right) < 50 and ball.xcor() > 320 or ball.distance(player_left) < 50 and ball.xcor() < - 320:
ball.bounce_x()
if ball.xcor() > 380:
ball.reset_position()
score.left_score()
start_speed *= 0.9
print(start_speed)
if ball.xcor() < -380:
ball.reset_position()
score.right_score()
start_speed *= 0.9
print(start_speed)
if score.score_right > 9 or score.score_left > 9:
game_is_on = False
screen.exitonclick()