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"
25 * Kamikaze Snowball will fly in one direction until he hits something.
26 * On impact he is destroyed, trying to kill what he hit or hit him.
29 static const float SPEED = 200;
30 const std::string SPLAT_SOUND = "sounds/splat.wav";
33 KamikazeSnowball::KamikazeSnowball(const lisp::Lisp& reader)
34 : BadGuy(reader, "images/creatures/snowball/kamikaze-snowball.sprite")
36 sound_manager->preload(SPLAT_SOUND);
39 KamikazeSnowball::KamikazeSnowball(const Vector& pos, Direction d)
40 : BadGuy(pos, d, "images/creatures/snowball/kamikaze-snowball.sprite")
42 sound_manager->preload(SPLAT_SOUND);
46 KamikazeSnowball::initialize()
48 physic.set_velocity_x(dir == LEFT ? -SPEED : SPEED);
49 physic.enable_gravity(false);
50 sprite->set_action(dir == LEFT ? "left" : "right");
54 KamikazeSnowball::collision_squished(GameObject& object)
56 sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
57 kill_squished(object);
62 KamikazeSnowball::collision_solid(const CollisionHit& hit)
64 if(hit.top || hit.bottom) {
65 physic.set_velocity_y(0);
66 } else if(hit.left || hit.right) {
72 KamikazeSnowball::kill_collision()
74 sprite->set_action(dir == LEFT ? "collision-left" : "collision-right");
75 sound_manager->play(SPLAT_SOUND, get_pos());
76 physic.set_velocity_x(0);
77 physic.set_velocity_y(0);
78 physic.enable_gravity(true);
79 set_state(STATE_FALLING);
83 KamikazeSnowball::collision_player(Player& player, const CollisionHit& hit)
85 HitResponse response = BadGuy::collision_player(player, hit);
86 if(response == FORCE_MOVE){
88 response = ABORT_MOVE;
94 IMPLEMENT_FACTORY(KamikazeSnowball, "kamikazesnowball")