X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fbadguy%2Fmrbomb.cpp;h=8b411892c3b1339528f8d93c7ce803ed44811cd7;hb=dcd6b92996ea0767156f862be11498f1bd44e7c1;hp=fca87666e46f79a9d211b883721d33aa1189e9dd;hpb=08ccb17345a52f5ffd8a5dd6ecf675cad55f16a7;p=supertux.git diff --git a/src/badguy/mrbomb.cpp b/src/badguy/mrbomb.cpp index fca87666e..8b411892c 100644 --- a/src/badguy/mrbomb.cpp +++ b/src/badguy/mrbomb.cpp @@ -1,12 +1,10 @@ -// $Id$ -// // SuperTux // Copyright (C) 2006 Matthias Braun // -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -14,19 +12,22 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#include +// along with this program. If not, see . -#include "mrbomb.hpp" -#include "bomb.hpp" +#include "audio/sound_manager.hpp" +#include "badguy/bomb.hpp" +#include "badguy/mrbomb.hpp" #include "object/explosion.hpp" +#include "object/player.hpp" +#include "sprite/sprite.hpp" #include "sprite/sprite_manager.hpp" -#include "audio/sound_manager.hpp" +#include "supertux/object_factory.hpp" +#include "supertux/sector.hpp" +#include "util/reader.hpp" -MrBomb::MrBomb(const lisp::Lisp& reader) - : WalkingBadguy(reader, "images/creatures/mr_bomb/mr_bomb.sprite", "left", "right") +MrBomb::MrBomb(const Reader& reader) : + WalkingBadguy(reader, "images/creatures/mr_bomb/mr_bomb.sprite", "left", "right"), + grabbed() { walk_speed = 80; max_drop_height = 16; @@ -48,8 +49,9 @@ MrBomb::MrBomb(const lisp::Lisp& reader) } /* MrBomb created by a dispenser always gets default sprite atm.*/ -MrBomb::MrBomb(const Vector& pos, Direction d) - : WalkingBadguy(pos, d, "images/creatures/mr_bomb/mr_bomb.sprite", "left", "right") +MrBomb::MrBomb(const Vector& pos, Direction d) : + WalkingBadguy(pos, d, "images/creatures/mr_bomb/mr_bomb.sprite", "left", "right"), + grabbed() { walk_speed = 80; max_drop_height = 16; @@ -57,14 +59,6 @@ MrBomb::MrBomb(const Vector& pos, Direction d) sound_manager->preload("sounds/explosion.wav"); } -void -MrBomb::write(lisp::Writer& writer) -{ - writer.start_list("mrbomb"); - WalkingBadguy::write(writer); - writer.end_list("mrbomb"); -} - HitResponse MrBomb::collision(GameObject& object, const CollisionHit& hit) { @@ -84,8 +78,16 @@ MrBomb::collision_player(Player& player, const CollisionHit& hit) bool MrBomb::collision_squished(GameObject& object) { - remove_me(); - Sector::current()->add_object(new Bomb(get_pos(), dir, sprite_name )); + Player* player = dynamic_cast(&object); + if(player && player->is_invincible()) { + player->bounce(*this); + kill_fall(); + return true; + } + if(is_valid()) { + remove_me(); + Sector::current()->add_object(new Bomb(get_pos(), dir, sprite_name )); + } kill_squished(object); return true; } @@ -101,9 +103,11 @@ MrBomb::active_update(float elapsed_time) void MrBomb::kill_fall() { - remove_me(); - Explosion* explosion = new Explosion(get_bbox().get_middle()); - Sector::current()->add_object(explosion); + if(is_valid()) { + remove_me(); + Explosion* explosion = new Explosion(get_bbox().get_middle()); + Sector::current()->add_object(explosion); + } run_dead_script(); } @@ -146,4 +150,4 @@ MrBomb::is_portable() const return frozen; } -IMPLEMENT_FACTORY(MrBomb, "mrbomb") +/* EOF */