-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB-18-7
125 lines (81 loc) · 2.53 KB
/
B-18-7
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import pyxel
class Ball:
speed = 2
def __init__(self):
self.restart()
def restart(self):
self.x = pyxel.rndi(0, 199)
self.y = 0
angle = pyxel.rndi(30, 150)
self.vx = pyxel.cos(angle)
self.vy = pyxel.sin(angle)
self.t = 0
def move(self):
self.x += self.vx * Ball.speed
self.y += self.vy * Ball.speed
if self.x >= 200 or self.x <= 0:
self.vx *= -1
class Pad:
def __int__(self):
self.x = 100
def move(self):
self.x = pyxel.mouse_x
def catch(self,ball):
if ball.y >= 195 and self.x-20 <= ball.x <= self.x+20 and ball.t == 0:
return True
else:
return False
class Bullet:
def __init__(self, x):
self.x = x
self.y = 200
def move(self):
self.y -= 5
def draw(self):
pyxel.circ(self.x, self.y, 2, 4)
class App:
def __init__(self):
pyxel.init(200,200)
self.score = 0
self.miss = 0
self.ball = Ball()
self.balls = [Ball()]
self.pad = Pad()
self.bullets = []
pyxel.run(self.update, self.draw)
def update(self):
if self.miss >= 10:
return
self.pad.move()
if pyxel.btnp(pyxel.MOUSE_BUTTON_LEFT):
self.bullets.append(Bullet(pyxel.mouse_x))
for bullet in self.bullets:
bullet.move()
for i in self.balls:
i.move()
if i.y >= 200:
if i.t == 0:
self.miss += 1
i.restart()
Ball.speed += 0.5
if self.pad.catch(i):
i.t = 1
self.score += 1
if self.score % 10 == 0:
Ball.speed = 2
self.balls.append(Ball())
def draw(self):
if self.miss < 10:
pyxel.cls(7)
for i in self.balls:
pyxel.circ(i.x, i.y, 10, 6)
for bullet in self.bullets:
bullet.draw()
pyxel.text(10, 10, "score : " + str(self.score), 0)
pyxel.text(10, 20, "miss : " + str(self.miss), 0)
pyxel.rect(self.pad.x-20, 195, 40, 5, 14)
else:
pyxel.cls(0)
pyxel.text(80,100,"game over",7)
pyxel.text(70, 110, "final score : " + str(self.score), 7)
App()