-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (42 loc) · 1.25 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
52
53
54
55
56
57
58
59
60
61
62
63
64
from turtle import Screen
from paddle import Paddle
from mode import Mode
from ball import Ball
import time
from scoreboard import Score
screen=Screen()
screen.bgcolor("black")
screen.setup(width=800, height=600)
screen.title("Pong")
screen.tracer(0)
m=Mode()
ch=m.choose_mode()
paddle=Paddle()
ball=Ball()
score=Score()
screen.listen()
screen.onkey(paddle.player1moveup,"Up")
screen.onkey(paddle.player1movedown,"Down")
if ch == 'v':
screen.onkey(paddle.player2moveup,"w")
screen.onkey(paddle.player2movedown,"s")
game_is_on=True
while game_is_on:
time.sleep(ball.bspeed)
screen.update()
ball.move()
if ch != 'v': # If computer mode is selected
paddle.computer(ball)
#collicion with wall
if ball.ycor()>280 or ball.ycor() < -280:
ball.bounce_y()
#collision with paddle
if ball.distance(paddle.paddle1[2])<50 and ball.xcor()>320 or ball.distance(paddle.paddle2[2]) <50 and ball.xcor()<-320:
ball.bounce_x()
if ball.xcor() > 380 :
ball.reset_position()
score.l_point()
if ball.xcor() < -380 :
ball.reset_position()
score.r_point()
screen.exitonclick()