Skip to content

Commit

Permalink
Improve make_bubble(), and renamed it to bubble_factory().
Browse files Browse the repository at this point in the history
  • Loading branch information
asweigart committed Aug 8, 2012
1 parent 38f0371 commit 113c91d
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions square-shooter/square-shooter_makeover.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,13 @@ def random_position():
return random.uniform(0.75, 1.0)


def make_bubble(kind):
if kind == "big":
size = 0.1
speed = 0.1
elif kind == "medium":
size = 0.075
speed = 0.15
elif kind == "small":
size = 0.05
speed = 0.25
def bubble_factory(kind):
# (size, speed)
kinds = {'big': (0.1, 0.1),
'medium': (0.075, 0.15),
'small': (0.05, 0.25)}

size, speed = kinds[kind]

new_bubble = ObjectOnMap(size)
new_bubble.pos = Vector2D(
Expand Down Expand Up @@ -182,7 +179,7 @@ def init_level(self, level):
del self.explosions[:]
del self.powerups[:]
for i in range(level):
self.bubbles.append(make_bubble("big"))
self.bubbles.append(bubble_factory("big"))

def update(self, delta_t):
self.handle_collisions(delta_t)
Expand Down Expand Up @@ -282,10 +279,10 @@ def spawn_bubbles(self, parent):
new_type = "medium"
elif parent.kind == "medium":
new_type = "small"
b = make_bubble(new_type)
b = bubble_factory(new_type)
b.pos.copy(parent.pos)
self.bubbles.append(b)
b = make_bubble(new_type)
b = bubble_factory(new_type)
b.pos.copy(parent.pos)
self.bubbles.append(b)

Expand Down

0 comments on commit 113c91d

Please sign in to comment.