Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Improve make_bubble(), and renamed it to bubble_factory().

  • Loading branch information...
commit 113c91dd899e1f41ba4a7154b43a24bf00e267c0 1 parent 38f0371
Al Sweigart authored August 07, 2012

Showing 1 changed file with 10 additions and 13 deletions. Show diff stats Hide diff stats

  1. 23  square-shooter/square-shooter_makeover.py
23  square-shooter/square-shooter_makeover.py
@@ -118,16 +118,13 @@ def random_position():
118 118
         return random.uniform(0.75, 1.0)
119 119
 
120 120
 
121  
-def make_bubble(kind):
122  
-    if kind == "big":
123  
-        size = 0.1
124  
-        speed = 0.1
125  
-    elif kind == "medium":
126  
-        size = 0.075
127  
-        speed = 0.15
128  
-    elif kind == "small":
129  
-        size = 0.05
130  
-        speed = 0.25
  121
+def bubble_factory(kind):
  122
+    #                   (size, speed)
  123
+    kinds  = {'big':    (0.1,   0.1),
  124
+              'medium': (0.075, 0.15),
  125
+              'small':  (0.05,  0.25)}
  126
+
  127
+    size, speed = kinds[kind]
131 128
 
132 129
     new_bubble = ObjectOnMap(size)
133 130
     new_bubble.pos = Vector2D(
@@ -182,7 +179,7 @@ def init_level(self, level):
182 179
         del self.explosions[:]
183 180
         del self.powerups[:]
184 181
         for i in range(level):
185  
-            self.bubbles.append(make_bubble("big"))
  182
+            self.bubbles.append(bubble_factory("big"))
186 183
 
187 184
     def update(self, delta_t):
188 185
         self.handle_collisions(delta_t)
@@ -282,10 +279,10 @@ def spawn_bubbles(self, parent):
282 279
                 new_type = "medium"
283 280
             elif parent.kind == "medium":
284 281
                 new_type = "small"
285  
-            b = make_bubble(new_type)
  282
+            b = bubble_factory(new_type)
286 283
             b.pos.copy(parent.pos)
287 284
             self.bubbles.append(b)
288  
-            b = make_bubble(new_type)
  285
+            b = bubble_factory(new_type)
289 286
             b.pos.copy(parent.pos)
290 287
             self.bubbles.append(b)
291 288
 

0 notes on commit 113c91d

Please sign in to comment.
Something went wrong with that request. Please try again.