X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Fblock.cpp;h=fd6e2fc211308b5188723058b91fdbf49ac3129a;hb=fea3446f05e1e7673607b835c269d3e8d1929ab3;hp=0f999ae69a3ac36d5fed92e42685e1466d6b9cc4;hpb=0be43004e861eb30599657f95051583e108d0a83;p=supertux.git diff --git a/src/object/block.cpp b/src/object/block.cpp index 0f999ae69..fd6e2fc21 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" @@ -43,15 +44,16 @@ #include "object_factory.hpp" #include "lisp/list_iterator.hpp" #include "object_factory.hpp" +#include "level.hpp" -static const float BOUNCY_BRICK_MAX_OFFSET=8; -static const float BOUNCY_BRICK_SPEED=90; -static const float EPSILON = .0001; +static const float BOUNCY_BRICK_MAX_OFFSET = 8; +static const float BOUNCY_BRICK_SPEED = 90; +static const float EPSILON = .0001f; Block::Block(Sprite* newsprite) : sprite(newsprite), bouncing(false), breaking(false), bounce_dir(0), bounce_offset(0) { - bbox.set_size(32, 32.1); + bbox.set_size(32, 32.1f); set_group(COLGROUP_STATIC); sound_manager->preload("sounds/upgrade.wav"); sound_manager->preload("sounds/brick.wav"); @@ -72,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; @@ -222,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); } @@ -243,6 +262,7 @@ BonusBlock::try_open() case CONTENT_COIN: Sector::current()->add_object(new BouncyCoin(get_pos())); player.get_status()->add_coins(1); + Sector::current()->get_level()->stats.coins++; break; case CONTENT_FIREGROW: @@ -342,6 +362,13 @@ Brick::collision(GameObject& other, const CollisionHit& hit){ try_break(false); } } + 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); }