From: Christoph Sommer Date: Sun, 24 Feb 2008 10:28:07 +0000 (+0000) Subject: Fixed crash when using Mr. Iceblock to break a brick X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c94f71a53fc081a0b2a4c8bf87a2fa0830821bcc;p=supertux.git Fixed crash when using Mr. Iceblock to break a brick SVN-Revision: 5335 --- diff --git a/src/object/block.cpp b/src/object/block.cpp index 9e179c379..e5995b7a4 100644 --- a/src/object/block.cpp +++ b/src/object/block.cpp @@ -139,7 +139,7 @@ Block::draw(DrawingContext& context) } void -Block::start_bounce(float center_of_hitter) +Block::start_bounce(GameObject* hitter) { if(original_y == -1){ original_y = bbox.p1.y; @@ -148,14 +148,18 @@ Block::start_bounce(float center_of_hitter) bounce_dir = -BOUNCY_BRICK_SPEED; bounce_offset = 0; - float offset = (get_bbox().get_middle().x - center_of_hitter)*2 / get_bbox().get_width(); - sprite->set_angle(BUMP_ROTATION_ANGLE*offset); + MovingObject* hitter_mo = dynamic_cast(hitter); + if (hitter_mo) { + float center_of_hitter = hitter_mo->get_bbox().get_middle().x; + float offset = (get_bbox().get_middle().x - center_of_hitter)*2 / get_bbox().get_width(); + sprite->set_angle(BUMP_ROTATION_ANGLE*offset); + } } void -Block::start_break(float center_of_hitter) +Block::start_break(GameObject* hitter) { - start_bounce(center_of_hitter); + start_bounce(hitter); breaking = true; } @@ -322,7 +326,7 @@ BonusBlock::try_open() break; } - start_bounce(player.get_bbox().get_middle().x); + start_bounce(&player); sprite->set_action("empty"); } @@ -410,14 +414,14 @@ Brick::try_break(Player* player) player_one.get_status()->add_coins(1); if(coin_counter == 0) sprite->set_action("empty"); - start_bounce(player->get_bbox().get_middle().x); + start_bounce(player); } else if(breakable) { if(player){ if(player->is_big()){ - start_break(player->get_bbox().get_middle().x); + start_break(player); return; } else { - start_bounce(player->get_bbox().get_middle().x); + start_bounce(player); return; } } diff --git a/src/object/block.hpp b/src/object/block.hpp index f6069e4de..4f326eb2f 100644 --- a/src/object/block.hpp +++ b/src/object/block.hpp @@ -40,8 +40,8 @@ protected: friend class FlipLevelTransformer; virtual void hit(Player& player) = 0; - void start_bounce(float center_of_hitter); - void start_break(float center_of_hitter); + void start_bounce(GameObject* hitter); + void start_break(GameObject* hitter); void break_me(); Sprite* sprite; diff --git a/src/object/infoblock.cpp b/src/object/infoblock.cpp index 919ef9b1a..1359ddef5 100644 --- a/src/object/infoblock.cpp +++ b/src/object/infoblock.cpp @@ -68,7 +68,7 @@ InfoBlock::~InfoBlock() void InfoBlock::hit(Player& player) { - start_bounce(player.get_bbox().get_middle().x); + start_bounce(&player); //if (!stopped) { // ringing->remove_me(); diff --git a/src/object/invisible_block.cpp b/src/object/invisible_block.cpp index 4dbe5a335..01302bf21 100644 --- a/src/object/invisible_block.cpp +++ b/src/object/invisible_block.cpp @@ -75,7 +75,7 @@ InvisibleBlock::hit(Player& player) return; sprite->set_action("empty"); - start_bounce(player.get_bbox().get_middle().x); + start_bounce(&player); set_group(COLGROUP_STATIC); visible = true; }