1 // ----------------------------------------------------------------------------
3 // ----------------------------------------------------------------------------
5 #include "MainGameLoop.h"
7 // static char *VB_Name = "modMainGameLoop";
13 int LeadOutCounter, EnterRepeatCounter;
18 boolean AutoScrollFlag;
20 // ==========================================================================
23 // ==========================================================================
31 TickCountObject Clock;
36 // EP set level success byte: demo, not game
38 EP_GameDemoVar0DAA = 0; // demo
42 // EP set level success byte: game, not demo
44 EP_GameDemoVar0DAA = 1; // game
48 // If RecordDemoFlag = 1 Then
49 // RecordDemoFlag = 0 ' clear Demo Recording flag
50 // Call subDisplayPlayingTime ' playing time on screen
51 // ' Record key still pressed?' >= (Ctrl-)F1 and <= (Ctrl-)F10
52 // While &H3B <= KeyScanCode7 And KeyScanCode7 <= &H44
53 // ' yes -> wait until released
54 // ' should we DoEvents here???? ... depends on how ... but yes!
55 // ' ...or we can rather poll the keyboardstate inside this loop???
57 // Call subInitGameConditions ' Init game conditions (vars)
58 // If MusicOnFlag = 0 Then Call subMusicInit
59 // WasDemoFlag = 0 ' no demo anymore
60 // EP_GameDemoVar0DAA = 1 ' force game
63 // This was a bug in the original Supaplex: sometimes red disks could not
64 // be released. This happened If Murphy was killed DURING a red disk release
65 // and the next try started.
67 RedDiskReleasePhase = 0; // (re-)enable red disk release
72 // ----------------------------------------------------------------------------
73 // --------------------- START OF GAME-BUSY LOOP ------------------------------
74 // ----------------------------------------------------------------------------
76 locRepeatMainGameLoop: // start repeating game loop
78 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
80 while (PauseMode != 0)
87 DoEvents(); // user may klick on menus or move the window here ...
89 while (Clock.TickDiffUS(LastFrame) < DeltaT); // wait till its time for the next frame
91 // never any additional code between here!
92 LastFrame = Clock.TickNow; // store the frame time
93 // never any additional code between here!
94 if (! NoDisplayFlag) // copy the BackBuffer(=Stage) to visible screen
97 // FS end of synchronization
98 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
100 goto locExitMainGameLoop;
102 // If DemoFlag = 0 Then Call subCheckJoystick ' check joystick
103 // bx = subCheckRightMouseButton() ' check (right) mouse button
104 // If bx = 2 And LeadOutCounter < 1 Then KillMurphyFlag = 1 ' lead-out busy after quit? -> kill Murphy!
106 // If DebugVersionFlag <> 0 Then ' debug mode on?
107 // If Data_SubRest <> 0 Then Data_SubRest = Data_SubRest - 1
108 // If keyEnter <> 0 Then GoTo loc_g_186F ' Was it the Enter key? -> yes--skip! No mouse!
109 // ' fixes ENTER bug If no mouse driver!
110 // If bx <> 1 Then GoTo loc_g_186F ' Left button=Init game field
111 // ' Also Enter If no mouse!
112 // If Data_SubRest <> 0 Then GoTo loc_g_186F
114 // Call subRestoreFancy
115 // Call subDisplayLevel ' Paint (Init) game field
116 // Call subConvertToEasySymbols ' Convert to easy symbols
121 subProcessKeyboardInput(); // Check keyboard, act on keys
124 // TimerVar = TimerVar + 1
128 // If RecordDemoFlag = 1 Then GoTo RestartGameLoop
130 // ----------------------------------------------------------------------------
133 subDoGameStuff(); // do all game stuff
136 // ----------------------------------------------------------------------------
138 // Call subDisplayPlayingTime ' playing time on screen
140 subCheckRestoreRedDiskCountDisplay(); // Restore panel: red-disk hole
142 subRedDiskReleaseExplosion(); // Red Disk release and explode
143 subFollowUpExplosions(); // every explosion may cause up to 8 following explosions
145 bx = subCalculateScreenScrollPos(); // calculate screen start addrs
149 // Now new X and new Y are calculated, and bx = screen position = ScreenPosition
150 data_h_Ytmp = ScreenScrollYPos; // copy Y for next soft scroll
151 data_h_Xtmp = ScreenScrollXPos; // copy X for next soft scroll
152 if ((! UserDragFlag) && AutoScrollFlag)
153 ScrollTowards(ScreenScrollXPos, ScreenScrollYPos);
155 if (ForcedExitFlag != 0) // Forced Exit?' yes--exit!
156 goto locExitMainGameLoop;
158 TimerVar = TimerVar + 1;
162 MainForm.SaveSnapshot(TimerVar);
165 // If Not NoDisplayFlag Then
166 // With MainForm.lblFrameCount
167 // .Caption = TimerVar
171 if (ExitToMenuFlag == 1)
172 goto locExitMainGameLoop;
174 if (LeadOutCounter == 0) // no lead-out: game busy
175 goto locRepeatMainGameLoop;
177 // ----------------------------------------------------------------------------
178 // ---------------------- END OF GAME-BUSY LOOP -------------------------------
179 // ----------------------------------------------------------------------------
180 LeadOutCounter = LeadOutCounter - 1; // do more lead-out after quit
181 if (LeadOutCounter != 0) // lead-out not ready: more
182 goto locRepeatMainGameLoop;
184 // lead-out done: exit now
185 // ---------------------- END OF GAME-BUSY LOOP (including lead-out) ----------
190 DoEvents(); // user may klick on menus or move the window here ...
192 while (Clock.TickDiffUS(LastFrame) < DeltaT); // wait till its time for the next frame
194 Stage.Blt(); // blit the last frame
198 MainForm.menStop_Click();
199 MainForm.PanelVisible = True;
202 // If DemoRecordingFlag <> 0 Then Call subCloseDemoRecordingFile ' Demo recording on? -> close opened demo file (w)
203 if (SavedGameFlag != 0) // after savegame: no update!
206 return subMainGameLoop;
210 if (UpdateTimeFlag == 0) // update time?
211 return subMainGameLoop;
213 if (UpdatedFlag == 0) // update playing time
214 subUpdatePlayingTime();
217 return subMainGameLoop;
220 void subUpdatePlayingTime()
224 int subCalculateScreenScrollPos()
226 int subCalculateScreenScrollPos;
230 if (ExplosionShake != 0)
232 subGetRandomNumber();
236 ax = MainForm.picPane.Width / 2;
237 Ay = MainForm.picPane.Height / 2;
239 ScreenScrollXPos = Stretch * (MurphyScreenXPos + 8) - ax;
240 ScreenScrollYPos = Stretch * (MurphyScreenYPos + 8) - Ay;
242 return subCalculateScreenScrollPos;