#include <flyingsnowball.hpp>
Inherits BadGuy.
Public Member Functions | |
FlyingSnowBall (const Reader &reader) | |
FlyingSnowBall (const Vector &pos) | |
void | initialize () |
called immediately before the first call to initialize | |
void | activate () |
called when the badguy has been activated. | |
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. | |
Protected Member Functions | |
bool | collision_squished (GameObject &object) |
Called when the player hit the badguy from above. | |
Private Attributes | |
float | normal_propeller_speed |
Timer | puff_timer |
time until the next smoke puff is spawned |
Definition at line 22 of file flyingsnowball.hpp.
FlyingSnowBall::FlyingSnowBall | ( | const Reader & | reader | ) |
Definition at line 30 of file flyingsnowball.cpp.
References Physic::enable_gravity(), and BadGuy::physic.
00030 : 00031 BadGuy(reader, "images/creatures/flying_snowball/flying_snowball.sprite"), 00032 normal_propeller_speed(), 00033 puff_timer() 00034 { 00035 physic.enable_gravity(true); 00036 }
FlyingSnowBall::FlyingSnowBall | ( | const Vector & | pos | ) |
Definition at line 38 of file flyingsnowball.cpp.
References Physic::enable_gravity(), and BadGuy::physic.
00038 : 00039 BadGuy(pos, "images/creatures/flying_snowball/flying_snowball.sprite"), 00040 normal_propeller_speed(), 00041 puff_timer() 00042 { 00043 physic.enable_gravity(true); 00044 }
void FlyingSnowBall::initialize | ( | ) | [virtual] |
called immediately before the first call to initialize
Reimplemented from BadGuy.
Definition at line 47 of file flyingsnowball.cpp.
References BadGuy::dir, LEFT, and MovingSprite::sprite.
void FlyingSnowBall::activate | ( | ) | [virtual] |
called when the badguy has been activated.
(As a side effect the dir variable might have been changed so that it faces towards the player.
Reimplemented from BadGuy.
Definition at line 53 of file flyingsnowball.cpp.
References gameRandom, normal_propeller_speed, PUFF_INTERVAL_MAX, PUFF_INTERVAL_MIN, puff_timer, RandomGenerator::randf(), and Timer::start().
00054 { 00055 puff_timer.start(gameRandom.randf(PUFF_INTERVAL_MIN, PUFF_INTERVAL_MAX)); 00056 normal_propeller_speed = gameRandom.randf(0.95, 1.05); 00057 }
void FlyingSnowBall::active_update | ( | float | elapsed_time | ) | [virtual] |
called each frame when the badguy is activated.
Reimplemented from BadGuy.
Definition at line 78 of file flyingsnowball.cpp.
References Sector::add_object(), ANCHOR_MIDDLE, MovingObject::bbox, Timer::check(), Sector::current(), BadGuy::dir, gameRandom, Sector::get_gravity(), Rectf::get_middle(), Physic::get_movement(), BadGuy::get_nearest_player(), MovingObject::get_pos(), Physic::get_velocity_y(), LAYER_OBJECTS, LEFT, MovingObject::movement, normal_propeller_speed, BadGuy::physic, PUFF_INTERVAL_MAX, PUFF_INTERVAL_MIN, puff_timer, RandomGenerator::randf(), RIGHT, Physic::set_acceleration_y(), Physic::set_velocity_y(), MovingSprite::sprite, Timer::start(), BadGuy::start_position, Vector::x, and Vector::y.
00079 { 00080 00081 const float grav = Sector::current()->get_gravity() * 100.0f; 00082 if (get_pos().y > start_position.y + 2*32) { 00083 00084 // Flying too low - increased propeller speed 00085 physic.set_acceleration_y(-grav*1.2); 00086 00087 physic.set_velocity_y(physic.get_velocity_y() * 0.99); 00088 00089 } else if (get_pos().y < start_position.y - 2*32) { 00090 00091 // Flying too high - decreased propeller speed 00092 physic.set_acceleration_y(-grav*0.8); 00093 00094 physic.set_velocity_y(physic.get_velocity_y() * 0.99f); 00095 00096 } else { 00097 00098 // Flying at acceptable altitude - normal propeller speed 00099 physic.set_acceleration_y(-grav*normal_propeller_speed); 00100 00101 } 00102 00103 movement=physic.get_movement(elapsed_time); 00104 00105 Player* player = this->get_nearest_player(); 00106 if (player) { 00107 dir = (player->get_pos().x > get_pos().x) ? RIGHT : LEFT; 00108 sprite->set_action(dir == LEFT ? "left" : "right"); 00109 } 00110 00111 // spawn smoke puffs 00112 if (puff_timer.check()) { 00113 Vector ppos = bbox.get_middle(); 00114 Vector pspeed = Vector(gameRandom.randf(-10, 10), 150); 00115 Vector paccel = Vector(0,0); 00116 Sector::current()->add_object(new SpriteParticle("images/objects/particles/smoke.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1)); 00117 puff_timer.start(gameRandom.randf(PUFF_INTERVAL_MIN, PUFF_INTERVAL_MAX)); 00118 00119 normal_propeller_speed = gameRandom.randf(0.95, 1.05); 00120 physic.set_velocity_y(physic.get_velocity_y() - 50); 00121 } 00122 }
void FlyingSnowBall::collision_solid | ( | const CollisionHit & | hit | ) | [virtual] |
Called when the badguy collided with solid ground.
Reimplemented from BadGuy.
Definition at line 70 of file flyingsnowball.cpp.
References CollisionHit::bottom, BadGuy::physic, Physic::set_velocity_y(), and CollisionHit::top.
00071 { 00072 if(hit.top || hit.bottom) { 00073 physic.set_velocity_y(0); 00074 } 00075 }
bool FlyingSnowBall::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 60 of file flyingsnowball.cpp.
References BadGuy::dir, BadGuy::kill_squished(), LEFT, BadGuy::physic, Physic::set_acceleration_y(), Physic::set_velocity_y(), and MovingSprite::sprite.
00061 { 00062 sprite->set_action(dir == LEFT ? "squished-left" : "squished-right"); 00063 physic.set_acceleration_y(0); 00064 physic.set_velocity_y(0); 00065 kill_squished(object); 00066 return true; 00067 }
float FlyingSnowBall::normal_propeller_speed [private] |
Timer FlyingSnowBall::puff_timer [private] |
time until the next smoke puff is spawned
Definition at line 37 of file flyingsnowball.hpp.
Referenced by activate(), and active_update().