-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlazypong.kv
executable file
·100 lines (84 loc) · 2.42 KB
/
lazypong.kv
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#:kivy 1.8.0
#:import Win kivy.core.window.Window
#:import Rand random.randint
<PongPaddle>:
size: Win.width / 80, Win.width / 8
canvas:
Color:
rgba: Rand (230, 255)/255.0, Rand (127, 153)/255.0, Rand (30, 127)/255.0, 1
Rectangle:
source: 'data/pong.png'
pos:self.pos
size:self.size
<PongGame>:
id: ping
ball: pong_ball
player1: player_left
player2: player_right
canvas:
Color:
rgba: 0, Rand (200, 255)/255.0, Rand (220, 255)/255.0, 1
Rectangle:
source: 'data/back.jpg'
size: self.size
Rectangle:
pos: self.center_x -5, 0
size: Win.width / 80, self.height
Label:
font_size: 70
center_x: root.width / 4
top: root.top -50
italic: True
text: 'score: ' + str(root.player1.score)
Label:
font_size: 70
center_x: root.width * 3 / 4
top: root.top -50
italic: True
text: 'lives: ' + str(5 - root.player2.score)
PongBall:
id: pong_ball
center: self.parent.center
PongPaddle:
id: player_left
x: root.x + Win.width / 40
center_y: root.center_y
PongPaddle:
id: player_right
x: root.width - self.width - Win.width / 40
center_y: root.center_y
AnchorLayout:
id: end
pos: root.pos
size: root.size
opacity: 0
BoxLayout:
orientation: 'vertical'
padding: '20dp'
spacing: '30dp'
Label:
id: end_label
font_size: min (self.height, self.width) / 3.0
color: 0.686, 0.067, 0.106, 1
bold: True
text: 'Game\nover!'
halign: 'center'
valign: 'middle'
Button:
text: 'Restart'
on_press: root.restart () if end.opacity == 1. else None
font_size: '30dp'
<PongBall>:
size: Win.height / 16, Win.height /16
canvas:
Color:
rgb: Rand (200, 255)/255.0, 0, 0
Ellipse:
source: 'data/ball2.png'
pos: self.pos
size: self.size
<PongMenu>:
canvas:
Rectangle:
source: 'data/back.jpg'
size: self.size