-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
51 lines (39 loc) · 1.05 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
from turtle import Screen
import turtle
from paddle import Paddle
from ball import Ball
from scoreboard import ScoreBoard
import time
WIDTH = 800
HEIGHT = 600
screen = Screen()
screen.setup(width=WIDTH,height=HEIGHT)
screen.title("Pong Game")
screen.bgcolor("black")
screen.tracer(0)
r_paddle = Paddle((350,0))
l_paddle = Paddle((-350,0))
ball = Ball()
scoreboard = ScoreBoard()
screen.listen()
screen.onkey(r_paddle.go_up,"Up")
screen.onkey(r_paddle.go_down,"Down")
screen.onkey(l_paddle.go_up,"W")
screen.onkey(l_paddle.go_down,"S")
print(ball.xcor(),ball.ycor())
game_on=True
while game_on:
time.sleep(ball.move_speed )
screen.update()
ball.move()
if ball.ycor() > 280 or ball.ycor() < -280:
ball.bounce_y()
if ball.xcor() > 320 and ball.distance(r_paddle) < 50 or ball.xcor() < -320 and ball.distance(l_paddle) < 50 :
ball.bounce_x()
if ball.xcor() > 380:
ball.reset_position()
scoreboard.l_point()
if ball.xcor() < -380:
ball.reset_position()
scoreboard.r_point()
turtle.done()