From: LMH Date: Sat, 6 Jul 2013 01:42:52 +0000 (-1000) Subject: Consolidated code for walkingflame and swalking flame, added new dormant state X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=49ab5a3963f49aeac46e11f7254b39e1de097a9b;p=supertux.git Consolidated code for walkingflame and swalking flame, added new dormant state --- diff --git a/data/levels/test/glow_effects.stl b/data/levels/test/glow_effects.stl index e70005642..2fe85e3d5 100755 --- a/data/levels/test/glow_effects.stl +++ b/data/levels/test/glow_effects.stl @@ -24,6 +24,7 @@ (ghostflame (x 656 )(y 96 )) (walkingflame (x 224 )(y 192 )) (swalkingflame (x 64 )(y 192 )(direction "right")) + (dwalkingflame (x 128)(y 192)) (tilemap (name "Interactive" ) (z-pos 0 )(solid #t ) diff --git a/src/badguy/walkingflame.cpp b/src/badguy/walkingflame.cpp index 7652f8ed3..dcf9ee8a0 100644 --- a/src/badguy/walkingflame.cpp +++ b/src/badguy/walkingflame.cpp @@ -28,7 +28,8 @@ static const float MAXDROPHEIGHT = 20; 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; @@ -37,79 +38,7 @@ WalkingFlame::WalkingFlame(const Reader& reader) : } 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); @@ -119,7 +48,7 @@ SWalkingFlame::collision_solid(const CollisionHit& 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); @@ -128,7 +57,7 @@ SWalkingFlame::collision_badguy(BadGuy& badguy, const CollisionHit& hit) } void -SWalkingFlame::active_update(float elapsed_time) { +WalkingFlame::active_update(float elapsed_time) { if(state == STATE_WALKING) { WalkingBadguy::active_update(elapsed_time); @@ -169,7 +98,7 @@ SWalkingFlame::active_update(float elapsed_time) { } void -SWalkingFlame::draw(DrawingContext& context) +WalkingFlame::draw(DrawingContext& context) { //Draw the Sprite. sprite->draw(context, get_pos(), LAYER_OBJECTS); @@ -181,26 +110,26 @@ SWalkingFlame::draw(DrawingContext& context) } 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()); @@ -220,4 +149,34 @@ SWalkingFlame::kill_fall() 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 */ diff --git a/src/badguy/walkingflame.hpp b/src/badguy/walkingflame.hpp index 7b782ede6..69e2e541d 100644 --- a/src/badguy/walkingflame.hpp +++ b/src/badguy/walkingflame.hpp @@ -24,6 +24,9 @@ class WalkingFlame : public WalkingBadguy 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(); @@ -34,35 +37,31 @@ public: 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 diff --git a/src/supertux/object_factory.cpp b/src/supertux/object_factory.cpp index f309bdfa8..ce556aee6 100644 --- a/src/supertux/object_factory.cpp +++ b/src/supertux/object_factory.cpp @@ -186,6 +186,7 @@ ObjectFactory::init_factories() add_factory("dart"); add_factory("darttrap"); add_factory("dispenser"); + add_factory("dwalkingflame");// add_factory("fish"); add_factory("flame"); add_factory("flyingsnowball"); @@ -217,7 +218,7 @@ ObjectFactory::init_factories() add_factory("spiky"); add_factory("stalactite"); add_factory("stumpy"); - add_factory("swalkingflame"); + add_factory("swalkingflame");// add_factory("toad"); add_factory("totem"); add_factory("walkingflame");