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