src/badguy/mrbomb.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "audio/sound_manager.hpp"
00018 #include "badguy/bomb.hpp"
00019 #include "badguy/mrbomb.hpp"
00020 #include "object/explosion.hpp"
00021 #include "object/player.hpp"
00022 #include "sprite/sprite.hpp"
00023 #include "sprite/sprite_manager.hpp"
00024 #include "supertux/object_factory.hpp"
00025 #include "supertux/sector.hpp"
00026 #include "util/reader.hpp"
00027 
00028 MrBomb::MrBomb(const Reader& reader) :
00029   WalkingBadguy(reader, "images/creatures/mr_bomb/mr_bomb.sprite", "left", "right"),
00030   grabbed()
00031 {
00032   walk_speed = 80;
00033   max_drop_height = 16;
00034   grabbed = false;
00035 
00036   //Prevent stutter when Tux jumps on Mr Bomb
00037   sound_manager->preload("sounds/explosion.wav");
00038 
00039   //Check if we need another sprite
00040   if( !reader.get( "sprite", sprite_name ) ){
00041     return;
00042   }
00043   if( sprite_name == "" ){
00044     sprite_name = "images/creatures/mr_bomb/mr_bomb.sprite";
00045     return;
00046   }
00047   //Replace sprite
00048   sprite = sprite_manager->create( sprite_name );
00049 }
00050 
00051 /* MrBomb created by a dispenser always gets default sprite atm.*/
00052 MrBomb::MrBomb(const Vector& pos, Direction d) :
00053   WalkingBadguy(pos, d, "images/creatures/mr_bomb/mr_bomb.sprite", "left", "right"),
00054   grabbed()
00055 {
00056   walk_speed = 80;
00057   max_drop_height = 16;
00058   grabbed = false;
00059   sound_manager->preload("sounds/explosion.wav");
00060 }
00061 
00062 HitResponse
00063 MrBomb::collision(GameObject& object, const CollisionHit& hit)
00064 {
00065   if(grabbed)
00066     return FORCE_MOVE;
00067   return WalkingBadguy::collision(object, hit);
00068 }
00069 
00070 HitResponse
00071 MrBomb::collision_player(Player& player, const CollisionHit& hit)
00072 {
00073   if(grabbed)
00074     return FORCE_MOVE;
00075   return WalkingBadguy::collision_player(player, hit);
00076 }
00077 
00078 bool
00079 MrBomb::collision_squished(GameObject& object)
00080 {
00081   Player* player = dynamic_cast<Player*>(&object);
00082   if(player && player->is_invincible()) {
00083     player->bounce(*this);
00084     kill_fall();
00085     return true;
00086   }
00087   if(is_valid()) {
00088     remove_me();
00089     Sector::current()->add_object(new Bomb(get_pos(), dir, sprite_name ));
00090   }
00091   kill_squished(object);
00092   return true;
00093 }
00094 
00095 void
00096 MrBomb::active_update(float elapsed_time)
00097 {
00098   if(grabbed)
00099     return;
00100   WalkingBadguy::active_update(elapsed_time);
00101 }
00102 
00103 void
00104 MrBomb::kill_fall()
00105 {
00106   if(is_valid()) {
00107     remove_me();
00108     Explosion* explosion = new Explosion(get_bbox().get_middle());
00109     Sector::current()->add_object(explosion);
00110   }
00111 
00112   run_dead_script();
00113 }
00114 
00115 void
00116 MrBomb::grab(MovingObject&, const Vector& pos, Direction dir)
00117 {
00118   assert(frozen);
00119   movement = pos - get_pos();
00120   this->dir = dir;
00121   sprite->set_action(dir == LEFT ? "iced-left" : "iced-right");
00122   set_colgroup_active(COLGROUP_DISABLED);
00123   grabbed = true;
00124 }
00125 
00126 void
00127 MrBomb::ungrab(MovingObject& , Direction dir)
00128 {
00129   this->dir = dir;
00130   set_colgroup_active(COLGROUP_MOVING);
00131   grabbed = false;
00132 }
00133 
00134 void
00135 MrBomb::freeze()
00136 {
00137   WalkingBadguy::freeze();
00138   sprite->set_action(dir == LEFT ? "iced-left" : "iced-right");
00139 }
00140 
00141 bool
00142 MrBomb::is_freezable() const
00143 {
00144   return true;
00145 }
00146 
00147 bool
00148 MrBomb::is_portable() const
00149 {
00150   return frozen;
00151 }
00152 
00153 /* EOF */

Generated on Mon Jun 9 03:38:17 2014 for SuperTux by  doxygen 1.5.1