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"
23 #include "object/tilemap.hpp"
28 #define BASE_SPEED 200
29 #define RAND_SPEED 150
31 Kugelblitz::Kugelblitz(const lisp::Lisp& reader)
32 : groundhit_pos_set(false)
34 reader.get("x", start_position.x);
35 start_position.y = 0; //place above visible area
36 bbox.set_size(63.8, 63.8);
37 sprite = sprite_manager->create("kugelblitz");
38 sprite->set_action("falling");
39 physic.enable_gravity(false);
43 Kugelblitz::write(lisp::Writer& writer)
45 writer.start_list("kugelblitz");
47 writer.write_float("x", start_position.x);
48 writer.write_float("y", start_position.y);
50 writer.end_list("kugelblitz");
54 Kugelblitz::activate()
56 physic.set_velocity_y(-300);
57 physic.set_velocity_x(-20); //fall a little to the left
63 Kugelblitz::collision_solid(GameObject& , const CollisionHit& chit)
69 Kugelblitz::collision_player(Player& player, const CollisionHit& )
71 if(player.is_invincible()) {
76 if(player.get_movement().y - get_movement().y > 0 && player.get_bbox().p2.y <
77 (get_bbox().p1.y + get_bbox().p2.y) / 2) {
78 // if it's not is it possible to squish us, then this will hurt
79 if(!collision_squished(player))
80 player.kill(Player::SHRINK);
84 player.kill(Player::SHRINK);
90 Kugelblitz::collision_badguy(BadGuy& other , const CollisionHit& chit)
92 //Let the Kugelblitz explode, too? The problem with that is that
93 //two Kugelblitzes would cancel each other out on contact...
99 Kugelblitz::hit(const CollisionHit& chit)
102 if(chit.normal.y < -.5) {
103 if (!groundhit_pos_set)
105 pos_groundhit = get_pos();
106 groundhit_pos_set = true;
108 sprite->set_action("flying");
109 physic.set_velocity_y(0);
110 //Set random initial speed and direction
111 if ((rand() % 2) == 1) direction = 1; else direction = -1;
112 int speed = (BASE_SPEED + (rand() % RAND_SPEED)) * direction;
113 physic.set_velocity_x(speed);
114 movement_timer.start(MOVETIME);
115 lifetime.start(LIFETIME);
117 } else if(chit.normal.y < .5) { // bumped on roof
118 physic.set_velocity_y(0);
125 Kugelblitz::active_update(float elapsed_time)
127 if (lifetime.check()) {
131 if (groundhit_pos_set) {
132 if (movement_timer.check()) {
133 if (direction == 1) direction = -1; else direction = 1;
134 int speed = (BASE_SPEED + (rand() % RAND_SPEED)) * direction;
135 physic.set_velocity_x(speed);
136 movement_timer.start(MOVETIME);
139 if (Sector::current()->solids->get_tile_at(get_pos())->getAttributes() != 0)
140 std::cout << Sector::current()->solids->get_tile_at(get_pos())->getAttributes() << std::endl;
141 if (Sector::current()->solids->get_tile_at(get_pos())->getAttributes() == 16) {
143 Sector::current()->add_object(new Electrifier(75,1421,1.5));
144 Sector::current()->add_object(new Electrifier(76,1422,1.5));
147 if (Sector::current()->solids->get_tile_at(get_pos())->getAttributes() == 48) {
148 //HIT ELECTRIFIED WATER
152 BadGuy::active_update(elapsed_time);
156 Kugelblitz::kill_fall()
161 Kugelblitz::explode()
164 sprite->set_action("pop");
171 IMPLEMENT_FACTORY(Kugelblitz, "kugelblitz")