Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactoring handle_collisions()

  • Loading branch information...
commit 63baedb58bbaaf4730606e4ba36c2534fd8e1156 1 parent 70f7b17
Al Sweigart authored
Showing with 10 additions and 13 deletions.
  1. +10 −13 square-shooter/square-shooter_makeover.py
23 square-shooter/square-shooter_makeover.py
View
@@ -357,7 +357,7 @@ def handle_collisions(self, delta_t):
if self.bullet != None and self.bullet.collides_with(b):
self.bubbles.remove(b)
if self.ship != None and not self.ship.has_super_bullets():
- self.bullet = None
+ self.bullet = None # delete the non-super bullet when it hits a bubble
else:
# Push it along or it will just
# destroy the newly formed bubbles.
@@ -367,26 +367,23 @@ def handle_collisions(self, delta_t):
self.powerups.extend(spawned_powerups)
self.spawn_explosion(b)
self.mark_score(b)
- if len(self.bubbles) == 0:
+ if not len(self.bubbles):
self.afterfinish_timer = 3
break
- elif self.ship != None:
- if not b.collides_with(self.ship):
- continue
- if self.ship.has_shield():
- continue
+
+ # check if the bubble has hit the ship
+ if self.ship != None and b.collides_with(self.ship) and not self.ship.has_shield():
self.spawn_explosion(self.ship)
self.ship = None
self.lives -= 1
self.afterdeath_timer = 3;
break
- if self.ship == None: return
-
- for p in self.powerups[:]:
- if p.collides_with(self.ship):
- self.apply_powerup(p)
- self.powerups.remove(p)
+ if self.ship != None:
+ for p in self.powerups[:]:
+ if p.collides_with(self.ship):
+ self.apply_powerup(p)
+ self.powerups.remove(p)
def spawn_explosion(self, bubble):
explosion = ObjectOnMap(0)
Please sign in to comment.
Something went wrong with that request. Please try again.