From e58a0205a8836820b53a7b875942bae7b0e629fd Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Mon, 4 Sep 2006 16:33:43 +0000 Subject: [PATCH] Stalactites interact with badguys again. Additional tile attribute FIRE for lava (=WATER, HURTS, FIRE). Badguys that collide with tiles that have HURTS and one of FIRE or ICE set are ignited or frozen instead of killed SVN-Revision: 4206 --- data/images/tiles.strf | 18 ++++++++++++++++++ src/badguy/badguy.cpp | 13 +++++++++++-- src/badguy/stalactite.cpp | 40 +++++++++++++++++++++++++++++++--------- src/badguy/stalactite.hpp | 3 +++ src/tile.cpp | 2 ++ src/tile.hpp | 2 ++ 6 files changed, 67 insertions(+), 11 deletions(-) diff --git a/data/images/tiles.strf b/data/images/tiles.strf index 59c03b5fc..cd287863a 100644 --- a/data/images/tiles.strf +++ b/data/images/tiles.strf @@ -1645,6 +1645,7 @@ ) (water #t) (hurts #t) + (fire #t) (anim-fps 10) ) (tile @@ -1657,6 +1658,7 @@ ) (water #t) (hurts #t) + (fire #t) (anim-fps 10) ) (tile @@ -5880,6 +5882,7 @@ "tiles/lava/zone/body-1-3.png" "tiles/lava/zone/body-1-4.png") (hurts #t) + (fire #t) (solid #f) (anim-fps 2) ) @@ -5891,6 +5894,7 @@ "tiles/lava/zone/edge-1-3.png" "tiles/lava/zone/edge-1-4.png") (hurts #t) + (fire #t) (solid #f) (anim-fps 2) ) @@ -5906,6 +5910,7 @@ "tiles/lava/zone/rest.png" "tiles/lava/zone/rest.png") (hurts #t) + (fire #t) (solid #f) (anim-fps 2) ) @@ -5921,6 +5926,7 @@ "tiles/lava/zone/bubble-in-1-3.png" "tiles/lava/zone/bubble-in-1-4.png") (hurts #t) + (fire #t) (solid #f) (anim-fps 2) ) @@ -5937,6 +5943,7 @@ "tiles/lava/zone/bubble-out-1-4.png" ) (hurts #t) + (fire #t) (solid #f) (anim-fps 2) ) @@ -5948,6 +5955,7 @@ "tiles/lava/zone/body-2-3.png" "tiles/lava/zone/body-2-4.png") (hurts #t) + (fire #t) (solid #f) (anim-fps 2) ) @@ -5959,6 +5967,7 @@ "tiles/lava/zone/body-bottom-1-3.png" "tiles/lava/zone/body-bottom-1-4.png") (hurts #t) + (fire #t) (solid #f) (anim-fps 2) ) @@ -5970,6 +5979,7 @@ "tiles/lava/zone/edge-right-1-3.png" "tiles/lava/zone/edge-right-1-4.png") (hurts #t) + (fire #t) (solid #f) (anim-fps 2) ) @@ -5991,6 +6001,7 @@ "tiles/lava/zone/edge-left-1-3.png" "tiles/lava/zone/edge-left-1-4.png") (hurts #t) + (fire #t) (solid #f) (anim-fps 2) ) @@ -6002,6 +6013,7 @@ "tiles/lava/zone/edge-right-1-2.png" "tiles/lava/zone/edge-right-1-1.png") (hurts #t) + (fire #t) (solid #f) (anim-fps 2) ) @@ -6013,6 +6025,7 @@ "tiles/lava/zone/edge-left-1-3.png" "tiles/lava/zone/edge-left-1-4.png") (hurts #t) + (fire #t) (solid #f) (anim-fps 2) ) @@ -6024,6 +6037,7 @@ "tiles/lava/zone/edge-flip-1-3.png" "tiles/lava/zone/edge-flip-1-4.png") (hurts #t) + (fire #t) (solid #f) (anim-fps 2) ) @@ -6035,6 +6049,7 @@ "tiles/lava/zone/bubble-bottom-1-3.png" "tiles/lava/zone/bubble-bottom-1-4.png") (hurts #t) + (fire #t) (solid #f) (anim-fps 2) ) @@ -6050,6 +6065,7 @@ "tiles/lava/zone/bubble-out-1-3.png" "tiles/lava/zone/bubble-out-1-4.png") (hurts #t) + (fire #t) (solid #f) (anim-fps 2) ) @@ -6065,6 +6081,7 @@ "tiles/lava/zone/rest.png" "tiles/lava/zone/rest.png") (hurts #t) + (fire #t) (solid #f) (anim-fps 2) ) @@ -6082,6 +6099,7 @@ "tiles/lava/zone/bubble-in-1-4.png" ) (hurts #t) + (fire #t) (solid #f) (anim-fps 2) ) diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index ae6c39f62..8d9ae8cc4 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -163,8 +163,17 @@ BadGuy::inactive_update(float ) void BadGuy::collision_tile(uint32_t tile_attributes) { - if(tile_attributes & Tile::HURTS) - kill_fall(); + if(tile_attributes & Tile::HURTS) { + if (tile_attributes & Tile::FIRE) { + if (is_flammable()) ignite(); + } + else if (tile_attributes & Tile::ICE) { + if (is_freezable()) freeze(); + } + else { + kill_fall(); + } + } } HitResponse diff --git a/src/badguy/stalactite.cpp b/src/badguy/stalactite.cpp index c0fd7be98..26b9fcd80 100644 --- a/src/badguy/stalactite.cpp +++ b/src/badguy/stalactite.cpp @@ -69,18 +69,23 @@ Stalactite::active_update(float elapsed_time) } void -Stalactite::collision_solid(const CollisionHit& hit) +Stalactite::squish() { - if(state != STALACTITE_FALLING && state != STALACTITE_SQUISHED) - return; + state = STALACTITE_SQUISHED; + set_group(COLGROUP_MOVING_ONLY_STATIC); + sprite->set_action("squished"); + if(!timer.started()) + timer.start(SQUISH_TIME); +} - if(hit.bottom) { // hit floor? - state = STALACTITE_SQUISHED; - set_group(COLGROUP_MOVING_ONLY_STATIC); +void +Stalactite::collision_solid(const CollisionHit& hit) +{ + if(state == STALACTITE_FALLING) { + if (hit.bottom) squish(); + } + if(state == STALACTITE_SQUISHED) { physic.set_velocity_y(0); - sprite->set_action("squished"); - if(!timer.started()) - timer.start(SQUISH_TIME); } } @@ -94,6 +99,23 @@ Stalactite::collision_player(Player& player) return FORCE_MOVE; } +HitResponse +Stalactite::collision_badguy(BadGuy& other, const CollisionHit& hit) +{ + if (state == STALACTITE_SQUISHED) return FORCE_MOVE; + if (state != STALACTITE_FALLING) return BadGuy::collision_badguy(other, hit); + + if (other.is_freezable()) { + other.freeze(); + } else { + other.kill_fall(); + } + + remove_me(); + + return FORCE_MOVE; +} + void Stalactite::kill_fall() { diff --git a/src/badguy/stalactite.hpp b/src/badguy/stalactite.hpp index ef48ede79..bf9484bfd 100644 --- a/src/badguy/stalactite.hpp +++ b/src/badguy/stalactite.hpp @@ -31,6 +31,7 @@ public: void write(lisp::Writer& writer); void collision_solid(const CollisionHit& hit); HitResponse collision_player(Player& player); + HitResponse collision_badguy(BadGuy& other, const CollisionHit& hit); void kill_fall(); void draw(DrawingContext& context); @@ -38,6 +39,8 @@ public: virtual Stalactite* clone() const { return new Stalactite(*this); } + void squish(); + protected: Timer timer; diff --git a/src/tile.cpp b/src/tile.cpp index fa0b8349d..ea18d8e56 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -73,6 +73,8 @@ Tile::parse(const lisp::Lisp& reader) attributes |= WATER; if(reader.get("hurts", value) && value) attributes |= HURTS; + if(reader.get("fire", value) && value) + attributes |= FIRE; if(reader.get("fullbox", value) && value) attributes |= FULLBOX; if(reader.get("coin", value) && value) diff --git a/src/tile.hpp b/src/tile.hpp index c03154f8e..e1b57f4b3 100644 --- a/src/tile.hpp +++ b/src/tile.hpp @@ -65,6 +65,8 @@ public: WATER = 0x0200, /** a tile that hurts the player if he touches it */ HURTS = 0x0400, + /** for lava: WATER, HURTS, FIRE */ + FIRE = 0x0800 }; /// worldmap flags -- 2.11.0