Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Renamed Bubble2D class to ObjectOnMap and got rid of random_speed().

  • Loading branch information...
commit 38f037186cd286c074fbb46976b4072cdefc1e72 1 parent 991811b
Al Sweigart authored August 07, 2012

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

  1. 24  square-shooter/square-shooter_makeover.py
24  square-shooter/square-shooter_makeover.py
@@ -74,7 +74,7 @@ def copy(self, vector):
74 74
         self.y = vector.y
75 75
 
76 76
 
77  
-class Bubble2D:
  77
+class ObjectOnMap:
78 78
     """Represents a circular object on the game map with position, radius, and velocity."""
79 79
 
80 80
     def __init__(self, radius):
@@ -103,7 +103,7 @@ def is_out(self):
103 103
         return not (0 < self.pos.x < 1 and 0 < self.pos.y < 1)
104 104
 
105 105
     def collides_with(self, other):
106  
-        """Returns True if this bubble is intersecting with the Bubble2D object passed in for the "other" parameter."""
  106
+        """Returns True if this bubble is intersecting with the ObjectOnMap object passed in for the "other" parameter."""
107 107
         a = self.pos.x - other.pos.x
108 108
         b = self.pos.y - other.pos.y
109 109
         distance = math.sqrt(a * a + b * b)
@@ -117,10 +117,6 @@ def random_position():
117 117
     else:
118 118
         return random.uniform(0.75, 1.0)
119 119
 
120  
-def random_speed(magnitude):
121  
-    """Returns a random float value between -magnitude and magnitude."""
122  
-    return random.uniform(-magnitude, magnitude)
123  
-
124 120
 
125 121
 def make_bubble(kind):
126 122
     if kind == "big":
@@ -133,13 +129,13 @@ def make_bubble(kind):
133 129
         size = 0.05
134 130
         speed = 0.25
135 131
 
136  
-    new_bubble = Bubble2D(size)
  132
+    new_bubble = ObjectOnMap(size)
137 133
     new_bubble.pos = Vector2D(
138 134
         random_position(),
139 135
         random_position())
140 136
     new_bubble.speed = Vector2D(
141  
-        random_speed(speed),
142  
-        random_speed(speed))
  137
+        random.uniform(-speed, speed),
  138
+        random.uniform(-speed, speed))
143 139
     new_bubble.kind = kind
144 140
     return new_bubble
145 141
 
@@ -170,7 +166,7 @@ def init_level(self, level):
170 166
         self.level = level
171 167
         if (level > self.max_level): self.max_level = level
172 168
         if self.ship == None:
173  
-            self.ship = Bubble2D(1.0 / 25)
  169
+            self.ship = ObjectOnMap(1.0 / 25)
174 170
         self.ship.pos = Vector2D(0.5, 0.5)
175 171
         self.ship.speed = Vector2D(0, 0)
176 172
         self.bullet = None;
@@ -230,7 +226,7 @@ def update(self, delta_t):
230 226
             if self.death_timer > 0:
231 227
                 self.death_timer -= delta_t
232 228
             elif self.lives > 0:
233  
-                self.ship = Bubble2D(1.0 / 25)
  229
+                self.ship = ObjectOnMap(1.0 / 25)
234 230
                 self.ship.pos = Vector2D(0.5, 0.5)
235 231
                 self.ship_shield_timer = 6;
236 232
             else:
@@ -294,12 +290,12 @@ def spawn_bubbles(self, parent):
294 290
             self.bubbles.append(b)
295 291
 
296 292
     def spawn_explosion(self, bubble):
297  
-        explosion = Bubble2D(0)
  293
+        explosion = ObjectOnMap(0)
298 294
         explosion.pos.copy(bubble.pos)
299 295
         self.explosions.append(explosion)
300 296
 
301 297
     def spawn_powerup(self, bubble):
302  
-        powerup = Bubble2D(0.03)
  298
+        powerup = ObjectOnMap(0.03)
303 299
         powerup.pos.copy(bubble.pos)
304 300
         powerup.kind = random.choice(("shield", "bullet", "freeze"))
305 301
         powerup.age = 0
@@ -337,7 +333,7 @@ def shoot_at(self, x, y):
337 333
         x -= self.ship.pos.x;
338 334
         y -= self.ship.pos.y;
339 335
 
340  
-        b = Bubble2D(0.01)
  336
+        b = ObjectOnMap(0.01)
341 337
         b.pos.copy(self.ship.pos);
342 338
         b.speed.x = x * 3
343 339
         b.speed.y = y * 3

0 notes on commit 38f0371

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