Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Moved shoot_at() to the Ship class.

  • Loading branch information...
commit 8b7815451ba312ed0d0c98754cec45358fd422d9 1 parent 98a3972
Al Sweigart authored August 08, 2012

Showing 1 changed file with 23 additions and 25 deletions. Show diff stats Hide diff stats

  1. 48  square-shooter/square-shooter_makeover.py
48  square-shooter/square-shooter_makeover.py
@@ -153,7 +153,7 @@ def spawn(self):
153 153
             elif self.kind == "big":
154 154
                 new_kind = "medium"
155 155
 
156  
-            for i in range(20): # creates two new Bubbles
  156
+            for i in range(2): # creates two new Bubbles
157 157
                 spawned_bubbles.append(Bubble(new_kind))
158 158
                 spawned_bubbles[-1].pos.copy(self.pos)
159 159
 
@@ -221,6 +221,26 @@ def has_super_bullets(self):
221 221
         """Returns True if this ship currently has a shield, False if it does not have a shield."""
222 222
         return self._super_bullet_timer > 0
223 223
 
  224
+    def shoot_at(self, x, y):
  225
+        """Returns a list of bullet objects that were created by the Ship."""
  226
+        x -= self.pos.x;
  227
+        y -= self.pos.y;
  228
+
  229
+        b = Bullet()
  230
+        b.pos.copy(self.pos);
  231
+        b.speed.x = x * 3
  232
+        b.speed.y = y * 3
  233
+
  234
+        # Help out the poor sods who click on their
  235
+        # own ship and get stuck with a non-moving
  236
+        # bullet. (2009-11-14)
  237
+        if abs(x) < 0.1 and abs(y) < 0.1:
  238
+            b.speed.x *= 30
  239
+            b.speed.y *= 30
  240
+
  241
+        return [b]
  242
+
  243
+
224 244
 class Bullet(ObjectOnMap):
225 245
     def __init__(self):
226 246
         super(Bullet, self).__init__(0.01) # all Bullet objects are the same size
@@ -378,29 +398,6 @@ def apply_powerup(self, powerup):
378 398
         if self.score > self.high_score:
379 399
             self.high_score = self.score
380 400
 
381  
-    def shoot_at(self, x, y):
382  
-        if self.bullet != None or self.ship == None:
383  
-            return
384  
-
385  
-        x -= self.ship.pos.x;
386  
-        y -= self.ship.pos.y;
387  
-
388  
-        b = ObjectOnMap(0.01)
389  
-        b.pos.copy(self.ship.pos);
390  
-        b.speed.x = x * 3
391  
-        b.speed.y = y * 3
392  
-
393  
-        # Help out the poor sods who click on their
394  
-        # own ship and get stuck with a non-moving
395  
-        # bullet. (2009-11-14)
396  
-        absx = abs(x)
397  
-        absy = abs(y)
398  
-        if absx < 0.1 and absy < 0.1:
399  
-            b.speed.x *= 30
400  
-            b.speed.y *= 30
401  
-
402  
-        self.bullet = b
403  
-
404 401
 
405 402
 class GameScreen:
406 403
     def __init__(self, model, screen):
@@ -614,7 +611,8 @@ def render_pause_text(self):
614 611
         # on mouse down, fire a bullet and start the thruster of the ship
615 612
         if (model.level > 0) and (model.ship != None) and (not renderer.game_paused):
616 613
             x, y = ev.pos
617  
-            model.shoot_at(x / float(MAP_WIDTH), y / float(MAP_HEIGHT))
  614
+            if model.bullet == None:
  615
+                model.bullet = model.ship.shoot_at(x / float(MAP_WIDTH), y / float(MAP_HEIGHT))[0]
618 616
             model.ship.thrust_at(x / float(MAP_WIDTH), y / float(MAP_HEIGHT))
619 617
     elif ev.type == pygame.MOUSEBUTTONUP:
620 618
         # on mouse up, stop accelerating the ship

0 notes on commit 8b78154

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