#include <unstable_tile.hpp>
Inherits MovingSprite.
Public Member Functions | |
UnstableTile (const Reader &lisp) | |
HitResponse | collision (GameObject &other, const CollisionHit &hit) |
this function is called when the object collided with any other object | |
void | update (float elapsed_time) |
This function is called once per frame and allows the object to update it's state. | |
Private Types | |
enum | State { STATE_NORMAL, STATE_SHAKE, STATE_DISSOLVE, STATE_SLOWFALL, STATE_FALL } |
Private Member Functions | |
void | startCrumbling () |
void | shake (void) |
void | dissolve (void) |
void | fall_down (void) |
void | slow_fall (void) |
Private Attributes | |
Physic | physic |
State | state |
float | slowfall_timer |
Definition at line 29 of file unstable_tile.hpp.
enum UnstableTile::State [private] |
Definition at line 38 of file unstable_tile.hpp.
00038 { 00039 STATE_NORMAL, 00040 STATE_SHAKE, 00041 STATE_DISSOLVE, 00042 STATE_SLOWFALL, 00043 STATE_FALL 00044 };
UnstableTile::UnstableTile | ( | const Reader & | lisp | ) |
Definition at line 27 of file unstable_tile.cpp.
References Physic::enable_gravity(), physic, Physic::set_gravity_modifier(), and MovingSprite::sprite.
00027 : 00028 MovingSprite(lisp, LAYER_TILES, COLGROUP_STATIC), 00029 physic(), 00030 state(STATE_NORMAL), 00031 slowfall_timer() 00032 { 00033 sprite->set_action("normal"); 00034 physic.set_gravity_modifier (.98); 00035 physic.enable_gravity (false); 00036 }
HitResponse UnstableTile::collision | ( | GameObject & | other, | |
const CollisionHit & | hit | |||
) | [virtual] |
this function is called when the object collided with any other object
Implements MovingObject.
Definition at line 39 of file unstable_tile.cpp.
References FORCE_MOVE, MovingObject::get_bbox(), Rectf::get_bottom(), Rectf::get_top(), shake(), SHIFT_DELTA, state, and STATE_NORMAL.
00040 { 00041 if(state == STATE_NORMAL) { 00042 Player* player = dynamic_cast<Player*> (&other); 00043 if(player != NULL && 00044 player->get_bbox().get_bottom() < get_bbox().get_top() + SHIFT_DELTA) { 00045 shake (); 00046 } 00047 00048 if (dynamic_cast<Explosion*> (&other)) { 00049 shake (); 00050 } 00051 } 00052 return FORCE_MOVE; 00053 }
void UnstableTile::update | ( | float | elapsed_time | ) | [virtual] |
This function is called once per frame and allows the object to update it's state.
The elapsed_time is the time since the last frame in seconds and should be the base for all timed calculations (don't use SDL_GetTicks directly as this will fail in pause mode)
Reimplemented from MovingSprite.
Definition at line 123 of file unstable_tile.cpp.
References COLGROUP_DISABLED, dissolve(), fall_down(), Physic::get_movement(), MovingObject::movement, physic, GameObject::remove_me(), MovingObject::set_group(), slowfall_timer, MovingSprite::sprite, state, STATE_DISSOLVE, STATE_FALL, STATE_NORMAL, STATE_SHAKE, and STATE_SLOWFALL.
00124 { 00125 switch (state) 00126 { 00127 case STATE_NORMAL: 00128 break; 00129 00130 case STATE_SHAKE: 00131 if (sprite->animation_done()) 00132 dissolve (); 00133 break; 00134 00135 case STATE_DISSOLVE: 00136 if (sprite->animation_done()) { 00137 /* dissolving is done. Set to non-solid. */ 00138 set_group (COLGROUP_DISABLED); 00139 fall_down (); 00140 } 00141 break; 00142 00143 case STATE_SLOWFALL: 00144 if (slowfall_timer >= elapsed_time) 00145 slowfall_timer -= elapsed_time; 00146 else /* Switch to normal falling procedure */ 00147 fall_down (); 00148 movement = physic.get_movement (elapsed_time); 00149 break; 00150 00151 case STATE_FALL: 00152 if (sprite->animation_done()) 00153 remove_me (); 00154 else 00155 movement = physic.get_movement (elapsed_time); 00156 break; 00157 } 00158 }
void UnstableTile::startCrumbling | ( | ) | [private] |
void UnstableTile::shake | ( | void | ) | [private] |
Definition at line 55 of file unstable_tile.cpp.
References dissolve(), MovingSprite::set_action(), MovingSprite::sprite, state, STATE_NORMAL, and STATE_SHAKE.
Referenced by collision().
00056 { 00057 if (state != STATE_NORMAL) 00058 return; 00059 00060 if (sprite->has_action ("shake")) { 00061 state = STATE_SHAKE; 00062 this->set_action ("shake", /* loops = */ 1); 00063 } 00064 else { 00065 dissolve (); 00066 } 00067 }
void UnstableTile::dissolve | ( | void | ) | [private] |
Definition at line 69 of file unstable_tile.cpp.
References MovingSprite::set_action(), slow_fall(), MovingSprite::sprite, state, STATE_DISSOLVE, STATE_NORMAL, and STATE_SHAKE.
Referenced by shake(), and update().
00070 { 00071 if ((state != STATE_NORMAL) && (state != STATE_SHAKE)) 00072 return; 00073 00074 if (sprite->has_action ("dissolve")) { 00075 state = STATE_DISSOLVE; 00076 this->set_action ("dissolve", /* loops = */ 1); 00077 } 00078 else { 00079 slow_fall (); 00080 } 00081 }
void UnstableTile::fall_down | ( | void | ) | [private] |
Definition at line 103 of file unstable_tile.cpp.
References Physic::enable_gravity(), physic, GameObject::remove_me(), MovingSprite::set_action(), Physic::set_gravity_modifier(), MovingSprite::sprite, state, STATE_DISSOLVE, STATE_FALL, STATE_NORMAL, STATE_SHAKE, and STATE_SLOWFALL.
Referenced by slow_fall(), and update().
00104 { 00105 if ((state != STATE_NORMAL) 00106 && (state != STATE_SHAKE) 00107 && (state != STATE_DISSOLVE) 00108 && (state != STATE_SLOWFALL)) 00109 return; 00110 00111 if (sprite->has_action ("fall-down")) { 00112 state = STATE_FALL; 00113 this->set_action ("fall-down", /* loops = */ 1); 00114 physic.set_gravity_modifier (.98); 00115 physic.enable_gravity (true); 00116 } 00117 else { 00118 remove_me (); 00119 } 00120 }
void UnstableTile::slow_fall | ( | void | ) | [private] |
Definition at line 83 of file unstable_tile.cpp.
References Physic::enable_gravity(), fall_down(), physic, GameObject::remove_me(), MovingSprite::set_action(), Physic::set_gravity_modifier(), slowfall_timer, MovingSprite::sprite, state, STATE_NORMAL, and STATE_SLOWFALL.
Referenced by dissolve().
00084 { 00085 /* Only enter slow-fall if neither shake nor dissolve is available. */ 00086 if (state != STATE_NORMAL) { 00087 this->fall_down (); 00088 return; 00089 } 00090 00091 if (sprite->has_action ("fall-down")) { 00092 state = STATE_SLOWFALL; 00093 this->set_action ("fall-down", /* loops = */ 1); 00094 physic.set_gravity_modifier (.10); 00095 physic.enable_gravity (true); 00096 slowfall_timer = 0.5; /* Fall slowly for half a second. */ 00097 } 00098 else { 00099 remove_me (); 00100 } 00101 }
Physic UnstableTile::physic [private] |
Definition at line 54 of file unstable_tile.hpp.
Referenced by fall_down(), slow_fall(), UnstableTile(), and update().
State UnstableTile::state [private] |
Definition at line 55 of file unstable_tile.hpp.
Referenced by collision(), dissolve(), fall_down(), shake(), slow_fall(), and update().
float UnstableTile::slowfall_timer [private] |