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 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);
38 KamikazeSnowball::KamikazeSnowball(const Vector& pos, Direction d)
39 : BadGuy(pos, d, "images/creatures/snowball/kamikaze-snowball.sprite")
41 sound_manager->preload(SPLAT_SOUND);
45 KamikazeSnowball::initialize()
47 physic.set_velocity_x(dir == LEFT ? -SPEED : SPEED);
48 physic.enable_gravity(false);
49 sprite->set_action(dir == LEFT ? "left" : "right");
53 KamikazeSnowball::collision_squished(GameObject& object)
55 sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
56 kill_squished(object);
61 KamikazeSnowball::collision_solid(const CollisionHit& hit)
63 if(hit.top || hit.bottom) {
64 physic.set_velocity_y(0);
65 } else if(hit.left || hit.right) {
71 KamikazeSnowball::kill_collision()
73 sprite->set_action(dir == LEFT ? "collision-left" : "collision-right");
74 sound_manager->play(SPLAT_SOUND, get_pos());
75 physic.set_velocity_x(0);
76 physic.set_velocity_y(0);
77 physic.enable_gravity(true);
78 set_state(STATE_FALLING);
84 KamikazeSnowball::collision_player(Player& player, const CollisionHit& hit)
86 HitResponse response = BadGuy::collision_player(player, hit);
87 if(response == FORCE_MOVE){
89 response = ABORT_MOVE;
94 IMPLEMENT_FACTORY(KamikazeSnowball, "kamikazesnowball");