Skip to content

Commit

Permalink
Fixed a counting bug when using butt-jump on a multi-hit bonus block
Browse files Browse the repository at this point in the history
  • Loading branch information
LMH0013 committed Jul 18, 2014
1 parent 31bdb81 commit dc2410f
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/object/bonus_block.cpp
Expand Up @@ -41,7 +41,7 @@
#include <stdexcept>

BonusBlock::BonusBlock(const Vector& pos, int data) :
Block(sprite_manager->create("images/objects/bonus_block/bonusblock.sprite")),
Block(sprite_manager->create("images/objects/bonus_block/bonusblock.sprite")),
contents(),
object(0),
hit_counter(1),
Expand All @@ -55,8 +55,8 @@ BonusBlock::BonusBlock(const Vector& pos, int data) :
case 3: contents = CONTENT_STAR; break;
case 4: contents = CONTENT_1UP; break;
case 5: contents = CONTENT_ICEGROW; break;
case 6: contents = CONTENT_LIGHT;
sound_manager->preload("sounds/switch.ogg");
case 6: contents = CONTENT_LIGHT;
sound_manager->preload("sounds/switch.ogg");
lightsprite=Surface::create("/images/objects/lightmap_light/bonusblock_light.png");
break;
case 7: contents = CONTENT_TRAMPOLINE;
Expand All @@ -66,7 +66,7 @@ BonusBlock::BonusBlock(const Vector& pos, int data) :
object = new Trampoline(get_pos(), true);
break;
case 9: contents = CONTENT_CUSTOM;
object = new Rock(get_pos(), "images/objects/rock/rock.sprite");
object = new Rock(get_pos(), "images/objects/rock/rock.sprite");
break;
case 10: contents = CONTENT_RAIN; break;
case 11: contents = CONTENT_EXPLODE; break;
Expand Down Expand Up @@ -352,6 +352,8 @@ BonusBlock::try_drop(Player *player)

Direction direction = (player->get_bbox().get_middle().x > get_bbox().get_middle().x) ? LEFT : RIGHT;

bool countdown = false;

switch(contents) {
case CONTENT_COIN:
{
Expand All @@ -363,37 +365,42 @@ BonusBlock::try_drop(Player *player)
{
sector->add_object(new PowerUp(get_pos() + Vector(0, 32), "images/powerups/fireflower/fireflower.sprite"));
sound_manager->play("sounds/upgrade.wav");
countdown = true;
break;
}

case CONTENT_ICEGROW:
{
sector->add_object(new PowerUp(get_pos() + Vector(0, 32), "images/powerups/iceflower/iceflower.sprite"));
sound_manager->play("sounds/upgrade.wav");
countdown = true;
break;
}

case CONTENT_STAR:
{
sector->add_object(new Star(get_pos() + Vector(0, 32), direction));
sound_manager->play("sounds/upgrade.wav");
countdown = true;
break;
}

case CONTENT_1UP:
{
sector->add_object(new OneUp(get_pos(), DOWN));
sound_manager->play("sounds/upgrade.wav");
countdown = true;
break;
}

case CONTENT_CUSTOM:
{
//TODO: non-portable trampolines could be moved to CONTENT_CUSTOM, but they should not drop
//NOTE: non-portable trampolines could be moved to CONTENT_CUSTOM, but they should not drop
object->set_pos(get_pos() + Vector(0, 32));
sector->add_object(object);
object = 0;
sound_manager->play("sounds/upgrade.wav");
countdown = true;
break;
}

Expand All @@ -420,6 +427,7 @@ BonusBlock::try_drop(Player *player)
hit_counter = 1; // multiple hits of coin explode is not allowed
Sector::current()->add_object(new CoinExplode(get_pos() + Vector (0, 40)));
sound_manager->play("sounds/upgrade.wav");
countdown = true;
break;
}
}
Expand All @@ -429,11 +437,12 @@ BonusBlock::try_drop(Player *player)
Sector::current()->run_script(stream, "powerup-script");
}

if(hit_counter <= 0 || contents == CONTENT_LIGHT){ //use 0 to allow infinite hits
}else if(hit_counter == 1){
sprite->set_action("empty");
}else{
hit_counter--;
if(countdown){ // only decrease hit counter if try_open was not called
if(hit_counter == 1){
sprite->set_action("empty");
}else{
hit_counter--;
}
}
}

Expand Down

0 comments on commit dc2410f

Please sign in to comment.