From: Christoph Sommer Date: Sat, 26 May 2007 15:36:06 +0000 (+0000) Subject: (Tree)WillOWisps no longer collide with closed lamps. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=78bfc5227135b72fcbb651043c6774e0022fa2fd;p=supertux.git (Tree)WillOWisps no longer collide with closed lamps. TreeWillOWisps now hurt Tux. SVN-Revision: 5024 --- diff --git a/src/badguy/treewillowisp.cpp b/src/badguy/treewillowisp.cpp index c31531ff3..9ec089705 100644 --- a/src/badguy/treewillowisp.cpp +++ b/src/badguy/treewillowisp.cpp @@ -63,15 +63,15 @@ TreeWillOWisp::vanish() HitResponse TreeWillOWisp::collision_player(Player& player, const CollisionHit& hit) { - (void) player; - (void) hit; - - return FORCE_MOVE; + //TODO: basically a no-op. Remove if this doesn't change. + return BadGuy::collision_player(player, hit); } bool TreeWillOWisp::collides(GameObject& other, const CollisionHit& ) { - if (dynamic_cast(&other)) return true; + Lantern* lantern = dynamic_cast(&other); + if (lantern && lantern->is_open()) return true; + if (dynamic_cast(&other)) return true; return false; } diff --git a/src/badguy/treewillowisp.hpp b/src/badguy/treewillowisp.hpp index b57dcc76e..49b8d076a 100644 --- a/src/badguy/treewillowisp.hpp +++ b/src/badguy/treewillowisp.hpp @@ -40,6 +40,10 @@ public: void set_color(const Color& color); Color get_color() const; + virtual bool is_flammable() const { return false; } + virtual bool is_freezable() const { return false; } + virtual void kill_fall() { vanish(); } + protected: virtual bool collides(GameObject& other, const CollisionHit& hit); HitResponse collision_player(Player& player, const CollisionHit& hit); diff --git a/src/badguy/willowisp.cpp b/src/badguy/willowisp.cpp index 657bed89a..a4fecd897 100644 --- a/src/badguy/willowisp.cpp +++ b/src/badguy/willowisp.cpp @@ -139,11 +139,6 @@ WillOWisp::deactivate() } void -WillOWisp::kill_fall() -{ -} - -void WillOWisp::vanish() { mystate = STATE_VANISHING; @@ -153,7 +148,8 @@ WillOWisp::vanish() bool WillOWisp::collides(GameObject& other, const CollisionHit& ) { - if (dynamic_cast(&other)) return true; + Lantern* lantern = dynamic_cast(&other); + if (lantern && lantern->is_open()) return true; if (dynamic_cast(&other)) return true; return false; } diff --git a/src/badguy/willowisp.hpp b/src/badguy/willowisp.hpp index 78ea5c762..c21933d53 100644 --- a/src/badguy/willowisp.hpp +++ b/src/badguy/willowisp.hpp @@ -33,7 +33,9 @@ public: void write(lisp::Writer& write); void active_update(float elapsed_time); - void kill_fall(); + virtual bool is_flammable() const { return false; } + virtual bool is_freezable() const { return false; } + virtual void kill_fall() { vanish(); } /** * make WillOWisp vanish diff --git a/src/object/lantern.cpp b/src/object/lantern.cpp index a91b15ffc..605983e22 100644 --- a/src/object/lantern.cpp +++ b/src/object/lantern.cpp @@ -69,7 +69,7 @@ Lantern::draw(DrawingContext& context){ } HitResponse Lantern::collision(GameObject& other, const CollisionHit& hit) { - if ((grabbed) && lightcolor.red == 0 && lightcolor.green == 0 && lightcolor.blue == 0){ + if (is_open()) { WillOWisp* wow = dynamic_cast(&other); if (wow) { // collided with WillOWisp while grabbed and unlit @@ -94,7 +94,7 @@ Lantern::grab(MovingObject& object, const Vector& pos, Direction dir) Rock::grab(object, pos, dir); // if lantern is not lit, draw it as opened - if(lightcolor.red == 0 && lightcolor.green == 0 && lightcolor.blue == 0){ + if (is_open()) { sprite->set_action("off-open"); } @@ -103,12 +103,18 @@ Lantern::grab(MovingObject& object, const Vector& pos, Direction dir) void Lantern::ungrab(MovingObject& object, Direction dir) { - Rock::ungrab(object, dir); - // if lantern is not lit, it was drawn as opened while grabbed. Now draw it as closed again - if(lightcolor.red == 0 && lightcolor.green == 0 && lightcolor.blue == 0){ + if (is_open()) { sprite->set_action("off"); } + + Rock::ungrab(object, dir); +} + +bool +Lantern::is_open() +{ + return ((grabbed) && lightcolor.red == 0 && lightcolor.green == 0 && lightcolor.blue == 0); } IMPLEMENT_FACTORY(Lantern, "lantern"); diff --git a/src/object/lantern.hpp b/src/object/lantern.hpp index f99110585..a41e3869f 100644 --- a/src/object/lantern.hpp +++ b/src/object/lantern.hpp @@ -38,6 +38,11 @@ public: void grab(MovingObject& object, const Vector& pos, Direction dir); void ungrab(MovingObject& object, Direction dir); + /** + * returns true if lamp is currently open + */ + bool is_open(); + private: Color lightcolor; Sprite* lightsprite;