WalkingFlame::WalkingFlame(const Reader& reader) :
WalkingBadguy(reader, "images/creatures/walkingflame/walkingflame.sprite", "left", "right"),
- lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-medium.sprite"))
+ lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-medium.sprite")),
+ state(STATE_WALKING)
{
walk_speed = WALKSPEED;
max_drop_height = MAXDROPHEIGHT;
}
void
-WalkingFlame::draw(DrawingContext& context)
-{
- //Draw the Sprite.
- sprite->draw(context, get_pos(), LAYER_OBJECTS);
- //Draw the light
- context.push_target();
- context.set_target(DrawingContext::LIGHTMAP);
- lightsprite->draw(context, get_bbox().get_middle(), 0);
- context.pop_target();
-}
-
-void
-WalkingFlame::freeze()
-{
- // attempting to freeze a flame causes it to go out
- kill_fall();
-}
-
-bool
-WalkingFlame::is_freezable() const
-{
- return true;
-}
-
-bool
-WalkingFlame::is_flammable() const
-{
- return false;
-}
-
-void
-WalkingFlame::kill_fall()
-{
- //TODO: get unique sound for ice-fire encounters
- sound_manager->play("sounds/fall.wav", get_pos());
- // throw a puff of smoke
- Vector ppos = bbox.get_middle();
- Vector pspeed = Vector(0, -150);
- Vector paccel = Vector(0,0);
- Sector::current()->add_object(new SpriteParticle("images/objects/particles/smoke.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_BACKGROUNDTILES+2));
- // extinguish the flame
- sprite->set_action(dir == LEFT ? "extinguish-left" : "extinguish-right");
- physic.set_velocity_y(0);
- physic.set_acceleration_y(0);
- physic.enable_gravity(false);
- set_state(STATE_SQUISHED); // used to nullify any threat and remove
-
- // start dead-script
- run_dead_script();
-}
-
-/* The following handles a sleeping version */
-
-SWalkingFlame::SWalkingFlame(const Reader& reader) :
- WalkingBadguy(reader, "images/creatures/walkingflame/walkingflame.sprite", "left", "right"), state(STATE_SLEEPING),
- lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-medium.sprite"))
-{
- walk_speed = WALKSPEED;
- max_drop_height = MAXDROPHEIGHT;
- lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
- lightsprite->set_color(Color(1.0f, 0.9f, 0.8f));
-}
-
-void
-SWalkingFlame::initialize()
-{
- state = STATE_SLEEPING;
- physic.set_velocity_x(0);
- sprite->set_action(dir == LEFT ? "sleeping-left" : "sleeping-right");
-}
-
-void
-SWalkingFlame::collision_solid(const CollisionHit& hit)
+WalkingFlame::collision_solid(const CollisionHit& hit)
{
if(state != STATE_WALKING) {
BadGuy::collision_solid(hit);
}
HitResponse
-SWalkingFlame::collision_badguy(BadGuy& badguy, const CollisionHit& hit)
+WalkingFlame::collision_badguy(BadGuy& badguy, const CollisionHit& hit)
{
if(state != STATE_WALKING) {
return BadGuy::collision_badguy(badguy, hit);
}
void
-SWalkingFlame::active_update(float elapsed_time) {
+WalkingFlame::active_update(float elapsed_time) {
if(state == STATE_WALKING) {
WalkingBadguy::active_update(elapsed_time);
}
void
-SWalkingFlame::draw(DrawingContext& context)
+WalkingFlame::draw(DrawingContext& context)
{
//Draw the Sprite.
sprite->draw(context, get_pos(), LAYER_OBJECTS);
}
void
-SWalkingFlame::freeze()
+WalkingFlame::freeze()
{
// attempting to freeze a flame causes it to go out
kill_fall();
}
bool
-SWalkingFlame::is_freezable() const
+WalkingFlame::is_freezable() const
{
return true;
}
bool
-SWalkingFlame::is_flammable() const
+WalkingFlame::is_flammable() const
{
return false;
}
void
-SWalkingFlame::kill_fall()
+WalkingFlame::kill_fall()
{
//TODO: get unique sound for ice-fire encounters
sound_manager->play("sounds/fall.wav", get_pos());
run_dead_script();
}
+/* The following defines a sleeping version */
+
+SWalkingFlame::SWalkingFlame(const Reader& reader) :
+ WalkingFlame(reader)
+{
+ state = STATE_SLEEPING;
+}
+
+void
+SWalkingFlame::initialize()
+{
+ physic.set_velocity_x(0);
+ sprite->set_action(dir == LEFT ? "sleeping-left" : "sleeping-right");
+}
+
+/* The following defines a dormant version that never wakes */
+DWalkingFlame::DWalkingFlame(const Reader& reader) :
+ WalkingFlame(reader)
+{
+ walk_speed = 0;
+ state = STATE_DORMANT;
+}
+
+void
+DWalkingFlame::initialize()
+{
+ physic.set_velocity_x(0);
+ sprite->set_action(dir == LEFT ? "sleeping-left" : "sleeping-right");
+}
+
/* EOF */
public:
WalkingFlame(const Reader& reader);
+ void collision_solid(const CollisionHit& hit);
+ HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
+ void active_update(float elapsed_time);
void draw(DrawingContext& context);
void freeze();
private:
SpritePtr lightsprite;
+
+protected:
+ enum SState {
+ STATE_SLEEPING,
+ STATE_WAKING,
+ STATE_WALKING,
+ STATE_DORMANT
+ };
+ SState state;
};
-class SWalkingFlame : public WalkingBadguy
+class SWalkingFlame : public WalkingFlame
{
public:
SWalkingFlame(const Reader& reader);
void initialize();
- void collision_solid(const CollisionHit& hit);
- HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
- void active_update(float elapsed_time);
- void draw(DrawingContext& context);
-
- void freeze();
- bool is_freezable() const;
- bool is_flammable() const;
+};
- virtual void kill_fall();
+class DWalkingFlame : public WalkingFlame
+{
+public:
+ DWalkingFlame(const Reader& reader);
-protected:
- enum SState {
- STATE_SLEEPING,
- STATE_WAKING,
- STATE_WALKING
- };
- SState state;
-
-private:
- SpritePtr lightsprite;
+ void initialize();
};
#endif