1 // ----------------------------------------------------------------------------
3 // ----------------------------------------------------------------------------
5 #include "MainGameLoop.h"
7 // static char *VB_Name = "modMainGameLoop";
13 int LeadOutCounter, EnterRepeatCounter;
18 boolean AutoScrollFlag;
20 // ==========================================================================
23 // ==========================================================================
32 TickCountObject Clock;
38 printf("::: playing demo ...\n");
40 // EP set level success byte: demo, not game
42 EP_GameDemoVar0DAA = 0; // demo
46 printf("::: playing game ...\n");
48 // EP set level success byte: game, not demo
50 EP_GameDemoVar0DAA = 1; // game
54 // If RecordDemoFlag = 1 Then
55 // RecordDemoFlag = 0 ' clear Demo Recording flag
56 // Call subDisplayPlayingTime ' playing time on screen
57 // ' Record key still pressed?' >= (Ctrl-)F1 and <= (Ctrl-)F10
58 // While &H3B <= KeyScanCode7 And KeyScanCode7 <= &H44
59 // ' yes -> wait until released
60 // ' should we DoEvents here???? ... depends on how ... but yes!
61 // ' ...or we can rather poll the keyboardstate inside this loop???
63 // Call subInitGameConditions ' Init game conditions (vars)
64 // If MusicOnFlag = 0 Then Call subMusicInit
65 // WasDemoFlag = 0 ' no demo anymore
66 // EP_GameDemoVar0DAA = 1 ' force game
69 // This was a bug in the original Supaplex: sometimes red disks could not
70 // be released. This happened If Murphy was killed DURING a red disk release
71 // and the next try started.
73 RedDiskReleasePhase = 0; // (re-)enable red disk release
78 // ----------------------------------------------------------------------------
79 // --------------------- START OF GAME-BUSY LOOP ------------------------------
80 // ----------------------------------------------------------------------------
82 locRepeatMainGameLoop: // start repeating game loop
84 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
86 while (PauseMode != 0)
93 DoEvents(); // user may klick on menus or move the window here ...
98 while (Clock.TickDiffUS(LastFrame) < DeltaT); // wait till its time for the next frame
101 // never any additional code between here!
103 LastFrame = Clock.TickNow(); // store the frame time
105 // never any additional code between here!
106 if (! NoDisplayFlag) // copy the BackBuffer(=Stage) to visible screen
109 // FS end of synchronization
110 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
112 goto locExitMainGameLoop;
114 // If DemoFlag = 0 Then Call subCheckJoystick ' check joystick
115 // bx = subCheckRightMouseButton() ' check (right) mouse button
116 // If bx = 2 And LeadOutCounter < 1 Then KillMurphyFlag = 1 ' lead-out busy after quit? -> kill Murphy!
118 // If DebugVersionFlag <> 0 Then ' debug mode on?
119 // If Data_SubRest <> 0 Then Data_SubRest = Data_SubRest - 1
120 // If keyEnter <> 0 Then GoTo loc_g_186F ' Was it the Enter key? -> yes--skip! No mouse!
121 // ' fixes ENTER bug If no mouse driver!
122 // If bx <> 1 Then GoTo loc_g_186F ' Left button=Init game field
123 // ' Also Enter If no mouse!
124 // If Data_SubRest <> 0 Then GoTo loc_g_186F
126 // Call subRestoreFancy
127 // Call subDisplayLevel ' Paint (Init) game field
128 // Call subConvertToEasySymbols ' Convert to easy symbols
133 subProcessKeyboardInput(); // Check keyboard, act on keys
136 // TimerVar = TimerVar + 1
140 // If RecordDemoFlag = 1 Then GoTo RestartGameLoop
142 // ----------------------------------------------------------------------------
145 printf("::: MainGameLoop.c: subDoGameStuff() START\n");
147 subDoGameStuff(); // do all game stuff
149 printf("::: MainGameLoop.c: subDoGameStuff() END\n");
152 // ----------------------------------------------------------------------------
154 // Call subDisplayPlayingTime ' playing time on screen
156 subCheckRestoreRedDiskCountDisplay(); // Restore panel: red-disk hole
158 subRedDiskReleaseExplosion(); // Red Disk release and explode
159 subFollowUpExplosions(); // every explosion may cause up to 8 following explosions
161 bx = subCalculateScreenScrollPos(); // calculate screen start addrs
165 // Now new X and new Y are calculated, and bx = screen position = ScreenPosition
166 data_h_Ytmp = ScreenScrollYPos; // copy Y for next soft scroll
167 data_h_Xtmp = ScreenScrollXPos; // copy X for next soft scroll
168 if ((! UserDragFlag) && AutoScrollFlag)
169 ScrollTowards(ScreenScrollXPos, ScreenScrollYPos);
171 if (ForcedExitFlag != 0) // Forced Exit?' yes--exit!
172 goto locExitMainGameLoop;
174 TimerVar = TimerVar + 1;
178 MainForm.SaveSnapshot(TimerVar);
181 // If Not NoDisplayFlag Then
182 // With MainForm.lblFrameCount
183 // .Caption = TimerVar
187 if (ExitToMenuFlag == 1)
188 goto locExitMainGameLoop;
190 if (LeadOutCounter == 0) // no lead-out: game busy
191 goto locRepeatMainGameLoop;
193 // ----------------------------------------------------------------------------
194 // ---------------------- END OF GAME-BUSY LOOP -------------------------------
195 // ----------------------------------------------------------------------------
196 LeadOutCounter = LeadOutCounter - 1; // do more lead-out after quit
197 if (LeadOutCounter != 0) // lead-out not ready: more
198 goto locRepeatMainGameLoop;
200 // lead-out done: exit now
201 // ---------------------- END OF GAME-BUSY LOOP (including lead-out) ----------
206 DoEvents(); // user may klick on menus or move the window here ...
211 while (Clock.TickDiffUS(LastFrame) < DeltaT); // wait till its time for the next frame
214 Stage.Blt(); // blit the last frame
218 MainForm.menStop_Click();
219 MainForm.PanelVisible = True;
222 // If DemoRecordingFlag <> 0 Then Call subCloseDemoRecordingFile ' Demo recording on? -> close opened demo file (w)
223 if (SavedGameFlag != 0) // after savegame: no update!
226 return subMainGameLoop;
230 if (UpdateTimeFlag == 0) // update time?
231 return subMainGameLoop;
233 if (UpdatedFlag == 0) // update playing time
234 subUpdatePlayingTime();
237 return subMainGameLoop;
240 void subUpdatePlayingTime()
244 int subCalculateScreenScrollPos()
246 int subCalculateScreenScrollPos;
250 if (ExplosionShake != 0)
252 subGetRandomNumber();
256 ax = MainForm.picPane.Width / 2;
257 Ay = MainForm.picPane.Height / 2;
261 ScreenScrollXPos = Stretch * (MurphyScreenXPos + 16) - ax;
262 ScreenScrollYPos = Stretch * (MurphyScreenYPos + 16) - Ay;
264 ScreenScrollXPos = Stretch * (MurphyScreenXPos + 8) - ax;
265 ScreenScrollYPos = Stretch * (MurphyScreenYPos + 8) - Ay;
269 printf("::: MainGameLoop.c: subCalculateScreenScrollPos(): %d, %d [%d, %d] -> %d, %d\n",
270 MainForm.picPane.Width, MainForm.picPane.Height,
271 MurphyScreenXPos, MurphyScreenYPos,
272 ScreenScrollXPos, ScreenScrollYPos);
275 return subCalculateScreenScrollPos;