From: Marek Moeckel Date: Thu, 30 Dec 2004 11:29:52 +0000 (+0000) Subject: badguys can now have multiple hitpoints (default is 1) X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9e3d8f3cc7a07ab4dae67e86c6f1d0e0e450fa54;p=supertux.git badguys can now have multiple hitpoints (default is 1) gave Nolok 3 hitpoints SVN-Revision: 2266 --- diff --git a/data/levels/test/noloktest.stl b/data/levels/test/noloktest.stl index 6468f6ded..f832cea59 100644 --- a/data/levels/test/noloktest.stl +++ b/data/levels/test/noloktest.stl @@ -51,6 +51,7 @@ (spawnpoint (name "main2") (x 100) (y 100)) (secretarea (x 100) (y 100) (message "You found a secret area!")) (dispenser (x 700) (y 500) (badguy "snowball") (cycle 2)) + (jumpy (x 500) (y 400)) (tilemap (layer "background") (solid #f) diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index 4a209783c..e010794bd 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -10,6 +10,7 @@ static const float Y_OFFSCREEN_DISTANCE = 1200; BadGuy::BadGuy() : sprite(0), dir(LEFT), state(STATE_INIT) { + hitpoints = 1; } BadGuy::~BadGuy() @@ -131,8 +132,17 @@ BadGuy::collision_player(Player& player, const CollisionHit& hit) return ABORT_MOVE; } if(hit.normal.y > .9) { + //TODO: fix inaccuracy (tux sometimes dies even if badguy was hit) + // give badguys some invincible time (prevent them from being hit multiple times) + // use hitpoints also when hit by fireball or invincible tux + hitpoints--; + std::cout << "Hitpoints: " << hitpoints << std::endl; if(collision_squished(player)) return ABORT_MOVE; + else if (hitpoints <= 0) { + player.kill(Player::SHRINK); + return FORCE_MOVE; + } } player.kill(Player::SHRINK); return FORCE_MOVE; diff --git a/src/badguy/badguy.h b/src/badguy/badguy.h index 075b02558..c7c24e101 100644 --- a/src/badguy/badguy.h +++ b/src/badguy/badguy.h @@ -91,6 +91,8 @@ protected: Vector start_position; Direction dir; + + int hitpoints; private: void try_activate(); diff --git a/src/badguy/nolok_01.cpp b/src/badguy/nolok_01.cpp index f5a1c9409..e3b7c00f4 100644 --- a/src/badguy/nolok_01.cpp +++ b/src/badguy/nolok_01.cpp @@ -7,10 +7,11 @@ #define WALK_TIME 2.5 #define SHOOT_TIME 0.4 #define JUMP_TIME 0.5 +#define INITIAL_HITPOINTS 3 static const float WALKSPEED = 90; -//TODO: Create sprite, give multiple hitpoints, limit max number of snowballs +//TODO: Create sprite, limit max number of snowballs // Stop actions when pause button is hit (probably a general problem of timers) Nolok_01::Nolok_01(const lisp::Lisp& reader) { @@ -42,6 +43,7 @@ Nolok_01::write(lisp::Writer& writer) void Nolok_01::activate() { + hitpoints = INITIAL_HITPOINTS; physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "left" : "right"); action = WALKING; @@ -86,10 +88,15 @@ Nolok_01::active_action(float elapsed_time) bool Nolok_01::collision_squished(Player& player) { - sprite->set_action("dead"); - kill_squished(player); - Sector::current()->add_object(new Door((int)get_pos().x+32, 512, "sector1", "main2")); - return true; + bool result = false; + player.bounce(*this); + if (hitpoints <= 0) { + sprite->set_action("dead"); + kill_squished(player); + Sector::current()->add_object(new Door((int)get_pos().x+32, 512, "sector1", "main2")); + result = true; + } + return result; } HitResponse @@ -106,4 +113,4 @@ Nolok_01::collision_solid(GameObject& , const CollisionHit& hit) return CONTINUE; } -IMPLEMENT_FACTORY(Nolok_01, "nolok01") +IMPLEMENT_FACTORY(Nolok_01, "nolok_01") diff --git a/src/trigger/secretarea_trigger.cpp b/src/trigger/secretarea_trigger.cpp index 475103e60..69c9d2a23 100644 --- a/src/trigger/secretarea_trigger.cpp +++ b/src/trigger/secretarea_trigger.cpp @@ -71,3 +71,5 @@ SecretAreaTrigger::event(Player& , EventType type) } } } + +//IMPLEMENT_FACTORY(SecretAreaTrigger, "secretarea_trigger")