Consolidated code for walkingflame and swalking flame, added new dormant state
authorLMH <lmh.0013@gmail.com>
Sat, 6 Jul 2013 01:42:52 +0000 (15:42 -1000)
committerLMH <lmh.0013@gmail.com>
Sat, 6 Jul 2013 01:42:52 +0000 (15:42 -1000)
data/levels/test/glow_effects.stl
src/badguy/walkingflame.cpp
src/badguy/walkingflame.hpp
src/supertux/object_factory.cpp

index e700056..2fe85e3 100755 (executable)
@@ -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      )                                                                                                                                                                                                                                                                                               
index 7652f8e..dcf9ee8 100644 (file)
@@ -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 */
index 7b782ed..69e2e54 100644 (file)
@@ -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
index f309bdf..ce556ae 100644 (file)
@@ -186,6 +186,7 @@ ObjectFactory::init_factories()
   add_factory<Dart>("dart");
   add_factory<DartTrap>("darttrap");
   add_factory<Dispenser>("dispenser");
+  add_factory<DWalkingFlame>("dwalkingflame");//
   add_factory<Fish>("fish");
   add_factory<Flame>("flame");
   add_factory<FlyingSnowBall>("flyingsnowball");
@@ -217,7 +218,7 @@ ObjectFactory::init_factories()
   add_factory<Spiky>("spiky");
   add_factory<Stalactite>("stalactite");
   add_factory<Stumpy>("stumpy");
-  add_factory<SWalkingFlame>("swalkingflame");
+  add_factory<SWalkingFlame>("swalkingflame");//
   add_factory<Toad>("toad");
   add_factory<Totem>("totem");
   add_factory<WalkingFlame>("walkingflame");