* Launcher can shoot two new types of snowballs.
[supertux.git] / src / badguy / kamikazesnowball.cpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2008 Wolfgang Becker <uafr@gmx.de>
5 //
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.
10 //
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.
15 //
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.
19
20 #include <config.h>
21
22 #include "kamikazesnowball.hpp"
23
24 /* 
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. 
27  */
28 namespace{
29   static const float SPEED = 200;
30   const std::string SPLAT_SOUND = "sounds/splat.wav";
31 }
32
33 KamikazeSnowball::KamikazeSnowball(const lisp::Lisp& reader)
34         : BadGuy(reader, "images/creatures/snowball/kamikaze-snowball.sprite")
35 {
36   sound_manager->preload(SPLAT_SOUND);
37 }
38
39 KamikazeSnowball::KamikazeSnowball(const Vector& pos, Direction d)
40         : BadGuy(pos, d, "images/creatures/snowball/kamikaze-snowball.sprite")
41 {
42   sound_manager->preload(SPLAT_SOUND);
43 }
44
45 void
46 KamikazeSnowball::initialize()
47 {
48   physic.set_velocity_x(dir == LEFT ? -SPEED : SPEED);
49   physic.enable_gravity(false);
50   sprite->set_action(dir == LEFT ? "left" : "right");
51 }
52
53 bool
54 KamikazeSnowball::collision_squished(GameObject& object)
55 {
56   sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
57   kill_squished(object);
58   return true;
59 }
60
61 void
62 KamikazeSnowball::collision_solid(const CollisionHit& hit)
63 {
64   if(hit.top || hit.bottom) {
65     physic.set_velocity_y(0);
66   } else if(hit.left || hit.right) {
67     kill_collision();
68   }
69 }
70
71 void
72 KamikazeSnowball::kill_collision()
73 {
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);
80 }
81
82 HitResponse
83 KamikazeSnowball::collision_player(Player& player, const CollisionHit& hit)
84 {
85   HitResponse response = BadGuy::collision_player(player, hit);
86   if(response == FORCE_MOVE){
87     kill_collision();
88     response = ABORT_MOVE;
89   }
90   return response;
91 }
92
93
94 IMPLEMENT_FACTORY(KamikazeSnowball, "kamikazesnowball")