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 subDoGameStuff(); // do all game stuff
148 // ----------------------------------------------------------------------------
150 // Call subDisplayPlayingTime ' playing time on screen
152 subCheckRestoreRedDiskCountDisplay(); // Restore panel: red-disk hole
154 subRedDiskReleaseExplosion(); // Red Disk release and explode
155 subFollowUpExplosions(); // every explosion may cause up to 8 following explosions
157 bx = subCalculateScreenScrollPos(); // calculate screen start addrs
161 // Now new X and new Y are calculated, and bx = screen position = ScreenPosition
162 data_h_Ytmp = ScreenScrollYPos; // copy Y for next soft scroll
163 data_h_Xtmp = ScreenScrollXPos; // copy X for next soft scroll
164 if ((! UserDragFlag) && AutoScrollFlag)
165 ScrollTowards(ScreenScrollXPos, ScreenScrollYPos);
167 if (ForcedExitFlag != 0) // Forced Exit?' yes--exit!
168 goto locExitMainGameLoop;
170 TimerVar = TimerVar + 1;
174 MainForm.SaveSnapshot(TimerVar);
177 // If Not NoDisplayFlag Then
178 // With MainForm.lblFrameCount
179 // .Caption = TimerVar
183 if (ExitToMenuFlag == 1)
184 goto locExitMainGameLoop;
186 if (LeadOutCounter == 0) // no lead-out: game busy
187 goto locRepeatMainGameLoop;
189 // ----------------------------------------------------------------------------
190 // ---------------------- END OF GAME-BUSY LOOP -------------------------------
191 // ----------------------------------------------------------------------------
192 LeadOutCounter = LeadOutCounter - 1; // do more lead-out after quit
193 if (LeadOutCounter != 0) // lead-out not ready: more
194 goto locRepeatMainGameLoop;
196 // lead-out done: exit now
197 // ---------------------- END OF GAME-BUSY LOOP (including lead-out) ----------
202 DoEvents(); // user may klick on menus or move the window here ...
207 while (Clock.TickDiffUS(LastFrame) < DeltaT); // wait till its time for the next frame
210 Stage.Blt(); // blit the last frame
214 MainForm.menStop_Click();
215 MainForm.PanelVisible = True;
218 // If DemoRecordingFlag <> 0 Then Call subCloseDemoRecordingFile ' Demo recording on? -> close opened demo file (w)
219 if (SavedGameFlag != 0) // after savegame: no update!
222 return subMainGameLoop;
226 if (UpdateTimeFlag == 0) // update time?
227 return subMainGameLoop;
229 if (UpdatedFlag == 0) // update playing time
230 subUpdatePlayingTime();
233 return subMainGameLoop;
236 void subUpdatePlayingTime()
240 int subCalculateScreenScrollPos()
242 int subCalculateScreenScrollPos;
246 if (ExplosionShake != 0)
248 subGetRandomNumber();
252 ax = MainForm.picPane.Width / 2;
253 Ay = MainForm.picPane.Height / 2;
257 ScreenScrollXPos = Stretch * (MurphyScreenXPos + 16) - ax;
258 ScreenScrollYPos = Stretch * (MurphyScreenYPos + 16) - Ay;
260 ScreenScrollXPos = Stretch * (MurphyScreenXPos + 8) - ax;
261 ScreenScrollYPos = Stretch * (MurphyScreenYPos + 8) - Ay;
265 printf("::: MainGameLoop.c: subCalculateScreenScrollPos(): %d, %d [%d, %d] -> %d, %d\n",
266 MainForm.picPane.Width, MainForm.picPane.Height,
267 MurphyScreenXPos, MurphyScreenYPos,
268 ScreenScrollXPos, ScreenScrollYPos);
271 return subCalculateScreenScrollPos;