X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbadguy%2Fkugelblitz.cpp;h=94be0586410866d2090203f6a9ac2e61edf7d2a9;hb=9890da50f82d286c67e72feefcc423d1bc9076c3;hp=271bb8f785127bd229bd7d17c517c2c652a39d7a;hpb=ab908ed70c6ab1faba15e48b70aa50b90a152043;p=supertux.git diff --git a/src/badguy/kugelblitz.cpp b/src/badguy/kugelblitz.cpp index 271bb8f78..94be05864 100644 --- a/src/badguy/kugelblitz.cpp +++ b/src/badguy/kugelblitz.cpp @@ -20,10 +20,14 @@ #include #include "kugelblitz.hpp" -#include "sector.hpp" #include "object/tilemap.hpp" #include "tile.hpp" +#define LIFETIME 5 +#define MOVETIME 0.75 +#define BASE_SPEED 200 +#define RAND_SPEED 150 + Kugelblitz::Kugelblitz(const lisp::Lisp& reader) : groundhit_pos_set(false) { @@ -52,18 +56,41 @@ Kugelblitz::activate() 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& other, const CollisionHit& chit) +Kugelblitz::collision_solid(GameObject& , const CollisionHit& chit) { return hit(chit); } HitResponse +Kugelblitz::collision_player(Player& player, const CollisionHit& ) +{ + if(player.is_invincible()) { + explode(); + return ABORT_MOVE; + } + // hit from above? + if(player.get_movement().y - get_movement().y > 0 && player.get_bbox().p2.y < + (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); + explode(); + return FORCE_MOVE; + } + player.kill(Player::SHRINK); + explode(); + return FORCE_MOVE; +} + +HitResponse Kugelblitz::collision_badguy(BadGuy& other , const CollisionHit& chit) { - //Let the Kugelblitz explode, too? + //Let the Kugelblitz explode, too? The problem with that is that + //two Kugelblitzes would cancel each other out on contact... other.kill_fall(); return hit(chit); } @@ -80,7 +107,12 @@ Kugelblitz::hit(const CollisionHit& chit) } sprite->set_action("flying"); physic.set_velocity_y(0); - movement_timer.start(1500); + //Set random initial speed and direction + if ((rand() % 2) == 1) direction = 1; else direction = -1; + int speed = (BASE_SPEED + (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 physic.set_velocity_y(0); @@ -92,20 +124,42 @@ Kugelblitz::hit(const CollisionHit& chit) void Kugelblitz::active_update(float elapsed_time) { - if (groundhit_pos_set) { - if (movement_timer.check()) { - //std::cout << "IM HERE" << std::endl; - //FIXME: Find out why the program never gets here - if (direction == 1) direction = -1; else direction = 1; - int speed = (300 + (rand() % 300)) * direction; - physic.set_velocity_x(speed); - movement_timer.start(1500); - } + if (lifetime.check()) { + explode(); } - if (Sector::current()->solids->get_tile_at(get_pos())->getAttributes() == 16) { - //HIT WATER + else { + if (groundhit_pos_set) { + if (movement_timer.check()) { + if (direction == 1) direction = -1; else direction = 1; + int speed = (BASE_SPEED + (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)); + Sector::current()->add_object(new Electrifier(76,1422,1.5)); + explode(); + } } BadGuy::active_update(elapsed_time); } +void +Kugelblitz::kill_fall() +{ +} + +void +Kugelblitz::explode() +{ + if (!dying) { + sprite->set_action("pop"); + lifetime.start(0.2); + dying = true; + } + else remove_me(); +} + IMPLEMENT_FACTORY(Kugelblitz, "kugelblitz")