X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbadguy%2Fkugelblitz.cpp;h=f8ecf170366c7f4f6fbb02b20e445a51b41df5ab;hb=8a598e8d635ee4d629371493fef50826a38cd20d;hp=dd47c3168d2f3ddfb36be540e8f795d46132b3de;hpb=50e6fcee63ad5a258a6ad1df2923fa50d2c26dc3;p=supertux.git diff --git a/src/badguy/kugelblitz.cpp b/src/badguy/kugelblitz.cpp index dd47c3168..f8ecf1703 100644 --- a/src/badguy/kugelblitz.cpp +++ b/src/badguy/kugelblitz.cpp @@ -1,7 +1,7 @@ -// $Id: Kugelblitz.cpp 2654 2005-06-29 14:16:22Z wansti $ -// +// $Id$ +// // SuperTux -// Copyright (C) 2005 Marek Moeckel +// Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -12,29 +12,31 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -// 02111-1307, USA. +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + #include #include "kugelblitz.hpp" #include "object/tilemap.hpp" +#include "object/camera.hpp" #include "tile.hpp" +#include "random_generator.hpp" #define LIFETIME 5 #define MOVETIME 0.75 #define BASE_SPEED 200 #define RAND_SPEED 150 +static const float X_OFFSCREEN_DISTANCE = 1600; +static const float Y_OFFSCREEN_DISTANCE = 1200; + Kugelblitz::Kugelblitz(const lisp::Lisp& reader) - : groundhit_pos_set(false) + : BadGuy(Vector(0,0), "images/creatures/kugelblitz/kugelblitz.sprite"), groundhit_pos_set(false) { reader.get("x", start_position.x); - start_position.y = 0; //place above visible area - bbox.set_size(63.8, 63.8); - sprite = sprite_manager->create("kugelblitz"); sprite->set_action("falling"); physic.enable_gravity(false); } @@ -45,7 +47,6 @@ Kugelblitz::write(lisp::Writer& writer) writer.start_list("kugelblitz"); writer.write_float("x", start_position.x); - writer.write_float("y", start_position.y); writer.end_list("kugelblitz"); } @@ -53,7 +54,7 @@ Kugelblitz::write(lisp::Writer& writer) void Kugelblitz::activate() { - physic.set_velocity_y(-300); + physic.set_velocity_y(300); physic.set_velocity_x(-20); //fall a little to the left direction = 1; dying = false; @@ -77,11 +78,11 @@ Kugelblitz::collision_player(Player& player, const CollisionHit& ) (get_bbox().p1.y + get_bbox().p2.y) / 2) { // if it's not is it possible to squish us, then this will hurt if(!collision_squished(player)) - player.kill(Player::SHRINK); + player.kill(false); explode(); return FORCE_MOVE; } - player.kill(Player::SHRINK); + player.kill(false); explode(); return FORCE_MOVE; } @@ -108,8 +109,8 @@ Kugelblitz::hit(const CollisionHit& chit) sprite->set_action("flying"); physic.set_velocity_y(0); //Set random initial speed and direction - if ((rand() % 2) == 1) direction = 1; else direction = -1; - int speed = (BASE_SPEED + (rand() % RAND_SPEED)) * direction; + direction = systemRandom.rand(2)? 1: -1; + int speed = (BASE_SPEED + (systemRandom.rand(RAND_SPEED))) * direction; physic.set_velocity_x(speed); movement_timer.start(MOVETIME); lifetime.start(LIFETIME); @@ -131,13 +132,11 @@ Kugelblitz::active_update(float elapsed_time) if (groundhit_pos_set) { if (movement_timer.check()) { if (direction == 1) direction = -1; else direction = 1; - int speed = (BASE_SPEED + (rand() % RAND_SPEED)) * direction; + int speed = (BASE_SPEED + (systemRandom.rand(RAND_SPEED))) * direction; physic.set_velocity_x(speed); movement_timer.start(MOVETIME); } } - if (Sector::current()->solids->get_tile_at(get_pos())->getAttributes() != 0) - std::cout << Sector::current()->solids->get_tile_at(get_pos())->getAttributes() << std::endl; if (Sector::current()->solids->get_tile_at(get_pos())->getAttributes() == 16) { //HIT WATER Sector::current()->add_object(new Electrifier(75,1421,1.5)); @@ -168,4 +167,48 @@ Kugelblitz::explode() else remove_me(); } +void +Kugelblitz::try_activate() +{ + //FIXME: Don't activate Kugelblitz before it's on-screen + float scroll_x = Sector::current()->camera->get_translation().x; + float scroll_y = Sector::current()->camera->get_translation().y; + + /* Activate badguys if they're just around the screen to avoid + * the effect of having badguys suddenly popping up from nowhere. + */ + if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE && + start_position.x < scroll_x - bbox.get_width() && + start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE && + start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE) { + dir = RIGHT; + set_state(STATE_ACTIVE); + activate(); + } else if (start_position.x > scroll_x && + start_position.x < scroll_x + X_OFFSCREEN_DISTANCE && + start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE && + start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE) { + dir = LEFT; + set_state(STATE_ACTIVE); + activate(); + } else if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE && + start_position.x < scroll_x + X_OFFSCREEN_DISTANCE && + ((start_position.y > scroll_y && + start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE) || + (start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE && + start_position.y < scroll_y))) { + dir = start_position.x < scroll_x ? RIGHT : LEFT; + set_state(STATE_ACTIVE); + activate(); + } else if(state == STATE_INIT + && start_position.x > scroll_x - X_OFFSCREEN_DISTANCE + && start_position.x < scroll_x + X_OFFSCREEN_DISTANCE + && start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE + && start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE) { + dir = LEFT; + set_state(STATE_ACTIVE); + activate(); + } +} + IMPLEMENT_FACTORY(Kugelblitz, "kugelblitz")