-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpong.py
More file actions
39 lines (31 loc) · 807 Bytes
/
pong.py
File metadata and controls
39 lines (31 loc) · 807 Bytes
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
from turtle import Turtle, Screen
from paddle import Paddle
from ball import Ball
import time
# screen setup
screen=Screen()
screen.title("Pong Game")
screen.setup(width=800, height=600)
screen.bgcolor("black")
screen.tracer(0)
# creating and moving paddles
screen.listen()
# right paddle
r_paddle=Paddle((350, 0))
screen.onkeypress(key='Up', fun=r_paddle.move_up)
screen.onkeypress(key='Down', fun=r_paddle.move_down)
# left paddle
l_paddle=Paddle((-350, 0))
screen.onkeypress(key='w', fun=l_paddle.move_up)
screen.onkeypress(key='s', fun=l_paddle.move_down)
# creating ball
ball=Ball()
game_is_on=True
while game_is_on:
time.sleep(0.1)
screen.update()
ball.move()
# detect collision with wall
if ball.ycor()>280 or ball.ycor()< -280:
ball.bounce()
screen.exitonclick()