2 // Copyright (C) 2008 Wolfgang Becker <uafr@gmx.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "badguy/kamikazesnowball.hpp"
19 #include "audio/sound_manager.hpp"
20 #include "sprite/sprite.hpp"
21 #include "supertux/object_factory.hpp"
24 * Kamikaze Snowball will fly in one direction until he hits something.
25 * On impact he is destroyed, trying to kill what he hit or hit him.
28 static const float KAMIKAZE_SPEED = 200;
29 const std::string SPLAT_SOUND = "sounds/splat.wav";
32 KamikazeSnowball::KamikazeSnowball(const Reader& reader) :
33 BadGuy(reader, "images/creatures/snowball/kamikaze-snowball.sprite")
35 sound_manager->preload(SPLAT_SOUND);
36 set_action (dir == LEFT ? "left" : "right", /* loops = */ -1);
39 KamikazeSnowball::KamikazeSnowball(const Vector& pos, Direction d)
40 : BadGuy(pos, d, "images/creatures/snowball/kamikaze-snowball.sprite")
42 sound_manager->preload(SPLAT_SOUND);
43 set_action (dir == LEFT ? "left" : "right", /* loops = */ -1);
47 KamikazeSnowball::initialize()
49 physic.set_velocity_x(dir == LEFT ? -KAMIKAZE_SPEED : KAMIKAZE_SPEED);
50 physic.enable_gravity(false);
51 sprite->set_action(dir == LEFT ? "left" : "right");
55 KamikazeSnowball::collision_squished(GameObject& object)
57 sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
58 kill_squished(object);
63 KamikazeSnowball::collision_solid(const CollisionHit& hit)
65 if(hit.top || hit.bottom) {
66 physic.set_velocity_y(0);
68 if(hit.left || hit.right) {
74 KamikazeSnowball::kill_collision()
76 sprite->set_action(dir == LEFT ? "collision-left" : "collision-right");
77 sound_manager->play(SPLAT_SOUND, get_pos());
78 physic.set_velocity_x(0);
79 physic.set_velocity_y(0);
80 physic.enable_gravity(true);
81 set_state(STATE_FALLING);
87 KamikazeSnowball::collision_player(Player& player, const CollisionHit& hit)
89 //Hack to tell if we should die
90 HitResponse response = BadGuy::collision_player(player, hit);
91 if(response == FORCE_MOVE) {