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"
29 #define BASE_SPEED 200
30 #define RAND_SPEED 150
32 Kugelblitz::Kugelblitz(const lisp::Lisp& reader)
33 : groundhit_pos_set(false)
35 reader.get("x", start_position.x);
36 start_position.y = 0; //place above visible area
37 bbox.set_size(63.8, 63.8);
38 sprite = sprite_manager->create("kugelblitz");
39 sprite->set_action("falling");
40 physic.enable_gravity(false);
44 Kugelblitz::write(lisp::Writer& writer)
46 writer.start_list("kugelblitz");
48 writer.write_float("x", start_position.x);
49 writer.write_float("y", start_position.y);
51 writer.end_list("kugelblitz");
55 Kugelblitz::activate()
57 physic.set_velocity_y(-300);
58 physic.set_velocity_x(-20); //fall a little to the left
64 Kugelblitz::collision_solid(GameObject& , const CollisionHit& chit)
70 Kugelblitz::collision_player(Player& player, const CollisionHit& )
72 if(player.is_invincible()) {
77 if(player.get_movement().y - get_movement().y > 0 && player.get_bbox().p2.y <
78 (get_bbox().p1.y + get_bbox().p2.y) / 2) {
79 // if it's not is it possible to squish us, then this will hurt
80 if(!collision_squished(player))
81 player.kill(Player::SHRINK);
85 player.kill(Player::SHRINK);
91 Kugelblitz::collision_badguy(BadGuy& other , const CollisionHit& chit)
93 //Let the Kugelblitz explode, too? The problem with that is that
94 //two Kugelblitzes would cancel each other out on contact...
100 Kugelblitz::hit(const CollisionHit& chit)
103 if(chit.normal.y < -.5) {
104 if (!groundhit_pos_set)
106 pos_groundhit = get_pos();
107 groundhit_pos_set = true;
109 sprite->set_action("flying");
110 physic.set_velocity_y(0);
111 //Set random initial speed and direction
112 if ((rand() % 2) == 1) direction = 1; else direction = -1;
113 int speed = (BASE_SPEED + (rand() % RAND_SPEED)) * direction;
114 physic.set_velocity_x(speed);
115 movement_timer.start(MOVETIME);
116 lifetime.start(LIFETIME);
118 } else if(chit.normal.y < .5) { // bumped on roof
119 physic.set_velocity_y(0);
126 Kugelblitz::active_update(float elapsed_time)
128 if (electrify_timer.check()) {
129 Sector::current()->solids->change_all(1421,75);
130 Sector::current()->solids->change_all(1422,76);
133 else if (lifetime.check()) {
137 if (groundhit_pos_set) {
138 if (movement_timer.check()) {
139 if (direction == 1) direction = -1; else direction = 1;
140 int speed = (BASE_SPEED + (rand() % RAND_SPEED)) * direction;
141 physic.set_velocity_x(speed);
142 movement_timer.start(MOVETIME);
145 if (Sector::current()->solids->get_tile_at(get_pos())->getAttributes() == 16) {
147 Sector::current()->solids->change_all(75,1421);
148 Sector::current()->solids->change_all(76,1422);
149 physic.set_velocity_x(0);
150 physic.set_velocity_y(0);
151 electrify_timer.start(1);
154 BadGuy::active_update(elapsed_time);
158 Kugelblitz::kill_fall()
163 Kugelblitz::explode()
166 sprite->set_action("pop");
173 IMPLEMENT_FACTORY(Kugelblitz, "kugelblitz")