Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 798ece1b88b5735e8c43d849150a6b084da5d8f5 1 parent bacff96
@asweigart authored
Showing with 29 additions and 17 deletions.
  1. +29 −17 square-shooter/square-shooter_makeover.py
View
46 square-shooter/square-shooter_makeover.py
@@ -161,6 +161,13 @@ def spawn(self):
return (spawned_bubbles, spawned_powerups)
+ def render(self, surface):
+ pygame.draw.circle(
+ surface,
+ self.color,
+ scale_and_round(self.pos.x, self.pos.y),
+ int(round(self.radius * MAP_SIZE)),
+ 1)
class Powerup(ObjectOnMap):
def __init__(self, pos):
@@ -280,6 +287,21 @@ def render(self, surface):
if self.shield:
pygame.draw.rect(surface, RED, bbox, 1)
+class Explosion(ObjectOnMap):
+ def __init__(self):
+ super(Explosion, self).__init__(0) # explosions start at size 0
+
+ def update(self, delta_t):
+ self.radius += delta_t
+
+ def render(self, surface):
+ pygame.draw.circle(
+ surface,
+ RED,
+ scale_and_round(self.pos.x, self.pos.y),
+ int(round(self.radius * MAP_SIZE)),
+ 1)
+
class GameWorld:
bubbles = []
explosions = []
@@ -323,8 +345,8 @@ def update(self, delta_t):
self.handle_collisions(delta_t)
# expand the explosions and delete them once they get too big
- for i in self.explosions:
- i.radius += delta_t
+ for explosion in self.explosions:
+ explosion.update(delta_t)
for i in range(len(self.explosions) - 1, -1, -1):
if self.explosions[i].radius > MAX_EXPLOSION_SIZE:
self.explosions.pop(i)
@@ -409,7 +431,7 @@ def handle_collisions(self, delta_t):
self.powerups.remove(p)
def spawn_explosion(self, bubble):
- explosion = ObjectOnMap(0)
+ explosion = Explosion()
explosion.pos.copy(bubble.pos)
self.explosions.append(explosion)
@@ -519,21 +541,11 @@ def render_game_world(self):
self.world.bullet.render(self.screen)
for bubble in self.world.bubbles:
- pos = bubble.pos
- pygame.draw.circle(
- self.screen,
- bubble.color,
- scale_and_round(pos.x, pos.y),
- int(round(bubble.radius * MAP_SIZE)),
- 1)
+ bubble.render(self.screen)
+
for explosion in self.world.explosions:
- pos = explosion.pos
- pygame.draw.circle(
- self.screen,
- RED,
- scale_and_round(pos.x, pos.y),
- int(round(explosion.radius * MAP_SIZE)),
- 1)
+ explosion.render(self.screen)
+
for i in self.world.powerups:
self.render_powerup(i)
Please sign in to comment.
Something went wrong with that request. Please try again.