small updates to kugelblitz
[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 Kugelblitz::Kugelblitz(const lisp::Lisp& reader)
25     : groundhit_pos_set(false)
26 {
27   reader.get("x", start_position.x);
28   start_position.y = 0; //place above visible area
29   bbox.set_size(63.8, 63.8);
30   sprite = sprite_manager->create("kugelblitz");
31   sprite->set_action("falling");
32   physic.enable_gravity(false);
33 }
34
35 void
36 Kugelblitz::write(lisp::Writer& writer)
37 {
38   writer.start_list("kugelblitz");
39
40   writer.write_float("x", start_position.x);
41   writer.write_float("y", start_position.y);
42
43   writer.end_list("kugelblitz");
44 }
45
46 void
47 Kugelblitz::activate()
48 {
49   physic.set_velocity_y(-300);
50   physic.set_velocity_x(-20); //fall a little to the left
51 }
52
53 HitResponse
54 Kugelblitz::collision_solid(GameObject& other, const CollisionHit& chit)
55 {
56   return hit(chit);
57 }
58
59 HitResponse
60 Kugelblitz::collision_badguy(BadGuy& other , const CollisionHit& chit)
61 {
62   //Let the Kugelblitz explode, too?
63   other.kill_fall();
64   return hit(chit);
65 }
66
67 HitResponse
68 Kugelblitz::hit(const CollisionHit& chit)
69 {
70   // hit floor?
71   if(chit.normal.y < -.5) {
72     if (!groundhit_pos_set)
73     {
74       pos_groundhit = get_pos(); //I'm leaving this in, we might need it here, too
75       groundhit_pos_set = true;
76     }
77     sprite->set_action("flying");
78     physic.set_velocity_y(0);
79     physic.set_velocity_x(100);
80
81   } else if(chit.normal.y < .5) { // bumped on roof
82     physic.set_velocity_y(0);
83   }
84
85   return CONTINUE;
86 }
87
88 void
89 Kugelblitz::active_update(float elapsed_time)
90 {
91   BadGuy::active_update(elapsed_time);
92 }
93
94 IMPLEMENT_FACTORY(Kugelblitz, "kugelblitz")