Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Moved freeze timer logic into the Ship class, and some other minor ch…

…anges.
  • Loading branch information...
commit d0e100ce11f20546f352a8abdbd5a50d13e7aa8b 1 parent 8b78154
Al Sweigart authored August 08, 2012

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

  1. 28  square-shooter/square-shooter_makeover.py
28  square-shooter/square-shooter_makeover.py
@@ -173,6 +173,7 @@ def __init__(self):
173 173
         super(Ship, self).__init__(0.04) # all Ships are the same size.
174 174
         self._shield_timer = 0
175 175
         self._super_bullet_timer = 0
  176
+        self._freeze_timer = 0
176 177
         self.accel_x = 0 # acceleration rate of the ship
177 178
         self.accel_y = 0
178 179
 
@@ -202,6 +203,8 @@ def update(self, delta_t):
202 203
             self._shield_timer -= delta_t
203 204
         if self.has_super_bullets():
204 205
             self._super_bullet_timer -= delta_t
  206
+        if self.has_freeze():
  207
+            self._freeze_timer -= delta_t
205 208
 
206 209
         super(Ship, self).update(delta_t)
207 210
 
@@ -214,13 +217,21 @@ def has_shield(self):
214 217
         return self._shield_timer > 0
215 218
 
216 219
     def add_super_bullets(self, secs=6):
217  
-        """Extends the time on the ship's shield by secs seconds."""
  220
+        """Extends the time on the ship's super bullets by secs seconds."""
218 221
         self._super_bullet_timer += secs
219 222
 
220 223
     def has_super_bullets(self):
221  
-        """Returns True if this ship currently has a shield, False if it does not have a shield."""
  224
+        """Returns True if this ship currently has a super bullets, False if it does not have a super bullets."""
222 225
         return self._super_bullet_timer > 0
223 226
 
  227
+    def add_freeze(self, secs=6):
  228
+        """Extends the time on the ship's freeze powerup by secs seconds."""
  229
+        self._freeze_timer += secs
  230
+
  231
+    def has_freeze(self):
  232
+        """Returns True if this ship currently has a freeze powerup, False if it does not have a shield."""
  233
+        return self._freeze_timer > 0
  234
+
224 235
     def shoot_at(self, x, y):
225 236
         """Returns a list of bullet objects that were created by the Ship."""
226 237
         x -= self.pos.x;
@@ -254,12 +265,8 @@ class GameWorld:
254 265
     bullet = None
255 266
     ship = None
256 267
 
257  
-    accel_x = 0
258  
-    accel_y = 0
259  
-
260 268
     death_timer = 0
261 269
     finish_timer = 0
262  
-    freeze_timer = 0
263 270
 
264 271
     level = 0
265 272
     score = 0
@@ -277,8 +284,6 @@ def init_level(self, level):
277 284
         self.death_timer = 0
278 285
         self.finish_timer = 0
279 286
 
280  
-        self.freeze_timer = 0;
281  
-
282 287
         del self.bubbles[:]
283 288
         del self.explosions[:]
284 289
         del self.powerups[:]
@@ -300,9 +305,6 @@ def update(self, delta_t):
300 305
         for i in self.powerups:
301 306
             i.age += delta_t
302 307
 
303  
-        if self.freeze_timer > 0:
304  
-            self.freeze_timer -= delta_t
305  
-
306 308
         if len(self.bubbles) == 0:
307 309
             if self.finish_timer > 0:
308 310
                 self.finish_timer -= delta_t;
@@ -311,7 +313,7 @@ def update(self, delta_t):
311 313
                 self.lives += 1
312 314
                 self.init_level(self.level)
313 315
                 return
314  
-        elif self.freeze_timer <= 0:
  316
+        elif not self.ship.has_freeze():
315 317
             for i in self.bubbles:
316 318
                 i.update(delta_t)
317 319
 
@@ -390,7 +392,7 @@ def apply_powerup(self, powerup):
390 392
         elif powerup.kind == "bullet":
391 393
             self.ship.add_super_bullets()
392 394
         elif powerup.kind == "freeze":
393  
-            self.freeze_timer += 6
  395
+            self.ship.add_freeze()
394 396
         else:
395 397
             raise "Bad powerup type"
396 398
         self.score += self.level * 10

0 notes on commit d0e100c

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