Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added an Explosion class, and created Bubble.render()

  • Loading branch information...
commit 798ece1b88b5735e8c43d849150a6b084da5d8f5 1 parent bacff96
Al Sweigart authored August 09, 2012

Showing 1 changed file with 29 additions and 17 deletions. Show diff stats Hide diff stats

  1. 46  square-shooter/square-shooter_makeover.py
46  square-shooter/square-shooter_makeover.py
@@ -161,6 +161,13 @@ def spawn(self):
161 161
 
162 162
         return (spawned_bubbles, spawned_powerups)
163 163
 
  164
+    def render(self, surface):
  165
+        pygame.draw.circle(
  166
+            surface,
  167
+            self.color,
  168
+            scale_and_round(self.pos.x, self.pos.y),
  169
+            int(round(self.radius * MAP_SIZE)),
  170
+            1)
164 171
 
165 172
 class Powerup(ObjectOnMap):
166 173
     def __init__(self, pos):
@@ -280,6 +287,21 @@ def render(self, surface):
280 287
         if self.shield:
281 288
             pygame.draw.rect(surface, RED, bbox, 1)
282 289
 
  290
+class Explosion(ObjectOnMap):
  291
+    def __init__(self):
  292
+        super(Explosion, self).__init__(0) # explosions start at size 0
  293
+
  294
+    def update(self, delta_t):
  295
+        self.radius += delta_t
  296
+
  297
+    def render(self, surface):
  298
+        pygame.draw.circle(
  299
+            surface,
  300
+            RED,
  301
+            scale_and_round(self.pos.x, self.pos.y),
  302
+            int(round(self.radius * MAP_SIZE)),
  303
+            1)
  304
+
283 305
 class GameWorld:
284 306
     bubbles = []
285 307
     explosions = []
@@ -323,8 +345,8 @@ def update(self, delta_t):
323 345
         self.handle_collisions(delta_t)
324 346
 
325 347
         # expand the explosions and delete them once they get too big
326  
-        for i in self.explosions:
327  
-            i.radius += delta_t
  348
+        for explosion in self.explosions:
  349
+            explosion.update(delta_t)
328 350
         for i in range(len(self.explosions) - 1, -1, -1):
329 351
             if self.explosions[i].radius > MAX_EXPLOSION_SIZE:
330 352
                 self.explosions.pop(i)
@@ -409,7 +431,7 @@ def handle_collisions(self, delta_t):
409 431
                     self.powerups.remove(p)
410 432
 
411 433
     def spawn_explosion(self, bubble):
412  
-        explosion = ObjectOnMap(0)
  434
+        explosion = Explosion()
413 435
         explosion.pos.copy(bubble.pos)
414 436
         self.explosions.append(explosion)
415 437
 
@@ -519,21 +541,11 @@ def render_game_world(self):
519 541
             self.world.bullet.render(self.screen)
520 542
 
521 543
         for bubble in self.world.bubbles:
522  
-            pos = bubble.pos
523  
-            pygame.draw.circle(
524  
-                self.screen,
525  
-                bubble.color,
526  
-                scale_and_round(pos.x, pos.y),
527  
-                int(round(bubble.radius * MAP_SIZE)),
528  
-                1)
  544
+            bubble.render(self.screen)
  545
+
529 546
         for explosion in self.world.explosions:
530  
-            pos = explosion.pos
531  
-            pygame.draw.circle(
532  
-                self.screen,
533  
-                RED,
534  
-                scale_and_round(pos.x, pos.y),
535  
-                int(round(explosion.radius * MAP_SIZE)),
536  
-                1)
  547
+            explosion.render(self.screen)
  548
+
537 549
         for i in self.world.powerups:
538 550
             self.render_powerup(i)
539 551
 

0 notes on commit 798ece1

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