rnd-20091125-1-src
[rocksndiamonds.git] / src / game_sp / MainGameLoop.c
index 99c5dbe4496203bdde12c10eac4b96a40707ecaf..38f76fc7f6a1f7b760f5f1fd3a96ba4122f27171 100644 (file)
@@ -35,7 +35,7 @@ int subMainGameLoop_Init()
 
   if (DemoFlag != 0)
   {
-#if 1
+#if 0
     printf("::: playing demo ...\n");
 #endif
 
@@ -45,7 +45,7 @@ int subMainGameLoop_Init()
   }
   else // loc_g_1836:
   {
-#if 1
+#if 0
     printf("::: playing game ...\n");
 #endif
 
@@ -82,7 +82,7 @@ int subMainGameLoop_Init()
   return subMainGameLoop;
 }
 
-int subMainGameLoop_Main()
+int subMainGameLoop_Main(byte action, boolean warp_mode)
 {
   int subMainGameLoop;
   int bx;
@@ -91,7 +91,9 @@ int subMainGameLoop_Main()
   // --------------------- START OF GAME-BUSY LOOP ------------------------------
   // ----------------------------------------------------------------------------
 
+#if 0
 locRepeatMainGameLoop:                           // start repeating game loop
+#endif
 
   // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   // FS   synchronization
@@ -115,13 +117,31 @@ locRepeatMainGameLoop:                           // start repeating game loop
   LastFrame = Clock.TickNow(); // store the frame time
 #endif
   //   never any additional code between here!
+
+
+
+#if 0
   if (! NoDisplayFlag) // copy the BackBuffer(=Stage) to visible screen
     Stage.Blt();
+#endif
+
+
 
   // FS   end of synchronization
   // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+#if 1
   if (EndFlag)
+  {
+    // (should never happen)
+
+    // printf("::: EndFlag == True\n");
+
     goto locExitMainGameLoop;
+  }
+#else
+  if (EndFlag)
+    goto locExitMainGameLoop;
+#endif
 
   // If DemoFlag = 0 Then Call subCheckJoystick    ' check joystick
   // bx = subCheckRightMouseButton()                ' check (right) mouse button
@@ -142,7 +162,7 @@ locRepeatMainGameLoop:                           // start repeating game loop
 
   // loc_g_186F:
 
-  subProcessKeyboardInput();                 // Check keyboard, act on keys
+  subProcessKeyboardInput(action);             // Check keyboard, act on keys
 
   // 'HACK:
   //  TimerVar = TimerVar + 1
@@ -190,8 +210,19 @@ locRepeatMainGameLoop:                           // start repeating game loop
     ScrollTowards(ScreenScrollXPos, ScreenScrollYPos);
   }
 
+#if 1
   if (ForcedExitFlag != 0) // Forced Exit?' yes--exit!
+  {
+    // (should never happen)
+
+    // printf("::: ForcedExitFlag == True\n");
+
     goto locExitMainGameLoop;
+  }
+#else
+  if (ForcedExitFlag != 0) // Forced Exit?' yes--exit!
+    goto locExitMainGameLoop;
+#endif
 
   TimerVar = TimerVar + 1;
 
@@ -206,23 +237,72 @@ locRepeatMainGameLoop:                           // start repeating game loop
   //      .Refresh
   //    End With
   //  End If
+
+#if 1
+  if (ExitToMenuFlag == 1)
+  {
+    // happens when demo ends or when Murphy enters exit (to be checked)
+
+#if 0
+    printf("::: ExitToMenuFlag == True\n");
+#endif
+
+#if 0
+    goto locExitMainGameLoop;
+#endif
+  }
+#else
   if (ExitToMenuFlag == 1)
     goto locExitMainGameLoop;
+#endif
 
+#if 1
+  if (LeadOutCounter == 0) // no lead-out: game busy
+    return subMainGameLoop;
+#else
   if (LeadOutCounter == 0) // no lead-out: game busy
     goto locRepeatMainGameLoop;
+#endif
 
   // ----------------------------------------------------------------------------
   // ---------------------- END OF GAME-BUSY LOOP -------------------------------
   // ----------------------------------------------------------------------------
   LeadOutCounter = LeadOutCounter - 1;             // do more lead-out after quit
+
+#if 0
+  printf("::: LeadOutCounter == %d\n", LeadOutCounter);
+#endif
+
+#if 1
+  if (LeadOutCounter != 0) // lead-out not ready: more
+    return subMainGameLoop;
+#else
   if (LeadOutCounter != 0) // lead-out not ready: more
     goto locRepeatMainGameLoop;
+#endif
 
   // lead-out done: exit now
   // ---------------------- END OF GAME-BUSY LOOP (including lead-out) ----------
 
 locExitMainGameLoop:
+
+#if 1
+  printf("::: locExitMainGameLoop reached [%d]\n", LeadOutCounter);
+  printf("::: [KillMurphyFlag == %d]\n", KillMurphyFlag);
+#endif
+
+#if 1
+  /* if the game is not won when reaching this point, then it is lost */
+  if (!game_sp_info.LevelSolved)
+    game_sp_info.GameOver = TRUE;
+#endif
+
+#if 1
+  return subMainGameLoop;
+#endif
+
+
+
   do
   {
     DoEvents(); // user may klick on menus or move the window here ...
@@ -255,10 +335,11 @@ locExitMainGameLoop:
   if (UpdatedFlag == 0) // update playing time
     subUpdatePlayingTime();
 
-
   return subMainGameLoop;
 } // subMainGameLoop
 
+#if 0
+
 int subMainGameLoop()
 {
   int subMainGameLoop;
@@ -488,6 +569,8 @@ locExitMainGameLoop:
   return subMainGameLoop;
 } // subMainGameLoop
 
+#endif
+
 void subUpdatePlayingTime()
 {
 }
@@ -498,6 +581,21 @@ int subCalculateScreenScrollPos()
 
   int ax, Ay;
 
+#if 1
+  int jump_pos = TILEX / 2;
+
+  if (MurphyScreenXPos < -jump_pos)
+  {
+    MurphyScreenXPos = FieldWidth * TILEX + MurphyScreenXPos;
+    MurphyScreenYPos -= TILEY;
+  }
+  else if (MurphyScreenXPos >= FieldWidth * TILEX - jump_pos)
+  {
+    MurphyScreenXPos = MurphyScreenXPos - FieldWidth * TILEX;
+    MurphyScreenYPos += TILEY;
+  }
+#endif
+
   if (ExplosionShake != 0)
   {
     subGetRandomNumber();