fixed the small fix :-)
[supertux.git] / src / badguy / kugelblitz.cpp
1 //  $Id: Kugelblitz.cpp 2654 2005-06-29 14:16:22Z wansti $
2 // 
3 //  SuperTux
4 //  Copyright (C) 2005 Marek Moeckel <wansti@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
19 //  02111-1307, USA.
20 #include <config.h>
21
22 #include "kugelblitz.hpp"
23
24 static const float JUMPSPEED=600;
25 static const float Kugelblitz_MID_TOLERANCE=4;
26 static const float Kugelblitz_LOW_TOLERANCE=2;
27
28 Kugelblitz::Kugelblitz(const lisp::Lisp& reader)
29     : groundhit_pos_set(false)
30 {
31   reader.get("x", start_position.x);
32   start_position.y = 0; //place above visible area
33   bbox.set_size(63.8, 127.8);
34   sprite = sprite_manager->create("kugelblitz");
35   sprite->set_action("falling");
36   physic.enable_gravity(false);
37 }
38
39 void
40 Kugelblitz::write(lisp::Writer& writer)
41 {
42   writer.start_list("kugelblitz");
43
44   writer.write_float("x", start_position.x);
45   writer.write_float("y", start_position.y);
46
47   writer.end_list("kugelblitz");
48 }
49
50 void
51 Kugelblitz::activate()
52 {
53   physic.set_velocity_y(-300);
54 }
55
56 HitResponse
57 Kugelblitz::collision_solid(GameObject& , const CollisionHit& chit)
58 {
59   return hit(chit);
60 }
61
62 HitResponse
63 Kugelblitz::collision_badguy(BadGuy& other , const CollisionHit& chit)
64 {
65   other.kill_fall();
66   return hit(chit);
67 }
68
69 HitResponse
70 Kugelblitz::hit(const CollisionHit& chit)
71 {
72   // hit floor?
73   if(chit.normal.y < -.5) {
74     if (!groundhit_pos_set)
75     {
76       pos_groundhit = get_pos();
77       groundhit_pos_set = true;
78     }
79     bbox.set_size(63.8, 63.8);
80     sprite->set_action("flying");
81     physic.set_velocity_y(0);
82     physic.set_velocity_x(100);
83
84   } else if(chit.normal.y < .5) { // bumped on roof
85     physic.set_velocity_y(0);
86   }
87
88   return CONTINUE;
89 }
90
91 void
92 Kugelblitz::active_update(float elapsed_time)
93 {
94   BadGuy::active_update(elapsed_time);
95 }
96
97 IMPLEMENT_FACTORY(Kugelblitz, "kugelblitz")