Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Unstable tile: Implement a "slow fall" phase for sprites without "sha…
…ke" 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
  • Loading branch information
Florian Forster committed Mar 15, 2010
1 parent 5e12ad4 commit 750df62
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
9 changes: 1 addition & 8 deletions data/images/objects/unstable_tile/iceplatform.sprite
Expand Up @@ -5,16 +5,9 @@
"iceplatform.png"
)
)
(action
(name "shake")
(fps 2)
(images
"iceplatform.png"
)
)
(action
(name "fall-down")
(fps 1)
(fps 0.2)
(images
"iceplatform.png"
)
Expand Down
34 changes: 32 additions & 2 deletions src/object/unstable_tile.cpp
Expand Up @@ -75,20 +75,42 @@ 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 ();
}
}

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 {
Expand Down Expand Up @@ -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 ();
Expand Down
3 changes: 3 additions & 0 deletions src/object/unstable_tile.hpp
Expand Up @@ -39,6 +39,7 @@ class UnstableTile : public MovingSprite
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 */
};

Expand All @@ -48,9 +49,11 @@ class UnstableTile : public MovingSprite
void shake (void);
void dissolve (void);
void fall_down (void);
void slow_fall (void);

Physic physic;
State state;
float slowfall_timer;
};

#endif
Expand Down

0 comments on commit 750df62

Please sign in to comment.