rnd-20030901-B-src
[rocksndiamonds.git] / src / libgame / toons.c
index 94c72152c2890d0461b849675d8fd18672033265..048696f6cd365fb4322959f5d7da4fcced91bfed 100644 (file)
@@ -64,10 +64,10 @@ int getAnimationFrame(int num_frames, int delay, int mode, int start_frame,
   {
     /* note: expect different frames for the same delay cycle! */
 
-    if (anim.random_frame < 0)
+    if (gfx.anim_random_frame < 0)
       frame = SimpleRND(num_frames);
     else
-      frame = anim.random_frame % num_frames;
+      frame = gfx.anim_random_frame % num_frames;
   }
 
   if (mode & ANIM_REVERSE)             /* use reverse animation direction */
@@ -81,16 +81,18 @@ int getAnimationFrame(int num_frames, int delay, int mode, int start_frame,
 /* toon animation functions                                                  */
 /* ========================================================================= */
 
-static int get_toon_direction(char *direction_raw)
+static int get_toon_direction(char *direction_string_raw)
 {
-  static char *direction = NULL;
+  char *direction_string = getStringToLower(direction_string_raw);
+  int direction = (strcmp(direction_string, "left")  == 0 ? MV_LEFT :
+                  strcmp(direction_string, "right") == 0 ? MV_RIGHT :
+                  strcmp(direction_string, "up")    == 0 ? MV_UP :
+                  strcmp(direction_string, "down")  == 0 ? MV_DOWN :
+                  MV_NO_MOVING);
 
-  setString(&direction, getStringToLower(direction_raw));
+  free(direction_string);
 
-  return (strcmp(direction, "left")  == 0 ? MV_LEFT :
-         strcmp(direction, "right") == 0 ? MV_RIGHT :
-         strcmp(direction, "up")    == 0 ? MV_UP :
-         strcmp(direction, "down")  == 0 ? MV_DOWN : MV_NO_MOVING);
+  return direction;
 }
 
 void InitToonScreen(Bitmap *save_buffer,
@@ -309,6 +311,7 @@ void HandleAnimation(int mode)
 {
   static unsigned long animstart_delay = -1;
   static unsigned long animstart_delay_value = 0;
+  static boolean anim_running = FALSE;
   static boolean anim_restart = TRUE;
   static boolean reset_delay = TRUE;
   static int toon_nr = 0;
@@ -325,12 +328,17 @@ void HandleAnimation(int mode)
   {
     case ANIM_START:
       screen_info.prepare_backbuffer_function();
+
+      anim_running = TRUE;
       anim_restart = TRUE;
       reset_delay = TRUE;
 
       return;
 
     case ANIM_CONTINUE:
+      if (!anim_running)
+       return;
+
       break;
 
     case ANIM_STOP:
@@ -342,6 +350,8 @@ void HandleAnimation(int mode)
       screen_info.update_function();
       setup.direct_draw = draw_mode;
 
+      anim_running = FALSE;
+
       return;
 
     default: