1 // $Id: Kugelblitz.cpp 2654 2005-06-29 14:16:22Z wansti $
4 // Copyright (C) 2005 Marek Moeckel <wansti@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
22 #include "kugelblitz.hpp"
24 #include "object/tilemap.hpp"
27 Kugelblitz::Kugelblitz(const lisp::Lisp& reader)
28 : groundhit_pos_set(false)
30 reader.get("x", start_position.x);
31 start_position.y = 0; //place above visible area
32 bbox.set_size(63.8, 63.8);
33 sprite = sprite_manager->create("kugelblitz");
34 sprite->set_action("falling");
35 physic.enable_gravity(false);
39 Kugelblitz::write(lisp::Writer& writer)
41 writer.start_list("kugelblitz");
43 writer.write_float("x", start_position.x);
44 writer.write_float("y", start_position.y);
46 writer.end_list("kugelblitz");
50 Kugelblitz::activate()
52 physic.set_velocity_y(-300);
53 physic.set_velocity_x(-20); //fall a little to the left
58 Kugelblitz::collision_solid(GameObject& other, const CollisionHit& chit)
64 Kugelblitz::collision_badguy(BadGuy& other , const CollisionHit& chit)
66 //Let the Kugelblitz explode, too?
72 Kugelblitz::hit(const CollisionHit& chit)
75 if(chit.normal.y < -.5) {
76 if (!groundhit_pos_set)
78 pos_groundhit = get_pos();
79 groundhit_pos_set = true;
81 sprite->set_action("flying");
82 physic.set_velocity_y(0);
83 movement_timer.start(1500);
85 } else if(chit.normal.y < .5) { // bumped on roof
86 physic.set_velocity_y(0);
93 Kugelblitz::active_update(float elapsed_time)
95 if (groundhit_pos_set) {
96 if (movement_timer.check()) {
97 //std::cout << "IM HERE" << std::endl;
98 //FIXME: Find out why the program never gets here
99 if (direction == 1) direction = -1; else direction = 1;
100 int speed = (300 + (rand() % 300)) * direction;
101 physic.set_velocity_x(speed);
102 movement_timer.start(1500);
105 if (Sector::current()->solids->get_tile_at(get_pos())->getAttributes() == 16) {
108 BadGuy::active_update(elapsed_time);
111 IMPLEMENT_FACTORY(Kugelblitz, "kugelblitz")