From: LMH Date: Sat, 10 Aug 2013 21:15:59 +0000 (-1000) Subject: Start working on a bonusblock drop procedure for when buttjump is used to open X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c3aa86d03291e219885b8e3f0318fa503b7c8158;p=supertux.git Start working on a bonusblock drop procedure for when buttjump is used to open --- diff --git a/src/object/bonus_block.cpp b/src/object/bonus_block.cpp index 36d755812..47cc964fd 100644 --- a/src/object/bonus_block.cpp +++ b/src/object/bonus_block.cpp @@ -165,7 +165,7 @@ BonusBlock::collision(GameObject& other, const CollisionHit& hit){ Player* player = dynamic_cast (&other); if (player) { if (player->does_buttjump) - try_open(player); + try_drop(player); } BadGuy* badguy = dynamic_cast (&other); @@ -331,6 +331,140 @@ BonusBlock::try_open(Player *player) } void +BonusBlock::try_drop(Player *player) +{ + if(sprite->get_action() == "empty") { + sound_manager->play("sounds/brick.wav"); + return; + } + + Sector* sector = Sector::current(); + assert(sector); + + if (player == NULL) + player = sector->player; + + if (player == NULL) + return; + + Direction direction = (player->get_bbox().get_middle().x > get_bbox().get_middle().x) ? LEFT : RIGHT; + + //TODO: when solid below send up + + switch(contents) { + case CONTENT_COIN: + { + try_open(player); + break; + } + + case CONTENT_FIREGROW: + { + //TODO: drop flowers + if(player->get_status()->bonus == NO_BONUS) { + SpecialRiser* riser = new SpecialRiser(get_pos(), new GrowUp(direction)); + sector->add_object(riser); + } else { + SpecialRiser* riser = new SpecialRiser( + get_pos(), new Flower(FIRE_BONUS)); + sector->add_object(riser); + } + sound_manager->play("sounds/upgrade.wav"); + break; + } + + case CONTENT_ICEGROW: + { + //TODO: drop flowers + if(player->get_status()->bonus == NO_BONUS) { + SpecialRiser* riser = new SpecialRiser(get_pos(), new GrowUp(direction)); + sector->add_object(riser); + } else { + SpecialRiser* riser = new SpecialRiser( + get_pos(), new Flower(ICE_BONUS)); + sector->add_object(riser); + } + sound_manager->play("sounds/upgrade.wav"); + break; + } + + case CONTENT_STAR: + { + sector->add_object(new Star(get_pos() + Vector(0, 32), direction)); + break; + } + + case CONTENT_1UP: + { + //TODO: drop doll straight down + sector->add_object(new OneUp(get_pos(), direction)); + break; + } + + case CONTENT_CUSTOM: + { + //TODO: drop custom contents + SpecialRiser* riser = new SpecialRiser(get_pos(), object); + object = 0; + sector->add_object(riser); + sound_manager->play("sounds/upgrade.wav"); + break; + } + + case CONTENT_SCRIPT: + { break; } // because scripts always run, this prevents default contents from being assumed + + case CONTENT_LIGHT: + { + try_open(player); + break; + } + case CONTENT_TRAMPOLINE: + { + try_open(player); + break; + } + case CONTENT_PORTTRAMPOLINE: + { + Sector::current()->add_object(new Trampoline(get_pos() + Vector (0, 32), true)); + sound_manager->play("sounds/upgrade.wav"); + break; + } + case CONTENT_ROCK: + { + Sector::current()->add_object(new Rock(get_pos() + Vector (0, 32), "images/objects/rock/rock.sprite")); + sound_manager->play("sounds/upgrade.wav"); + break; + } + + case CONTENT_RAIN: + { + try_open(player); + break; + } + case CONTENT_EXPLODE: + { + hit_counter = 1; // multiple hits of coin explode is not allowed + Sector::current()->add_object(new CoinExplode(get_pos() + Vector (0, 40), -1)); + sound_manager->play("sounds/upgrade.wav"); + break; + } + } + + if(script != "") { // scripts always run if defined + std::istringstream stream(script); + 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--; + } +} + +void Block::break_me() { Sector* sector = Sector::current(); diff --git a/src/object/bonus_block.hpp b/src/object/bonus_block.hpp index 4e3be522e..5c4590c6a 100644 --- a/src/object/bonus_block.hpp +++ b/src/object/bonus_block.hpp @@ -29,6 +29,7 @@ public: HitResponse collision(GameObject& other, const CollisionHit& hit); void try_open(Player *player); + void try_drop(Player *player); enum Contents { CONTENT_COIN,