rnd-20030306-3-src
[rocksndiamonds.git] / src / game.c
index 13110880ec46d7dad1189c95e64e9a2e298fdea4..9dca25854cf41ca1b13b79267f3d8323b54acaf4 100644 (file)
@@ -643,9 +643,10 @@ void InitGame()
     player->Pushing = FALSE;
     player->Switching = FALSE;
     player->GfxPos = 0;
-    player->Frame = 0;
-
+    player->GfxDir = MV_NO_MOVING;
     player->GfxAction = ACTION_DEFAULT;
+    player->Frame = 0;
+    player->StepFrame = 0;
 
     player->use_murphy_graphic = FALSE;
     player->use_disk_red_graphic = FALSE;
@@ -736,6 +737,7 @@ void InitGame()
       GfxFrame[x][y] = 0;
       GfxAction[x][y] = ACTION_DEFAULT;
       GfxRandom[x][y] = INIT_GFX_RANDOM();
+      GfxElement[x][y] = EL_UNDEFINED;
     }
   }
 
@@ -1260,12 +1262,19 @@ int NewHiScore()
   return position;
 }
 
-static void InitPlayerGfxAnimation(struct PlayerInfo *player, int action)
+void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
 {
-  if (player->GfxAction != action)
+  if (player->GfxAction != action || player->GfxDir != dir)
   {
+#if 0
+    printf("Player frame reset! (%d => %d, %d => %d)\n",
+          player->GfxAction, action, player->GfxDir, dir);
+#endif
+
     player->GfxAction = action;
+    player->GfxDir = dir;
     player->Frame = 0;
+    player->StepFrame = 0;
   }
 }
 
@@ -4463,7 +4472,14 @@ static void PlayerActions(struct PlayerInfo *player, byte player_action)
     SnapField(player, 0, 0);
     CheckGravityMovement(player);
 
-    InitPlayerGfxAnimation(player, ACTION_DEFAULT);
+    if (player->MovPos == 0)
+    {
+#if 0
+      printf("Trying... Player frame reset\n");
+#endif
+
+      InitPlayerGfxAnimation(player, ACTION_DEFAULT, player->MovDir);
+    }
 
     if (player->MovPos == 0)   /* needed for tape.playing */
       player->is_moving = FALSE;
@@ -4564,11 +4580,13 @@ void GameActions()
 
   ScrollScreen(NULL, SCROLL_GO_ON);
 
+#if 0
   FrameCounter++;
   TimeFrames++;
 
   for (i=0; i<MAX_PLAYERS; i++)
     stored_player[i].Frame++;
+#endif
 
   for (y=0; y<lev_fieldy; y++) for (x=0; x<lev_fieldx; x++)
   {
@@ -4609,6 +4627,10 @@ void GameActions()
 
     SetRandomAnimationValue(x, y);
 
+#if 1
+    PlaySoundLevelActionIfLoop(x, y, GfxAction[x][y]);
+#endif
+
     if (IS_INACTIVE(element))
     {
       if (IS_ANIMATED(graphic))
@@ -4889,6 +4911,33 @@ void GameActions()
 
     redraw_mask |= REDRAW_FPS;
   }
+
+#if 0
+  if (stored_player[0].jx != stored_player[0].last_jx ||
+      stored_player[0].jy != stored_player[0].last_jy)
+    printf("::: %d, %d, %d, %d, %d\n",
+          stored_player[0].MovDir,
+          stored_player[0].MovPos,
+          stored_player[0].GfxPos,
+          stored_player[0].Frame,
+          stored_player[0].StepFrame);
+#endif
+
+#if 1
+  FrameCounter++;
+  TimeFrames++;
+
+  for (i=0; i<MAX_PLAYERS; i++)
+  {
+    int move_frames =
+      MOVE_DELAY_NORMAL_SPEED /  stored_player[i].move_delay_value;
+
+    stored_player[i].Frame += move_frames;
+
+    if (stored_player[i].MovPos != 0)
+      stored_player[i].StepFrame += move_frames;
+  }
+#endif
 }
 
 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
@@ -5193,6 +5242,8 @@ boolean MoveFigure(struct PlayerInfo *player, int dx, int dy)
 #endif
 #endif
 
+  player->StepFrame = 0;
+
   if (moved & MF_MOVING)
   {
     if (old_jx != jx && old_jy == jy)
@@ -5612,7 +5663,8 @@ int DigField(struct PlayerInfo *player,
                        dy == +1 ? MV_DOWN : MV_NO_MOVING);
   int element;
 
-  player->is_digging = FALSE;
+  if (player->MovPos == 0)
+    player->is_digging = FALSE;
 
   if (player->MovPos == 0)
     player->Pushing = FALSE;
@@ -5669,6 +5721,10 @@ int DigField(struct PlayerInfo *player,
     case EL_SP_BASE:
     case EL_SP_BUGGY_BASE:
     case EL_SP_BUGGY_BASE_ACTIVATING:
+#if 1
+      if (mode != DF_SNAP && element == EL_SAND)
+       GfxElement[x][y] = Feld[x][y];
+#endif
       RemoveField(x, y);
       PlaySoundLevelElementAction(x, y, element, ACTION_DIGGING);
       break;
@@ -6335,7 +6391,10 @@ boolean SnapField(struct PlayerInfo *player, int dx, int dy)
       player->Pushing = FALSE;
 
     player->snapped = FALSE;
-    player->is_digging = FALSE;
+
+    if (player->MovPos == 0)
+      player->is_digging = FALSE;
+
     return FALSE;
   }