From 750df62bd38c2430e109f39e8cf9861805788a24 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 15 Mar 2010 20:21:03 +0000 Subject: [PATCH] Unstable tile: Implement a "slow fall" phase for sprites without "shake" and "dissolve" actions. Sprites with neither a "shake" nor a "dissolve" action now start to fall down immediately. For the first 0.5 seconds, the gravity modifier is set to 10% though, so that the movement is *very* slow at first. It is noticable however and hints at the instability of the tile. Hopefully, players won't be surprised by a falling platform anymore now. SVN-Revision: 6612 --- .../objects/unstable_tile/iceplatform.sprite | 9 +----- src/object/unstable_tile.cpp | 34 ++++++++++++++++++++-- src/object/unstable_tile.hpp | 3 ++ 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/data/images/objects/unstable_tile/iceplatform.sprite b/data/images/objects/unstable_tile/iceplatform.sprite index 076933285..51c691b5e 100644 --- a/data/images/objects/unstable_tile/iceplatform.sprite +++ b/data/images/objects/unstable_tile/iceplatform.sprite @@ -6,15 +6,8 @@ ) ) (action - (name "shake") - (fps 2) - (images - "iceplatform.png" - ) - ) - (action (name "fall-down") - (fps 1) + (fps 0.2) (images "iceplatform.png" ) diff --git a/src/object/unstable_tile.cpp b/src/object/unstable_tile.cpp index f83d71614..d31d5e625 100644 --- a/src/object/unstable_tile.cpp +++ b/src/object/unstable_tile.cpp @@ -75,7 +75,27 @@ void UnstableTile::dissolve (void) this->set_action ("dissolve", /* loops = */ 1); } else { - fall_down (); + slow_fall (); + } +} + +void UnstableTile::slow_fall (void) +{ + /* Only enter slow-fall if neither shake nor dissolve is available. */ + if (state != STATE_NORMAL) { + this->fall_down (); + return; + } + + if (sprite->has_action ("fall-down")) { + state = STATE_SLOWFALL; + this->set_action ("fall-down", /* loops = */ 1); + physic.set_gravity_modifier (.10); + physic.enable_gravity (true); + slowfall_timer = 0.5; /* Fall slowly for half a second. */ + } + else { + remove_me (); } } @@ -83,12 +103,14 @@ void UnstableTile::fall_down (void) { if ((state != STATE_NORMAL) && (state != STATE_SHAKE) - && (state != STATE_DISSOLVE)) + && (state != STATE_DISSOLVE) + && (state != STATE_SLOWFALL)) return; if (sprite->has_action ("fall-down")) { state = STATE_FALL; this->set_action ("fall-down", /* loops = */ 1); + physic.set_gravity_modifier (.98); physic.enable_gravity (true); } else { @@ -117,6 +139,14 @@ UnstableTile::update(float elapsed_time) } break; + case STATE_SLOWFALL: + if (slowfall_timer >= elapsed_time) + slowfall_timer -= elapsed_time; + else /* Switch to normal falling procedure */ + fall_down (); + movement = physic.get_movement (elapsed_time); + break; + case STATE_FALL: if (sprite->animation_done()) remove_me (); diff --git a/src/object/unstable_tile.hpp b/src/object/unstable_tile.hpp index aea657ddf..d041d9574 100644 --- a/src/object/unstable_tile.hpp +++ b/src/object/unstable_tile.hpp @@ -39,6 +39,7 @@ private: STATE_NORMAL, /**< default state */ STATE_SHAKE, /**< shaking, still solid */ STATE_DISSOLVE, /**< dissolving, will turn non-solid after this */ + STATE_SLOWFALL, /**< slow fall phase (used when neither shaking nor dissolving exist */ STATE_FALL /**< falling down */ }; @@ -48,9 +49,11 @@ private: void shake (void); void dissolve (void); void fall_down (void); + void slow_fall (void); Physic physic; State state; + float slowfall_timer; }; #endif -- 2.11.0