Skip to content

Commit

Permalink
Refactored mark_score() and apply_powerup()
Browse files Browse the repository at this point in the history
  • Loading branch information
asweigart committed Aug 10, 2012
1 parent 63baedb commit 60fd1e7
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions square-shooter/square-shooter_makeover.py
Expand Up @@ -114,10 +114,10 @@ def collides_with(self, other):




class Bubble(ObjectOnMap): class Bubble(ObjectOnMap):
# (size, speed) # (size, speed)
kinds = {'big': (0.1, 0.1), kinds = {'big': (0.1, 0.1),
'medium': (0.075, 0.15), 'medium': (0.075, 0.15),
'small': (0.05, 0.25)} 'small': (0.05, 0.25)}


colors = [pygame.Color('#ffffcc'), colors = [pygame.Color('#ffffcc'),
pygame.Color('#ffccff'), pygame.Color('#ffccff'),
Expand Down Expand Up @@ -391,25 +391,22 @@ def spawn_explosion(self, bubble):
self.explosions.append(explosion) self.explosions.append(explosion)


def mark_score(self, bubble): def mark_score(self, bubble):
if bubble.kind == "small": # score
self.score += 5 kinds = {'big': 1,
elif bubble.kind == "medium": 'medium': 2,
self.score += 2 'small': 5}
elif bubble.kind == "big": self.score += kinds[bubble.kind]
self.score += 1


if self.score > self.high_score: if self.score > self.high_score:
self.high_score = self.score self.high_score = self.score


def apply_powerup(self, powerup): def apply_powerup(self, powerup):
if powerup.kind == "shield": # function to call
self.ship.add_shield() kinds = {'shield': self.ship.add_shield,
elif powerup.kind == "bullet": 'bullet': self.ship.add_super_bullets,
self.ship.add_super_bullets() 'freeze': self.ship.add_freeze}
elif powerup.kind == "freeze": kinds[powerup.kind]()
self.ship.add_freeze()
else:
raise "Bad powerup type"
self.score += self.level * 10 self.score += self.level * 10


if self.score > self.high_score: if self.score > self.high_score:
Expand Down

0 comments on commit 60fd1e7

Please sign in to comment.