|
@@ -31,10 +31,10 @@ class Breakout:
|
31
|
31
|
3, 50, (255, 255, 255))
|
32
|
32
|
|
33
|
33
|
self.bg_c = (0, 0, 0)
|
34
|
|
- self.fg_c = (0, 255, 0)
|
35
|
|
- self.ball_c = (255, 0, 0)
|
36
|
|
- self.paddle_c = (255, 255, 255)
|
37
|
|
- self.text_c = (0, 0, 255)
|
|
34
|
+ self.fg_c = (63, 255, 33) # camp green
|
|
35
|
+ self.ball_c = (251, 72, 196) # camp pink
|
|
36
|
+ self.paddle_c = (255, 255, 0)
|
|
37
|
+ self.text_c = (0, 255, 255)
|
38
|
38
|
|
39
|
39
|
if self.randomInitialAngle:
|
40
|
40
|
random.seed()
|
|
@@ -51,9 +51,12 @@ class Breakout:
|
51
|
51
|
]
|
52
|
52
|
|
53
|
53
|
if self.randomInitialAngle:
|
54
|
|
- angle_degree = random.randrange(-45, 45)
|
|
54
|
+ angle_degree = 0
|
|
55
|
+ while (angle_degree <= 2) and (angle_degree >= -2):
|
|
56
|
+ angle_degree = random.randrange(-45, 45)
|
55
|
57
|
self.ball[2] = -1 * math.sin(angle_degree / 180 * 3.14159)
|
56
|
58
|
self.ball[3] = -1 * math.cos(angle_degree / 180 * 3.14159)
|
|
59
|
+ #print("init", angle_degree, self.ball[2], self.ball[3])
|
57
|
60
|
|
58
|
61
|
def restart(self):
|
59
|
62
|
self.start = time.time()
|
|
@@ -102,6 +105,7 @@ class Breakout:
|
102
|
105
|
if self.lives < 0:
|
103
|
106
|
# game over screen
|
104
|
107
|
return self.scoreText.finished()
|
|
108
|
+ #return True
|
105
|
109
|
|
106
|
110
|
return False
|
107
|
111
|
|
|
@@ -180,13 +184,14 @@ class Breakout:
|
180
|
184
|
return
|
181
|
185
|
|
182
|
186
|
# if hit exactly in the middle the direction of the angle depens on the x-direction it came from
|
183
|
|
- if pos_on_paddle == 0:
|
|
187
|
+ if pos_on_paddle <= 0.01:
|
184
|
188
|
pos_on_paddle = -0.5 if self.ball[3] > 0 else 0.5
|
185
|
189
|
|
186
|
190
|
# small angles in the middle, big angles at the end of the paddle (angle measured against the orthogonal of the paddle)
|
187
|
191
|
angle_degree = 80 * pos_on_paddle / (self.paddle_width/2)
|
188
|
192
|
self.ball[2] = -1 * math.sin(angle_degree/180*3.14159)
|
189
|
193
|
self.ball[3] = -1 * math.cos(angle_degree/180*3.14159)
|
|
194
|
+ #print("paddle", angle_degree, self.ball[2], self.ball[3])
|
190
|
195
|
|
191
|
196
|
|
192
|
197
|
def finishedEndScreen(self):
|
|
@@ -267,7 +272,7 @@ if __name__ == "__main__":
|
267
|
272
|
i = util.getInput()
|
268
|
273
|
t = util.getTarget(i)
|
269
|
274
|
|
270
|
|
- d = Breakout(t, i)
|
|
275
|
+ d = Breakout(t, i, 0.001)
|
271
|
276
|
|
272
|
277
|
# example color modifications
|
273
|
278
|
d.fg_c = (0, 150, 0)
|
|
@@ -276,4 +281,9 @@ if __name__ == "__main__":
|
276
|
281
|
d.text_c = (0, 0, 150)
|
277
|
282
|
d.restart() # re-gen with new colors
|
278
|
283
|
|
279
|
|
- util.loop(t, d.draw)
|
|
284
|
+ def helper():
|
|
285
|
+ d.draw()
|
|
286
|
+ if d.finished():
|
|
287
|
+ d.restart()
|
|
288
|
+
|
|
289
|
+ util.loop(t, helper)
|