Added next action to sprite.
authorRicardo Cruz <rick2@aeiou.pt>
Tue, 17 Aug 2004 23:01:58 +0000 (23:01 +0000)
committerRicardo Cruz <rick2@aeiou.pt>
Tue, 17 Aug 2004 23:01:58 +0000 (23:01 +0000)
SVN-Revision: 1799

lib/special/sprite.cpp
lib/special/sprite.h

index cc94821..be2b81f 100644 (file)
@@ -103,10 +103,12 @@ action = i->second;
 }
 
 void
-Sprite::start_animation(int loops)
+Sprite::start_animation(int loops, std::string next_act)
 {
-animation_loops = loops;
 reset();
+animation_loops = loops;
+if(!next_act.empty())
+  next_action = next_act;
 }
 
 void
@@ -115,6 +117,7 @@ Sprite::reset()
 frame = 0;
 last_tick = SDL_GetTicks();
 animation_reversed = true;
+next_action.clear();
 }
 
 bool
@@ -156,7 +159,14 @@ if(animation_reversed)
     {  // last case can happen when not used reverse_animation()
     frame = get_frames() - 1;
     if(animation_loops > 0)
+      {
       animation_loops--;
+      if(animation_loops == 0)
+        {
+        set_action(next_action);
+        start_animation(-1);
+        }
+      }
 
     if(fabsf(excedent) < get_frames())
       frame += excedent;
@@ -169,7 +179,14 @@ else
     {
     frame = 0;
     if(animation_loops > 0)
+      {
       animation_loops--;
+      if(animation_loops == 0)
+        {
+        set_action(next_action);
+        start_animation(-1);
+        }
+      }
 
     if(excedent < get_frames())
       frame += excedent;
index fdf83a5..54f3476 100644 (file)
@@ -64,8 +64,9 @@ namespace SuperTux
       /* Start an animation
           -1 - for infinite
           0  - stopped
-          1,2,3  - one, two, three times... */
-      void start_animation(int loops);
+          1,2,3  - one, two, three times...
+          If next_act specified, that action will be used when animation ends. */
+      void start_animation(int loops, std::string next_act = "");
       /** Check if animation is stopped or not */
       bool check_animation();
       /** Reverse the animation */
@@ -116,6 +117,7 @@ namespace SuperTux
       Actions actions;
 
       Action* action;
+      std::string next_action;
     };
 
 } //namespace SuperTux