X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Fblock.cpp;h=bb309f037b6ee33ec4280dd0c2ff760a16924785;hb=a98f7cee9f6a2593c0e1f3442800f159bad410df;hp=de4f311726a6e94cda051a53aa36c4d95c1b5718;hpb=02afe1b64f521ccc6f81701c288dfd56d459215b;p=supertux.git diff --git a/src/object/block.cpp b/src/object/block.cpp index de4f31172..bb309f037 100644 --- a/src/object/block.cpp +++ b/src/object/block.cpp @@ -32,6 +32,7 @@ #include "video/drawing_context.hpp" #include "lisp/lisp.hpp" #include "gameobjs.hpp" +#include "portable.hpp" #include "specialriser.hpp" #include "growup.hpp" #include "flower.hpp" @@ -73,15 +74,25 @@ Block::collision(GameObject& other, const CollisionHit& ) } } - if(bouncing) { + // only interact with other objects if... + // 1) we are bouncing + // and + // 2) the object is not portable (either never or not currently) + Portable* portable = dynamic_cast (&other); + if(bouncing && (portable == 0 || (!portable->is_portable()))) { + + // Badguys get killed BadGuy* badguy = dynamic_cast (&other); if(badguy) { badguy->kill_fall(); } + + // Coins get collected Coin* coin = dynamic_cast (&other); if(coin) { coin->collect(); } + } return SOLID; @@ -223,6 +234,13 @@ BonusBlock::collision(GameObject& other, const CollisionHit& hit){ try_open(); } } + Portable* portable = dynamic_cast (&other); + if(portable) { + MovingObject* moving = dynamic_cast (&other); + if(moving->get_bbox().get_top() > get_bbox().get_bottom() - 7.0) { + try_open(); + } + } return Block::collision(other, hit); } @@ -325,47 +343,60 @@ Brick::Brick(const Vector& pos, int data) } void -Brick::hit(Player& ) +Brick::hit(Player& player) { if(sprite->get_action() == "empty") return; - try_break(true); + try_break(&player); } HitResponse Brick::collision(GameObject& other, const CollisionHit& hit){ + + Player* player = dynamic_cast (&other); + if (player) { + if (player->does_buttjump) try_break(); + } + BadGuy* badguy = dynamic_cast (&other); if(badguy) { // hit contains no information for collisions with blocks. // Badguy's bottom has to be below the top of the brick // +7 is required to slide over one tile gaps. if( badguy->can_break() && ( badguy->get_bbox().get_bottom() > get_bbox().get_top() + 7.0 ) ){ - try_break(false); + try_break(); + } + } + Portable* portable = dynamic_cast (&other); + if(portable) { + MovingObject* moving = dynamic_cast (&other); + if(moving->get_bbox().get_top() > get_bbox().get_bottom() - 7.0) { + try_break(); } } return Block::collision(other, hit); } void -Brick::try_break(bool playerhit) +Brick::try_break(Player* player) { if(sprite->get_action() == "empty") return; sound_manager->play("sounds/brick.wav"); Sector* sector = Sector::current(); - Player& player = *(sector->player); + Player& player_one = *(sector->player); if(coin_counter > 0) { sector->add_object(new BouncyCoin(get_pos())); coin_counter--; - player.get_status()->add_coins(1); + player_one.get_status()->add_coins(1); if(coin_counter == 0) sprite->set_action("empty"); start_bounce(); } else if(breakable) { - if(playerhit){ - if(player.is_big()){ + if(player){ + if(player->is_big()){ start_break(); return; } else {