Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
73 lines (50 loc) · 1.38 KB
/
Copy pathmain.py
File metadata and controls
73 lines (50 loc) · 1.38 KB
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
65
66
67
68
69
70
71
72
73
import time
from turtle import Screen, Turtle
from paddle import Paddle
from ball import Ball
from scoreboard import ScoreBoard
screen=Screen()
tim=Turtle()
screen.title("Pong Game")
screen.setup(width=800, height=600)
screen.bgcolor("black")
screen.tracer(0)
tim.pencolor("white")
tim.speed(0)
tim. penup()
tim.goto(0,-300)
tim.seth(90)
for _ in range(1,20):
tim.pendown()
tim.fd(20)
tim.penup()
tim.fd(20)
r_paddle=Paddle(x_pos=380,y_pos=0)
l_paddle=Paddle(x_pos=-390,y_pos=0)
ball=Ball()
scoreboard=ScoreBoard()
screen.listen()
screen.onkey(key="Up",fun=r_paddle.move_up)
screen.onkey(key="Down",fun=r_paddle.move_down)
screen.onkey(key="w",fun=l_paddle.move_up)
screen.onkey(key="s",fun=l_paddle.move_down)
is_game_on=True
while is_game_on:
screen.update()
time.sleep(ball.move_speed)
ball.ball_move()
# Detect collision with wall
if ball.ycor() > 280 or ball.ycor() < -280:
ball.bounce_y()
# Detect collision with paddle
if ball.distance(r_paddle) < 56 and ball.xcor() > 355 or ball.distance(l_paddle) < 56 and ball.xcor() < -365:
ball.bounce_x()
# Detection collision with right wall
if ball.xcor() > 386 :
ball.reset_position()
scoreboard.l_point()
# Detection collision with left wall
if ball.xcor() < -389:
ball.reset_position()
scoreboard.r_point()
screen.exitonclick()