#include <stumpy.hpp>
Inherits WalkingBadguy.
Public Member Functions | |
Stumpy (const Reader &reader) | |
Stumpy (const Vector &pos, Direction d) | |
void | initialize () |
called immediately before the first call to initialize | |
void | active_update (float elapsed_time) |
called each frame when the badguy is activated. | |
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. | |
Protected Types | |
enum | MyState { STATE_INVINCIBLE, STATE_NORMAL } |
Protected Member Functions | |
bool | collision_squished (GameObject &object) |
Called when the player hit the badguy from above. | |
Private Attributes | |
MyState | mystate |
Timer | invincible_timer |
Definition at line 22 of file stumpy.hpp.
enum Stumpy::MyState [protected] |
Stumpy::Stumpy | ( | const Reader & | reader | ) |
Definition at line 31 of file stumpy.cpp.
References WalkingBadguy::max_drop_height, SoundManager::preload(), sound_manager, STUMPY_SPEED, and WalkingBadguy::walk_speed.
00031 : 00032 WalkingBadguy(reader, "images/creatures/mr_tree/stumpy.sprite","left","right"), 00033 mystate(STATE_NORMAL), 00034 invincible_timer() 00035 { 00036 walk_speed = STUMPY_SPEED; 00037 max_drop_height = 16; 00038 sound_manager->preload("sounds/mr_treehit.ogg"); 00039 }
Definition at line 41 of file stumpy.cpp.
References INVINCIBLE_TIME, invincible_timer, WalkingBadguy::max_drop_height, SoundManager::preload(), sound_manager, Timer::start(), STUMPY_SPEED, and WalkingBadguy::walk_speed.
00041 : 00042 WalkingBadguy(pos, d, "images/creatures/mr_tree/stumpy.sprite","left","right"), 00043 mystate(STATE_INVINCIBLE), 00044 invincible_timer() 00045 { 00046 walk_speed = STUMPY_SPEED; 00047 max_drop_height = 16; 00048 sound_manager->preload("sounds/mr_treehit.ogg"); 00049 invincible_timer.start(INVINCIBLE_TIME); 00050 }
void Stumpy::initialize | ( | ) | [virtual] |
called immediately before the first call to initialize
Reimplemented from WalkingBadguy.
Definition at line 53 of file stumpy.cpp.
References MovingObject::bbox, BadGuy::dir, WalkingBadguy::initialize(), LEFT, mystate, BadGuy::physic, Rectf::set_size(), Physic::set_velocity_x(), MovingSprite::sprite, STATE_INVINCIBLE, and STATE_NORMAL.
00054 { 00055 switch (mystate) { 00056 case STATE_INVINCIBLE: 00057 sprite->set_action(dir == LEFT ? "dizzy-left" : "dizzy-right"); 00058 bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); 00059 physic.set_velocity_x(0); 00060 break; 00061 case STATE_NORMAL: 00062 WalkingBadguy::initialize(); 00063 break; 00064 } 00065 }
void Stumpy::active_update | ( | float | elapsed_time | ) | [virtual] |
called each frame when the badguy is activated.
Reimplemented from WalkingBadguy.
Definition at line 68 of file stumpy.cpp.
References WalkingBadguy::active_update(), BadGuy::active_update(), Timer::check(), WalkingBadguy::initialize(), invincible_timer, mystate, STATE_INVINCIBLE, and STATE_NORMAL.
00069 { 00070 switch (mystate) { 00071 case STATE_INVINCIBLE: 00072 if (invincible_timer.check()) { 00073 mystate = STATE_NORMAL; 00074 WalkingBadguy::initialize(); 00075 } 00076 BadGuy::active_update(elapsed_time); 00077 break; 00078 case STATE_NORMAL: 00079 WalkingBadguy::active_update(elapsed_time); 00080 break; 00081 } 00082 }
void Stumpy::collision_solid | ( | const CollisionHit & | hit | ) | [virtual] |
Called when the badguy collided with solid ground.
Reimplemented from WalkingBadguy.
Definition at line 123 of file stumpy.cpp.
References CollisionHit::bottom, WalkingBadguy::collision_solid(), CollisionHit::left, mystate, BadGuy::physic, CollisionHit::right, Physic::set_velocity_x(), Physic::set_velocity_y(), STATE_INVINCIBLE, STATE_NORMAL, CollisionHit::top, and BadGuy::update_on_ground_flag().
00124 { 00125 update_on_ground_flag(hit); 00126 00127 switch (mystate) { 00128 case STATE_INVINCIBLE: 00129 if(hit.top || hit.bottom) { 00130 physic.set_velocity_y(0); 00131 } 00132 if(hit.left || hit.right) { 00133 physic.set_velocity_x(0); 00134 } 00135 break; 00136 case STATE_NORMAL: 00137 WalkingBadguy::collision_solid(hit); 00138 break; 00139 } 00140 }
HitResponse Stumpy::collision_badguy | ( | BadGuy & | badguy, | |
const CollisionHit & | hit | |||
) | [virtual] |
Called when the badguy collided with another badguy.
Reimplemented from WalkingBadguy.
Definition at line 143 of file stumpy.cpp.
References CollisionHit::bottom, WalkingBadguy::collision_badguy(), CONTINUE, CollisionHit::left, mystate, BadGuy::physic, CollisionHit::right, Physic::set_velocity_x(), Physic::set_velocity_y(), STATE_INVINCIBLE, STATE_NORMAL, and CollisionHit::top.
00144 { 00145 switch (mystate) { 00146 case STATE_INVINCIBLE: 00147 if(hit.top || hit.bottom) { 00148 physic.set_velocity_y(0); 00149 } 00150 if(hit.left || hit.right) { 00151 physic.set_velocity_x(0); 00152 } 00153 return CONTINUE; 00154 break; 00155 case STATE_NORMAL: 00156 return WalkingBadguy::collision_badguy(badguy, hit); 00157 break; 00158 } 00159 return CONTINUE; 00160 }
bool Stumpy::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 85 of file stumpy.cpp.
References Sector::add_object(), ANCHOR_MIDDLE, MovingObject::bbox, Player::bounce(), Sector::current(), BadGuy::dir, Rectf::get_middle(), MovingObject::get_pos(), graphicsRandom, BadGuy::kill_squished(), LAYER_OBJECTS, LEFT, mystate, SoundManager::play(), RandomGenerator::randf(), MovingObject::set_size(), sound_manager, MovingSprite::sprite, STATE_INVINCIBLE, and STATE_NORMAL.
00086 { 00087 00088 // if we're still invincible, we ignore the hit 00089 if (mystate == STATE_INVINCIBLE) { 00090 sound_manager->play("sounds/mr_treehit.ogg", get_pos()); 00091 Player* player = dynamic_cast<Player*>(&object); 00092 if (player) player->bounce(*this); 00093 return true; 00094 } 00095 00096 // if we can die, we do 00097 if (mystate == STATE_NORMAL) { 00098 sprite->set_action(dir == LEFT ? "squished-left" : "squished-right"); 00099 set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); 00100 kill_squished(object); 00101 // spawn some particles 00102 // TODO: provide convenience function in MovingSprite or MovingObject? 00103 for (int i = 0; i < 25; i++) { 00104 Vector ppos = bbox.get_middle(); 00105 float angle = graphicsRandom.randf(-M_PI_2, M_PI_2); 00106 float velocity = graphicsRandom.randf(45, 90); 00107 float vx = sin(angle)*velocity; 00108 float vy = -cos(angle)*velocity; 00109 Vector pspeed = Vector(vx, vy); 00110 Vector paccel = Vector(0, 100); 00111 Sector::current()->add_object(new SpriteParticle("images/objects/particles/bark.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1)); 00112 } 00113 00114 return true; 00115 00116 } 00117 00118 //TODO: exception? 00119 return true; 00120 }
MyState Stumpy::mystate [private] |
Definition at line 42 of file stumpy.hpp.
Referenced by active_update(), collision_badguy(), collision_solid(), collision_squished(), and initialize().
Timer Stumpy::invincible_timer [private] |