#include <snail.hpp>
Inherits WalkingBadguy.
Public Member Functions | |
Snail (const Reader &reader) | |
Snail (const Vector &pos, Direction d) | |
void | initialize () |
called immediately before the first call to initialize | |
void | collision_solid (const CollisionHit &hit) |
Called when the badguy collided with solid ground. | |
HitResponse | collision_badguy (BadGuy &badguy, const CollisionHit &hit) |
Called when the badguy collided with another badguy. | |
HitResponse | collision_player (Player &player, const CollisionHit &hit) |
Called when the badguy collided with a player. | |
bool | can_break () |
True if this badguy can break bricks or open bonusblocks in his current form. | |
void | active_update (float elapsed_time) |
called each frame when the badguy is activated. | |
Protected Member Functions | |
bool | collision_squished (GameObject &object) |
Called when the player hit the badguy from above. | |
void | be_normal () |
switch to state STATE_NORMAL | |
void | be_flat () |
switch to state STATE_FLAT | |
void | be_kicked () |
switch to state STATE_KICKED_DELAY | |
Private Types | |
enum | State { STATE_NORMAL, STATE_FLAT, STATE_KICKED_DELAY, STATE_KICKED } |
Private Attributes | |
State | state |
Timer | kicked_delay_timer |
wait time until switching from STATE_KICKED_DELAY to STATE_KICKED | |
int | squishcount |
Definition at line 25 of file snail.hpp.
enum Snail::State [private] |
STATE_NORMAL | walking around |
STATE_FLAT | flipped upside-down |
STATE_KICKED_DELAY | short delay before being launched |
STATE_KICKED | launched |
Reimplemented from BadGuy.
Definition at line 46 of file snail.hpp.
00046 { 00047 STATE_NORMAL, 00048 STATE_FLAT, 00049 STATE_KICKED_DELAY, 00050 STATE_KICKED 00051 };
Snail::Snail | ( | const Reader & | reader | ) |
Definition at line 32 of file snail.cpp.
References WalkingBadguy::max_drop_height, SoundManager::preload(), sound_manager, and WalkingBadguy::walk_speed.
00032 : 00033 WalkingBadguy(reader, "images/creatures/snail/snail.sprite", "left", "right"), 00034 state(STATE_NORMAL), 00035 kicked_delay_timer(), 00036 squishcount(0) 00037 { 00038 walk_speed = 80; 00039 max_drop_height = 600; 00040 sound_manager->preload("sounds/iceblock_bump.wav"); 00041 sound_manager->preload("sounds/stomp.wav"); 00042 sound_manager->preload("sounds/kick.wav"); 00043 }
Definition at line 45 of file snail.cpp.
References WalkingBadguy::max_drop_height, SoundManager::preload(), sound_manager, and WalkingBadguy::walk_speed.
00045 : 00046 WalkingBadguy(pos, d, "images/creatures/snail/snail.sprite", "left", "right"), 00047 state(STATE_NORMAL), 00048 kicked_delay_timer(), 00049 squishcount(0) 00050 { 00051 walk_speed = 80; 00052 max_drop_height = 600; 00053 sound_manager->preload("sounds/iceblock_bump.wav"); 00054 sound_manager->preload("sounds/stomp.wav"); 00055 sound_manager->preload("sounds/kick.wav"); 00056 }
void Snail::initialize | ( | ) | [virtual] |
called immediately before the first call to initialize
Reimplemented from WalkingBadguy.
Definition at line 59 of file snail.cpp.
References be_normal(), and WalkingBadguy::initialize().
00060 { 00061 WalkingBadguy::initialize(); 00062 be_normal(); 00063 }
void Snail::collision_solid | ( | const CollisionHit & | hit | ) | [virtual] |
Called when the badguy collided with solid ground.
Reimplemented from WalkingBadguy.
Definition at line 136 of file snail.cpp.
References WalkingBadguy::collision_solid(), BadGuy::dir, MovingObject::get_pos(), Physic::get_velocity_x(), LEFT, BadGuy::physic, SoundManager::play(), RIGHT, Physic::set_velocity_x(), Physic::set_velocity_y(), sound_manager, MovingSprite::sprite, state, STATE_FLAT, STATE_KICKED, STATE_KICKED_DELAY, STATE_NORMAL, and BadGuy::update_on_ground_flag().
00137 { 00138 switch (state) { 00139 case STATE_NORMAL: 00140 WalkingBadguy::collision_solid(hit); 00141 return; 00142 case STATE_KICKED: 00143 if(hit.left || hit.right) { 00144 sound_manager->play("sounds/iceblock_bump.wav", get_pos()); 00145 00146 if( ( dir == LEFT && hit.left ) || ( dir == RIGHT && hit.right) ){ 00147 dir = (dir == LEFT) ? RIGHT : LEFT; 00148 sprite->set_action(dir == LEFT ? "flat-left" : "flat-right"); 00149 00150 physic.set_velocity_x(-physic.get_velocity_x()); 00151 } 00152 } 00153 /* fall-through */ 00154 case STATE_FLAT: 00155 case STATE_KICKED_DELAY: 00156 if(hit.top || hit.bottom) { 00157 physic.set_velocity_y(0); 00158 } 00159 break; 00160 } 00161 00162 update_on_ground_flag(hit); 00163 00164 }
HitResponse Snail::collision_badguy | ( | BadGuy & | badguy, | |
const CollisionHit & | hit | |||
) | [virtual] |
Called when the badguy collided with another badguy.
Reimplemented from WalkingBadguy.
Definition at line 167 of file snail.cpp.
References ABORT_MOVE, WalkingBadguy::collision_badguy(), FORCE_MOVE, state, STATE_FLAT, STATE_KICKED, STATE_KICKED_DELAY, and STATE_NORMAL.
00168 { 00169 switch(state) { 00170 case STATE_NORMAL: 00171 return WalkingBadguy::collision_badguy(badguy, hit); 00172 case STATE_FLAT: 00173 case STATE_KICKED_DELAY: 00174 return FORCE_MOVE; 00175 case STATE_KICKED: 00176 badguy.kill_fall(); 00177 return FORCE_MOVE; 00178 default: 00179 assert(false); 00180 } 00181 00182 return ABORT_MOVE; 00183 }
HitResponse Snail::collision_player | ( | Player & | player, | |
const CollisionHit & | hit | |||
) | [virtual] |
Called when the badguy collided with a player.
Reimplemented from BadGuy.
Definition at line 186 of file snail.cpp.
References be_kicked(), BadGuy::collision_player(), BadGuy::dir, FORCE_MOVE, Player::kick(), LEFT, CollisionHit::left, RIGHT, CollisionHit::right, state, and STATE_FLAT.
00187 { 00188 // handle kicks from left or right side 00189 if(state == STATE_FLAT && (hit.left || hit.right)) { 00190 if(hit.left) { 00191 dir = RIGHT; 00192 } else if(hit.right) { 00193 dir = LEFT; 00194 } 00195 player.kick(); 00196 be_kicked(); 00197 return FORCE_MOVE; 00198 } 00199 00200 return BadGuy::collision_player(player, hit); 00201 }
bool Snail::can_break | ( | ) | [virtual] |
True if this badguy can break bricks or open bonusblocks in his current form.
Reimplemented from BadGuy.
Definition at line 98 of file snail.cpp.
References state, and STATE_KICKED.
00098 { 00099 return state == STATE_KICKED; 00100 }
void Snail::active_update | ( | float | elapsed_time | ) | [virtual] |
called each frame when the badguy is activated.
Reimplemented from WalkingBadguy.
Definition at line 103 of file snail.cpp.
References BadGuy::active_update(), WalkingBadguy::active_update(), be_normal(), Timer::check(), BadGuy::dir, Physic::get_velocity_x(), kicked_delay_timer, LEFT, BadGuy::physic, Physic::set_velocity_x(), Physic::set_velocity_y(), SNAIL_KICK_SPEED, SNAIL_KICK_SPEED_Y, MovingSprite::sprite, state, STATE_FLAT, STATE_KICKED, STATE_KICKED_DELAY, STATE_NORMAL, and WalkingBadguy::walk_speed.
00104 { 00105 switch (state) { 00106 00107 case STATE_NORMAL: 00108 WalkingBadguy::active_update(elapsed_time); 00109 return; 00110 00111 case STATE_FLAT: 00112 if (sprite->animation_done()) { 00113 be_normal(); 00114 } 00115 break; 00116 00117 case STATE_KICKED_DELAY: 00118 if (kicked_delay_timer.check()) { 00119 physic.set_velocity_x(dir == LEFT ? -SNAIL_KICK_SPEED : SNAIL_KICK_SPEED); 00120 physic.set_velocity_y(SNAIL_KICK_SPEED_Y); 00121 state = STATE_KICKED; 00122 } 00123 break; 00124 00125 case STATE_KICKED: 00126 physic.set_velocity_x(physic.get_velocity_x() * pow(0.99, elapsed_time/0.02)); 00127 if (sprite->animation_done() || (fabsf(physic.get_velocity_x()) < walk_speed)) be_normal(); 00128 break; 00129 00130 } 00131 00132 BadGuy::active_update(elapsed_time); 00133 }
bool Snail::collision_squished | ( | GameObject & | object | ) | [protected, virtual] |
Called when the player hit the badguy from above.
You should return true if the badguy was squished, false if squishing wasn't possible
Reimplemented from BadGuy.
Definition at line 204 of file snail.cpp.
References be_flat(), be_kicked(), Player::bounce(), BadGuy::dir, Player::does_buttjump, MovingObject::get_pos(), Player::is_invincible(), BadGuy::kill_fall(), LEFT, MAX_SNAIL_SQUISHES, BadGuy::on_ground(), SoundManager::play(), RIGHT, sound_manager, squishcount, state, STATE_FLAT, STATE_KICKED, STATE_KICKED_DELAY, STATE_NORMAL, and Vector::x.
00205 { 00206 Player* player = dynamic_cast<Player*>(&object); 00207 if(player && (player->does_buttjump || player->is_invincible())) { 00208 kill_fall(); 00209 player->bounce(*this); 00210 return true; 00211 } 00212 00213 switch(state) { 00214 00215 case STATE_KICKED: 00216 case STATE_NORMAL: 00217 00218 // Can't stomp in midair 00219 if(!on_ground()) 00220 break; 00221 00222 squishcount++; 00223 if (squishcount >= MAX_SNAIL_SQUISHES) { 00224 kill_fall(); 00225 return true; 00226 } 00227 sound_manager->play("sounds/stomp.wav", get_pos()); 00228 be_flat(); 00229 break; 00230 00231 case STATE_FLAT: 00232 sound_manager->play("sounds/kick.wav", get_pos()); 00233 { 00234 MovingObject* movingobject = dynamic_cast<MovingObject*>(&object); 00235 if (movingobject && (movingobject->get_pos().x < get_pos().x)) { 00236 dir = RIGHT; 00237 } else { 00238 dir = LEFT; 00239 } 00240 } 00241 be_kicked(); 00242 break; 00243 00244 case STATE_KICKED_DELAY: 00245 break; 00246 00247 } 00248 00249 if (player) player->bounce(*this); 00250 return true; 00251 }
void Snail::be_normal | ( | ) | [protected] |
switch to state STATE_NORMAL
Definition at line 66 of file snail.cpp.
References WalkingBadguy::initialize(), state, and STATE_NORMAL.
Referenced by active_update(), and initialize().
00067 { 00068 if (state == STATE_NORMAL) return; 00069 00070 state = STATE_NORMAL; 00071 WalkingBadguy::initialize(); 00072 }
void Snail::be_flat | ( | ) | [protected] |
switch to state STATE_FLAT
Definition at line 75 of file snail.cpp.
References BadGuy::dir, LEFT, BadGuy::physic, Physic::set_velocity_x(), Physic::set_velocity_y(), MovingSprite::sprite, state, and STATE_FLAT.
Referenced by collision_squished().
00076 { 00077 state = STATE_FLAT; 00078 sprite->set_action(dir == LEFT ? "flat-left" : "flat-right", 1); 00079 00080 physic.set_velocity_x(0); 00081 physic.set_velocity_y(0); 00082 }
void Snail::be_kicked | ( | ) | [protected] |
switch to state STATE_KICKED_DELAY
Definition at line 85 of file snail.cpp.
References BadGuy::dir, kicked_delay_timer, LEFT, BadGuy::physic, Physic::set_velocity_x(), Physic::set_velocity_y(), SNAIL_KICK_SPEED, MovingSprite::sprite, Timer::start(), state, and STATE_KICKED_DELAY.
Referenced by collision_player(), and collision_squished().
00086 { 00087 state = STATE_KICKED_DELAY; 00088 sprite->set_action(dir == LEFT ? "flat-left" : "flat-right", 1); 00089 00090 physic.set_velocity_x(dir == LEFT ? -SNAIL_KICK_SPEED : SNAIL_KICK_SPEED); 00091 physic.set_velocity_y(0); 00092 00093 // start a timer to delay addition of upward movement until we are (hopefully) out from under the player 00094 kicked_delay_timer.start(0.05f); 00095 }
State Snail::state [private] |
Reimplemented from BadGuy.
Definition at line 54 of file snail.hpp.
Referenced by active_update(), be_flat(), be_kicked(), be_normal(), can_break(), collision_badguy(), collision_player(), collision_solid(), and collision_squished().
Timer Snail::kicked_delay_timer [private] |
wait time until switching from STATE_KICKED_DELAY to STATE_KICKED
Definition at line 55 of file snail.hpp.
Referenced by active_update(), and be_kicked().
int Snail::squishcount [private] |