00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00039 sound_manager->preload("sounds/explosion.wav");
00040
00041
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
00050 sprite = sprite_manager->create( sprite_name );
00051 }
00052
00053
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
00108