Browse Source

fix breakout endless loop and modify default colors

Thomas Buck 1 year ago
parent
commit
af1f8ae328
1 changed files with 18 additions and 8 deletions
  1. 18
    8
      breakout.py

+ 18
- 8
breakout.py View File

31
                                     3, 50, (255, 255, 255))
31
                                     3, 50, (255, 255, 255))
32
 
32
 
33
         self.bg_c = (0, 0, 0)
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
         if self.randomInitialAngle:
39
         if self.randomInitialAngle:
40
             random.seed()
40
             random.seed()
51
         ]
51
         ]
52
 
52
 
53
         if self.randomInitialAngle:
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
             self.ball[2] = -1 * math.sin(angle_degree / 180 * 3.14159)
57
             self.ball[2] = -1 * math.sin(angle_degree / 180 * 3.14159)
56
             self.ball[3] = -1 * math.cos(angle_degree / 180 * 3.14159)
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
     def restart(self):
61
     def restart(self):
59
         self.start = time.time()
62
         self.start = time.time()
102
         if self.lives < 0:
105
         if self.lives < 0:
103
             # game over screen
106
             # game over screen
104
             return self.scoreText.finished()
107
             return self.scoreText.finished()
108
+            #return True
105
 
109
 
106
         return False
110
         return False
107
 
111
 
180
                 return
184
                 return
181
 
185
 
182
             # if hit exactly in the middle the direction of the angle depens on the x-direction it came from
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
                 pos_on_paddle = -0.5 if self.ball[3] > 0 else 0.5
188
                 pos_on_paddle = -0.5 if self.ball[3] > 0 else 0.5
185
 
189
 
186
             # small angles in the middle, big angles at the end of the paddle (angle measured against the orthogonal of the paddle)
190
             # small angles in the middle, big angles at the end of the paddle (angle measured against the orthogonal of the paddle)
187
             angle_degree = 80 * pos_on_paddle / (self.paddle_width/2)
191
             angle_degree = 80 * pos_on_paddle / (self.paddle_width/2)
188
             self.ball[2] = -1 * math.sin(angle_degree/180*3.14159)
192
             self.ball[2] = -1 * math.sin(angle_degree/180*3.14159)
189
             self.ball[3] = -1 * math.cos(angle_degree/180*3.14159)
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
     def finishedEndScreen(self):
197
     def finishedEndScreen(self):
267
     i = util.getInput()
272
     i = util.getInput()
268
     t = util.getTarget(i)
273
     t = util.getTarget(i)
269
 
274
 
270
-    d = Breakout(t, i)
275
+    d = Breakout(t, i, 0.001)
271
 
276
 
272
     # example color modifications
277
     # example color modifications
273
     d.fg_c = (0, 150, 0)
278
     d.fg_c = (0, 150, 0)
276
     d.text_c = (0, 0, 150)
281
     d.text_c = (0, 0, 150)
277
     d.restart() # re-gen with new colors
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)

Loading…
Cancel
Save