Skip to content

Commit

Permalink
NEW GIFT: EPIC AWESOMENESS (and background)
Browse files Browse the repository at this point in the history
  • Loading branch information
bertie-wooster committed Dec 12, 2019
1 parent de796d6 commit e81a272
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Binary file added images/background_winter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 21 additions & 4 deletions stackytower.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def make_inventory(player):
'basic_icon': 'basic',
'shotgun_icon': 'shotgun',
'medkit_icon': 'medkit',
'gift_icon': 'gift',
}

# This dictionary maps block images to their damaged images.
Expand All @@ -88,6 +89,7 @@ def make_inventory(player):
'shotgun': 'shotgun_damaged',
'medkit_icon': 'medkit_icon_damaged',
'small_shield_icon': 'small_shield_icon_damaged',
'gift': 'gift_damaged',
}
# This dictionary maps damaged blocks back to their original values (when healed).
healed_block_map = dict((value, key) for key, value in damaged_block_map.items())
Expand Down Expand Up @@ -139,13 +141,13 @@ def make_inventory(player):
# When medkits are dropped, their healing power drifts down the tower.
# Each medkit creates an Actor and adds it here.
medkit_heals = []

gifts = []
# This flag controls the 1-player version of the game. If this flag is
# True then player 2 is controlled by an "AI".
player2.is_ai = False

def draw():
screen.blit('background', (0, 0))
screen.blit('background_winter', (0, 0))
active_player_marker.draw()
draw_later = []
for block in player1.tower:
Expand Down Expand Up @@ -209,7 +211,7 @@ def replace_block(player):
if value > 0.3:
new_block_image = random.choice(['shotgun_icon', 'cannon_icon', 'basic_icon'])
else:
new_block_image = random.choice(['medkit_icon', 'small_shield_icon'])
new_block_image = random.choice(['medkit_icon', 'small_shield_icon', 'gift_icon'])
new_block = Actor(new_block_image)
if player.facing_left:
flip_actor_image(new_block)
Expand Down Expand Up @@ -263,7 +265,7 @@ def resolve_drop():
fall_onto_player_tower(player.falling_block, player)

def finish_drop(player):
"""Finishes processing the dropped block for the given player.facing_left
"""Finishes processing the dropped block for the given player.
Adds the block to their tower, removes the falling block, etc.
Expand All @@ -281,6 +283,8 @@ def finish_drop(player):
make_small_shield(player, player.falling_block)
elif player.falling_block.image == 'basic':
sounds.block_land.play()
elif player.falling_block.image == 'gift':
give_gift(player)
player.falling_block = None
if is_winner(player):
winner = player
Expand All @@ -289,6 +293,16 @@ def finish_drop(player):
else:
active_player = player1
animate(active_player_marker, duration=0.4, x=active_player.towerx, tween='accelerate', on_finished=do_ai_move)
def give_gift(player):
target_block = player.tower[-2]
if target_block.image == 'cannon':
fire_cannon(player, target_block)
elif target_block.image == 'shotgun':
fire_shotgun(player, target_block)
elif target_block.image == 'medkit':
heal_tower(player, target_block)
elif target_block.image == 'small_shield_icon':
make_small_shield(player, target_block)

def do_ai_move():
"""Selects a random block from the inventory."""
Expand Down Expand Up @@ -355,6 +369,7 @@ def heal_tower(player, medkit):
medkit_heal.medkit = medkit
animate(medkit_heal, y=target_y, on_finished=cleanup_medkits)


def make_small_shield(player, small_shield_icon):
"""Puts a small shield on the tower near small_shield_icon."""
small_shield = Actor('small_shield', pos=small_shield_icon.pos)
Expand Down Expand Up @@ -445,6 +460,8 @@ def update():
flip_actor_image(block)
block.damaged = False



def is_not_close_enough(cannon_ball):
"""Returns True if the ball hasn't reached the tower yet."""
if cannon_ball.target_player is player1:
Expand Down

0 comments on commit e81a272

Please sign in to comment.