Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refactoring handle_collisions()

  • Loading branch information...
commit 63baedb58bbaaf4730606e4ba36c2534fd8e1156 1 parent 70f7b17
Al Sweigart authored August 09, 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
@@ -357,7 +357,7 @@ def handle_collisions(self, delta_t):
357 357
             if self.bullet != None and self.bullet.collides_with(b):
358 358
                 self.bubbles.remove(b)
359 359
                 if self.ship != None and not self.ship.has_super_bullets():
360  
-                    self.bullet = None
  360
+                    self.bullet = None # delete the non-super bullet when it hits a bubble
361 361
                 else:
362 362
                     # Push it along or it will just
363 363
                     # destroy the newly formed bubbles.
@@ -367,26 +367,23 @@ def handle_collisions(self, delta_t):
367 367
                 self.powerups.extend(spawned_powerups)
368 368
                 self.spawn_explosion(b)
369 369
                 self.mark_score(b)
370  
-                if len(self.bubbles) == 0:
  370
+                if not len(self.bubbles):
371 371
                     self.afterfinish_timer = 3
372 372
                 break
373  
-            elif self.ship != None:
374  
-                if not b.collides_with(self.ship):
375  
-                    continue
376  
-                if self.ship.has_shield():
377  
-                    continue
  373
+
  374
+            # check if the bubble has hit the ship
  375
+            if self.ship != None and b.collides_with(self.ship) and not self.ship.has_shield():
378 376
                 self.spawn_explosion(self.ship)
379 377
                 self.ship = None
380 378
                 self.lives -= 1
381 379
                 self.afterdeath_timer = 3;
382 380
                 break
383 381
 
384  
-        if self.ship == None: return
385  
-
386  
-        for p in self.powerups[:]:
387  
-            if p.collides_with(self.ship):
388  
-                self.apply_powerup(p)
389  
-                self.powerups.remove(p)
  382
+        if self.ship != None:
  383
+            for p in self.powerups[:]:
  384
+                if p.collides_with(self.ship):
  385
+                    self.apply_powerup(p)
  386
+                    self.powerups.remove(p)
390 387
 
391 388
     def spawn_explosion(self, bubble):
392 389
         explosion = ObjectOnMap(0)

0 notes on commit 63baedb

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