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.
66 RedDiskReleasePhase = 0; // (re-)enable red disk release
70 // ----------------------------------------------------------------------------
71 // --------------------- START OF GAME-BUSY LOOP ------------------------------
72 // ----------------------------------------------------------------------------
74 locRepeatMainGameLoop: // start repeating game loop
76 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
78 while (PauseMode != 0)
85 DoEvents(); // user may klick on menus or move the window here ...
87 while (Clock.TickDiffUS(LastFrame) < DeltaT); // wait till its time for the next frame
89 // never any additional code between here!
90 LastFrame = Clock.TickNow; // store the frame time
91 // never any additional code between here!
92 if (! NoDisplayFlag) // copy the BackBuffer(=Stage) to visible screen
95 // FS end of synchronization
96 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
98 goto locExitMainGameLoop;
100 // If DemoFlag = 0 Then Call subCheckJoystick ' check joystick
101 // bx = subCheckRightMouseButton() ' check (right) mouse button
102 // If bx = 2 And LeadOutCounter < 1 Then KillMurphyFlag = 1 ' lead-out busy after quit? -> kill Murphy!
104 // If DebugVersionFlag <> 0 Then ' debug mode on?
105 // If Data_SubRest <> 0 Then Data_SubRest = Data_SubRest - 1
106 // If keyEnter <> 0 Then GoTo loc_g_186F ' Was it the Enter key? -> yes--skip! No mouse!
107 // ' fixes ENTER bug If no mouse driver!
108 // If bx <> 1 Then GoTo loc_g_186F ' Left button=Init game field
109 // ' Also Enter If no mouse!
110 // If Data_SubRest <> 0 Then GoTo loc_g_186F
112 // Call subRestoreFancy
113 // Call subDisplayLevel ' Paint (Init) game field
114 // Call subConvertToEasySymbols ' Convert to easy symbols
119 subProcessKeyboardInput(); // Check keyboard, act on keys
121 // TimerVar = TimerVar + 1
125 // If RecordDemoFlag = 1 Then GoTo RestartGameLoop
127 // ----------------------------------------------------------------------------
129 subDoGameStuff(); // do all game stuff
131 // ----------------------------------------------------------------------------
133 // Call subDisplayPlayingTime ' playing time on screen
134 subCheckRestoreRedDiskCountDisplay(); // Restore panel: red-disk hole
136 subRedDiskReleaseExplosion(); // Red Disk release and explode
137 subFollowUpExplosions(); // every explosion may cause up to 8 following explosions
139 bx = subCalculateScreenScrollPos(); // calculate screen start addrs
141 // Now new X and new Y are calculated, and bx = screen position = ScreenPosition
142 data_h_Ytmp = ScreenScrollYPos; // copy Y for next soft scroll
143 data_h_Xtmp = ScreenScrollXPos; // copy X for next soft scroll
144 if ((! UserDragFlag) && AutoScrollFlag)
145 ScrollTowards(ScreenScrollXPos, ScreenScrollYPos);
147 if (ForcedExitFlag != 0) // Forced Exit?' yes--exit!
148 goto locExitMainGameLoop;
150 TimerVar = TimerVar + 1;
154 MainForm.SaveSnapshot(TimerVar);
157 // If Not NoDisplayFlag Then
158 // With MainForm.lblFrameCount
159 // .Caption = TimerVar
163 if (ExitToMenuFlag == 1)
164 goto locExitMainGameLoop;
166 if (LeadOutCounter == 0) // no lead-out: game busy
167 goto locRepeatMainGameLoop;
169 // ----------------------------------------------------------------------------
170 // ---------------------- END OF GAME-BUSY LOOP -------------------------------
171 // ----------------------------------------------------------------------------
172 LeadOutCounter = LeadOutCounter - 1; // do more lead-out after quit
173 if (LeadOutCounter != 0) // lead-out not ready: more
174 goto locRepeatMainGameLoop;
176 // lead-out done: exit now
177 // ---------------------- END OF GAME-BUSY LOOP (including lead-out) ----------
182 DoEvents(); // user may klick on menus or move the window here ...
184 while (Clock.TickDiffUS(LastFrame) < DeltaT); // wait till its time for the next frame
186 Stage.Blt(); // blit the last frame
190 MainForm.menStop_Click();
191 MainForm.PanelVisible = True;
194 // If DemoRecordingFlag <> 0 Then Call subCloseDemoRecordingFile ' Demo recording on? -> close opened demo file (w)
195 if (SavedGameFlag != 0) // after savegame: no update!
198 return subMainGameLoop;
202 if (UpdateTimeFlag == 0) // update time?
203 return subMainGameLoop;
205 if (UpdatedFlag == 0) // update playing time
206 subUpdatePlayingTime();
209 return subMainGameLoop;
212 void subUpdatePlayingTime()
216 int subCalculateScreenScrollPos()
218 int subCalculateScreenScrollPos;
222 if (ExplosionShake != 0)
224 subGetRandomNumber();
228 ax = MainForm.picPane.Width / 2;
229 Ay = MainForm.picPane.Height / 2;
231 ScreenScrollXPos = Stretch * (MurphyScreenXPos + 8) - ax;
232 ScreenScrollYPos = Stretch * (MurphyScreenYPos + 8) - Ay;
234 return subCalculateScreenScrollPos;