4 // Copyright (C) 2008 Wolfgang Becker <uafr@gmx.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "kamikazesnowball.hpp"
24 #include "object_factory.hpp"
25 #include "audio/sound_manager.hpp"
26 #include "sprite/sprite.hpp"
29 * Kamikaze Snowball will fly in one direction until he hits something.
30 * On impact he is destroyed, trying to kill what he hit or hit him.
33 static const float SPEED = 200;
34 const std::string SPLAT_SOUND = "sounds/splat.wav";
37 KamikazeSnowball::KamikazeSnowball(const lisp::Lisp& reader)
38 : BadGuy(reader, "images/creatures/snowball/kamikaze-snowball.sprite")
40 sound_manager->preload(SPLAT_SOUND);
43 KamikazeSnowball::KamikazeSnowball(const Vector& pos, Direction d)
44 : BadGuy(pos, d, "images/creatures/snowball/kamikaze-snowball.sprite")
46 sound_manager->preload(SPLAT_SOUND);
50 KamikazeSnowball::initialize()
52 physic.set_velocity_x(dir == LEFT ? -SPEED : SPEED);
53 physic.enable_gravity(false);
54 sprite->set_action(dir == LEFT ? "left" : "right");
58 KamikazeSnowball::collision_squished(GameObject& object)
60 sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
61 kill_squished(object);
66 KamikazeSnowball::collision_solid(const CollisionHit& hit)
68 if(hit.top || hit.bottom) {
69 physic.set_velocity_y(0);
70 } else if(hit.left || hit.right) {
76 KamikazeSnowball::kill_collision()
78 sprite->set_action(dir == LEFT ? "collision-left" : "collision-right");
79 sound_manager->play(SPLAT_SOUND, get_pos());
80 physic.set_velocity_x(0);
81 physic.set_velocity_y(0);
82 physic.enable_gravity(true);
83 set_state(STATE_FALLING);
89 KamikazeSnowball::collision_player(Player& player, const CollisionHit& hit)
91 HitResponse response = BadGuy::collision_player(player, hit);
92 if(response == FORCE_MOVE){
94 response = ABORT_MOVE;
100 IMPLEMENT_FACTORY(KamikazeSnowball, "kamikazesnowball")