Short Fuse: Make badguy shootable with the fireflower.
[supertux.git] / src / badguy / short_fuse.cpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //  Copyright (C) 2010 Florian Forster <supertux at octo.it>
4 //
5 //  This program is free software: you can redistribute it and/or modify
6 //  it under the terms of the GNU General Public License as published by
7 //  the Free Software Foundation, either version 3 of the License, or
8 //  (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 #include "audio/sound_manager.hpp"
19 #include "badguy/bomb.hpp"
20 #include "badguy/short_fuse.hpp"
21 #include "object/explosion.hpp"
22 #include "object/player.hpp"
23 #include "sprite/sprite.hpp"
24 #include "sprite/sprite_manager.hpp"
25 #include "supertux/object_factory.hpp"
26 #include "supertux/sector.hpp"
27 #include "util/reader.hpp"
28 #include "util/log.hpp"
29
30 #define EXPLOSION_FORCE 1000.0f
31
32 ShortFuse::ShortFuse(const Reader& reader) :
33   WalkingBadguy(reader, "images/creatures/short_fuse/short_fuse.sprite", "left", "right")
34 {
35   walk_speed = 100;
36   max_drop_height = -1;
37
38   //Prevent stutter when Tux jumps on Mr Bomb
39   sound_manager->preload("sounds/explosion.wav");
40
41   //Check if we need another sprite
42   if( !reader.get( "sprite", sprite_name ) ){
43     return;
44   }
45   if( sprite_name == "" ){
46     sprite_name = "images/creatures/short_fuse/short_fuse.sprite";
47     return;
48   }
49   //Replace sprite
50   sprite = sprite_manager->create( sprite_name );
51 }
52
53 /* ShortFuse created by a dispenser always gets default sprite atm.*/
54 ShortFuse::ShortFuse(const Vector& pos, Direction d) :
55   WalkingBadguy(pos, d, "images/creatures/short_fuse/short_fuse.sprite", "left", "right")
56 {
57   walk_speed = 80;
58   max_drop_height = 16;
59   sound_manager->preload("sounds/explosion.wav");
60 }
61
62 void
63 ShortFuse::explode (void)
64 {
65   if (!is_valid ())
66     return;
67
68   Explosion *explosion = new Explosion (get_bbox ().get_middle ());
69
70   explosion->hurts (false);
71   explosion->pushes (true);
72   Sector::current()->add_object (explosion);
73
74   remove_me ();
75 }
76
77 bool
78 ShortFuse::collision_squished(GameObject& obj)
79 {
80   if (!is_valid ())
81     return true;
82
83   Player* player = dynamic_cast<Player*>(&obj);
84   if(player)
85     player->bounce(*this);
86
87   explode ();
88
89   return true;
90 }
91
92 HitResponse
93 ShortFuse::collision_player (Player& player, const CollisionHit&)
94 {
95   player.bounce (*this);
96   explode ();
97   return ABORT_MOVE;
98 }
99
100 void
101 ShortFuse::kill_fall (void)
102 {
103   explode ();
104   run_dead_script ();
105 }
106
107 /* vim: set sw=2 sts=2 et : */
108 /* EOF */