-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (54 loc) · 1.71 KB
/
main.py
File metadata and controls
58 lines (54 loc) · 1.71 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
from turtle import Turtle, Screen
from padle import Padles
from ball import Ball
import time
from scoreboard import Scoreboard
def linha():
linha_pontilhada.setheading(90)
while linha_pontilhada.ycor() < 400:
linha_pontilhada.pendown()
linha_pontilhada.forward(10)
linha_pontilhada.penup()
linha_pontilhada.forward(10)
screen = Screen(); screen.setup(width=800, height=600); screen.bgcolor("black")
screen.title("PONG")
cyntia = Padles(1)
jordan = Padles(2)
linha_pontilhada = Turtle(); linha_pontilhada.hideturtle(); linha_pontilhada.color("white");linha_pontilhada.penup()
linha_pontilhada.setpos(0, -400);linha_pontilhada.pensize(5); linha()
bola = Ball()
screen.tracer(0)
screen.listen()
screen.onkeypress(cyntia.up,"Up")
screen.onkeypress(cyntia.dn,"Down")
screen.listen()
screen.onkeypress(jordan.up,"w")
screen.onkeypress(jordan.dn,"s")
placar = Scoreboard()
dy = 1
dx = 1
move_speed_ball = 0.1
game_is_on = True
while game_is_on:
time.sleep(move_speed_ball)
screen.update()
bola.movingBall(dx, dy)
if bola.ycor() == 280 or bola.ycor() == -280:
dy *= -1
if bola.xcor() > 350 and bola.distance(cyntia) < 55 or bola.xcor() < -350 and bola.distance(jordan) < 55:
dx *= -1
move_speed_ball *= 0.85
if bola.xcor() > 370 or bola.xcor() < -370:
if bola.xcor() > 370:
placar.l_score += 1
placar.rewrite()
elif bola.xcor() < -370:
placar.r_score += 1
placar.rewrite()
bola.resetBall()
move_speed_ball = 0.1
jordan.resetPadle(2)
cyntia.resetPadle(1)
time.sleep(1)
dx *= -1
screen.exitonclick()