Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…anges.
  • Loading branch information...
commit d0e100ce11f20546f352a8abdbd5a50d13e7aa8b 1 parent 8b78154
@asweigart authored
Showing with 15 additions and 13 deletions.
  1. +15 −13 square-shooter/square-shooter_makeover.py
View
28 square-shooter/square-shooter_makeover.py
@@ -173,6 +173,7 @@ def __init__(self):
super(Ship, self).__init__(0.04) # all Ships are the same size.
self._shield_timer = 0
self._super_bullet_timer = 0
+ self._freeze_timer = 0
self.accel_x = 0 # acceleration rate of the ship
self.accel_y = 0
@@ -202,6 +203,8 @@ def update(self, delta_t):
self._shield_timer -= delta_t
if self.has_super_bullets():
self._super_bullet_timer -= delta_t
+ if self.has_freeze():
+ self._freeze_timer -= delta_t
super(Ship, self).update(delta_t)
@@ -214,13 +217,21 @@ def has_shield(self):
return self._shield_timer > 0
def add_super_bullets(self, secs=6):
- """Extends the time on the ship's shield by secs seconds."""
+ """Extends the time on the ship's super bullets by secs seconds."""
self._super_bullet_timer += secs
def has_super_bullets(self):
- """Returns True if this ship currently has a shield, False if it does not have a shield."""
+ """Returns True if this ship currently has a super bullets, False if it does not have a super bullets."""
return self._super_bullet_timer > 0
+ def add_freeze(self, secs=6):
+ """Extends the time on the ship's freeze powerup by secs seconds."""
+ self._freeze_timer += secs
+
+ def has_freeze(self):
+ """Returns True if this ship currently has a freeze powerup, False if it does not have a shield."""
+ return self._freeze_timer > 0
+
def shoot_at(self, x, y):
"""Returns a list of bullet objects that were created by the Ship."""
x -= self.pos.x;
@@ -254,12 +265,8 @@ class GameWorld:
bullet = None
ship = None
- accel_x = 0
- accel_y = 0
-
death_timer = 0
finish_timer = 0
- freeze_timer = 0
level = 0
score = 0
@@ -277,8 +284,6 @@ def init_level(self, level):
self.death_timer = 0
self.finish_timer = 0
- self.freeze_timer = 0;
-
del self.bubbles[:]
del self.explosions[:]
del self.powerups[:]
@@ -300,9 +305,6 @@ def update(self, delta_t):
for i in self.powerups:
i.age += delta_t
- if self.freeze_timer > 0:
- self.freeze_timer -= delta_t
-
if len(self.bubbles) == 0:
if self.finish_timer > 0:
self.finish_timer -= delta_t;
@@ -311,7 +313,7 @@ def update(self, delta_t):
self.lives += 1
self.init_level(self.level)
return
- elif self.freeze_timer <= 0:
+ elif not self.ship.has_freeze():
for i in self.bubbles:
i.update(delta_t)
@@ -390,7 +392,7 @@ def apply_powerup(self, powerup):
elif powerup.kind == "bullet":
self.ship.add_super_bullets()
elif powerup.kind == "freeze":
- self.freeze_timer += 6
+ self.ship.add_freeze()
else:
raise "Bad powerup type"
self.score += self.level * 10
Please sign in to comment.
Something went wrong with that request. Please try again.