Skip to content

Commit

Permalink
Added an Explosion class, and created Bubble.render()
Browse files Browse the repository at this point in the history
  • Loading branch information
asweigart committed Aug 10, 2012
1 parent bacff96 commit 798ece1
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions square-shooter/square-shooter_makeover.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 798ece1

Please sign in to comment.