X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbadguy%2Fkugelblitz.cpp;h=813492d1549dfe448aba8ed0aab6002cc16aaf85;hb=8b8e1c3576cedddb1d88eafa5fd4804e8257793c;hp=a3e21286b6056c7cfc2ac621bdef8d32f7d79412;hpb=07ddaed2a657e4d2a3d038fed223fc5827159caf;p=supertux.git diff --git a/src/badguy/kugelblitz.cpp b/src/badguy/kugelblitz.cpp index a3e21286b..813492d15 100644 --- a/src/badguy/kugelblitz.cpp +++ b/src/badguy/kugelblitz.cpp @@ -23,6 +23,7 @@ #include "object/tilemap.hpp" #include "object/camera.hpp" #include "tile.hpp" +#include "random_generator.hpp" #define LIFETIME 5 #define MOVETIME 0.75 @@ -33,12 +34,9 @@ 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(reader, "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("images/creatures/kugelblitz/kugelblitz.sprite"); sprite->set_action("falling"); physic.enable_gravity(false); } @@ -54,18 +52,18 @@ Kugelblitz::write(lisp::Writer& writer) } void -Kugelblitz::activate() +Kugelblitz::initialize() { - 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; } -HitResponse -Kugelblitz::collision_solid(GameObject& , const CollisionHit& chit) +void +Kugelblitz::collision_solid(const CollisionHit& chit) { - return hit(chit); + hit(chit); } HitResponse @@ -80,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; } @@ -99,10 +97,10 @@ Kugelblitz::collision_badguy(BadGuy& other , const CollisionHit& chit) } HitResponse -Kugelblitz::hit(const CollisionHit& chit) +Kugelblitz::hit(const CollisionHit& hit) { // hit floor? - if(chit.normal.y < -.5) { + if(hit.bottom) { if (!groundhit_pos_set) { pos_groundhit = get_pos(); @@ -111,13 +109,13 @@ 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); - } else if(chit.normal.y < .5) { // bumped on roof + } else if(hit.top) { // bumped on roof physic.set_velocity_y(0); } @@ -134,11 +132,12 @@ 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() == 16) { //HIT WATER Sector::current()->add_object(new Electrifier(75,1421,1.5)); @@ -149,8 +148,9 @@ Kugelblitz::active_update(float elapsed_time) //HIT ELECTRIFIED WATER explode(); } + */ } - BadGuy::active_update(elapsed_time); + BadGuy::active_update(elapsed_time); } void @@ -163,7 +163,7 @@ Kugelblitz::explode() { if (!dying) { sprite->set_action("pop"); - lifetime.start(0.2); + lifetime.start(0.2f); dying = true; } else remove_me();