src/badguy/short_fuse.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //  Copyright (C) 2010 Florian Forster <supertux at octo.it>
00004 //
00005 //  This program is free software: you can redistribute it and/or modify
00006 //  it under the terms of the GNU General Public License as published by
00007 //  the Free Software Foundation, either version 3 of the License, or
00008 //  (at your option) any later version.
00009 //
00010 //  This program is distributed in the hope that it will be useful,
00011 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 //  GNU General Public License for more details.
00014 //
00015 //  You should have received a copy of the GNU General Public License
00016 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 #include "audio/sound_manager.hpp"
00019 #include "badguy/bomb.hpp"
00020 #include "badguy/short_fuse.hpp"
00021 #include "object/explosion.hpp"
00022 #include "object/player.hpp"
00023 #include "sprite/sprite.hpp"
00024 #include "sprite/sprite_manager.hpp"
00025 #include "supertux/object_factory.hpp"
00026 #include "supertux/sector.hpp"
00027 #include "util/reader.hpp"
00028 #include "util/log.hpp"
00029 
00030 #define EXPLOSION_FORCE 1000.0f
00031 
00032 ShortFuse::ShortFuse(const Reader& reader) :
00033   WalkingBadguy(reader, "images/creatures/short_fuse/short_fuse.sprite", "left", "right")
00034 {
00035   walk_speed = 100;
00036   max_drop_height = -1;
00037 
00038   //Prevent stutter when Tux jumps on Mr Bomb
00039   sound_manager->preload("sounds/explosion.wav");
00040 
00041   //Check if we need another sprite
00042   if( !reader.get( "sprite", sprite_name ) ){
00043     return;
00044   }
00045   if( sprite_name == "" ){
00046     sprite_name = "images/creatures/short_fuse/short_fuse.sprite";
00047     return;
00048   }
00049   //Replace sprite
00050   sprite = sprite_manager->create( sprite_name );
00051 }
00052 
00053 /* ShortFuse created by a dispenser always gets default sprite atm.*/
00054 ShortFuse::ShortFuse(const Vector& pos, Direction d) :
00055   WalkingBadguy(pos, d, "images/creatures/short_fuse/short_fuse.sprite", "left", "right")
00056 {
00057   walk_speed = 80;
00058   max_drop_height = 16;
00059   sound_manager->preload("sounds/explosion.wav");
00060 }
00061 
00062 void
00063 ShortFuse::explode (void)
00064 {
00065   if (!is_valid ())
00066     return;
00067 
00068   Explosion *explosion = new Explosion (get_bbox ().get_middle ());
00069 
00070   explosion->hurts (false);
00071   explosion->pushes (true);
00072   Sector::current()->add_object (explosion);
00073 
00074   remove_me ();
00075 }
00076 
00077 bool
00078 ShortFuse::collision_squished(GameObject& obj)
00079 {
00080   if (!is_valid ())
00081     return true;
00082 
00083   Player* player = dynamic_cast<Player*>(&obj);
00084   if(player)
00085     player->bounce(*this);
00086 
00087   explode ();
00088 
00089   return true;
00090 }
00091 
00092 HitResponse
00093 ShortFuse::collision_player (Player& player, const CollisionHit&)
00094 {
00095   player.bounce (*this);
00096   explode ();
00097   return ABORT_MOVE;
00098 }
00099 
00100 void
00101 ShortFuse::kill_fall (void)
00102 {
00103   explode ();
00104   run_dead_script ();
00105 }
00106 
00107 /* vim: set sw=2 sts=2 et : */
00108 /* EOF */

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