|
@@ -14,11 +14,12 @@ import math
|
14
|
14
|
import util
|
15
|
15
|
|
16
|
16
|
class Breakout:
|
17
|
|
- def __init__(self, g, i, ts = 0.04, to = 60.0):
|
|
17
|
+ def __init__(self, g, i, ts = 0.025, to = 60.0, ria = True):
|
18
|
18
|
self.gui = g
|
19
|
19
|
self.input = i
|
20
|
20
|
self.timestep = ts
|
21
|
21
|
self.timeout = to
|
|
22
|
+ self.randomInitialAngle = ria
|
22
|
23
|
|
23
|
24
|
self.paddle_width = 9
|
24
|
25
|
|
|
@@ -35,7 +36,9 @@ class Breakout:
|
35
|
36
|
self.paddle_c = (255, 255, 255)
|
36
|
37
|
self.text_c = (0, 0, 255)
|
37
|
38
|
|
38
|
|
- random.seed()
|
|
39
|
+ if self.randomInitialAngle:
|
|
40
|
+ random.seed()
|
|
41
|
+
|
39
|
42
|
self.restart()
|
40
|
43
|
|
41
|
44
|
def place(self):
|
|
@@ -47,6 +50,11 @@ class Breakout:
|
47
|
50
|
-math.sqrt(.5), # v y
|
48
|
51
|
]
|
49
|
52
|
|
|
53
|
+ if self.randomInitialAngle:
|
|
54
|
+ angle_degree = random.randrange(-45, 45)
|
|
55
|
+ self.ball[2] = -1 * math.sin(angle_degree / 180 * 3.14159)
|
|
56
|
+ self.ball[3] = -1 * math.cos(angle_degree / 180 * 3.14159)
|
|
57
|
+
|
50
|
58
|
def restart(self):
|
51
|
59
|
self.start = time.time()
|
52
|
60
|
self.last = time.time()
|
|
@@ -171,7 +179,7 @@ class Breakout:
|
171
|
179
|
if abs(pos_on_paddle) > self.paddle_width/2:
|
172
|
180
|
return
|
173
|
181
|
|
174
|
|
- # if hit exactly in the middle the direction of the angle depens on the x-direction in came from
|
|
182
|
+ # if hit exactly in the middle the direction of the angle depens on the x-direction it came from
|
175
|
183
|
if pos_on_paddle == 0:
|
176
|
184
|
pos_on_paddle = -0.5 if self.ball[3] > 0 else 0.5
|
177
|
185
|
|