1 // ----------------------------------------------------------------------------
3 // ----------------------------------------------------------------------------
5 #include "MainGameLoop.h"
10 int LeadOutCounter, EnterRepeatCounter;
15 boolean AutoScrollFlag;
18 // ==========================================================================
21 // ==========================================================================
23 void subMainGameLoop_Init()
27 // EP set level success byte: demo, not game
29 EP_GameDemoVar0DAA = 0; // demo
33 // EP set level success byte: game, not demo
35 EP_GameDemoVar0DAA = 1; // game
38 // This was a bug in the original Supaplex: sometimes red disks could not
39 // be released. This happened if Murphy was killed DURING a red disk release
40 // and the next try started.
42 RedDiskReleasePhase = 0; // (re-)enable red disk release
48 void subMainGameLoop_Main(byte action, boolean warp_mode)
50 // ---------------------------------------------------------------------------
51 // --------------------- START OF GAME-BUSY LOOP -----------------------------
52 // ---------------------------------------------------------------------------
56 // (should never happen)
58 // printf("::: EndFlag == True\n");
60 goto locExitMainGameLoop;
63 subProcessKeyboardInput(action); // check keyboard, act on keys
65 // ---------------------------------------------------------------------------
68 subDoGameStuff(); // do all game stuff
71 // ---------------------------------------------------------------------------
73 subRedDiskReleaseExplosion(); // Red Disk release and explode
74 subFollowUpExplosions(); // every explosion may cause up to 8 following explosions
76 subCalculateScreenScrollPos(); // calculate screen start addrs
78 if ((! UserDragFlag) && AutoScrollFlag)
79 ScrollTowards(ScreenScrollXPos, ScreenScrollYPos);
81 if (ForcedExitFlag != 0) // Forced Exit?' yes--exit!
83 // (should never happen)
85 // printf("::: ForcedExitFlag == True\n");
87 goto locExitMainGameLoop;
90 TimerVar = TimerVar + 1;
93 if (ExitToMenuFlag == 1)
95 // happens when demo ends or when Murphy enters exit (to be checked)
98 goto locExitMainGameLoop;
102 if (ExitToMenuFlag == 1)
103 goto locExitMainGameLoop;
106 if (LeadOutCounter == 0) // no lead-out: game busy
109 // ---------------------------------------------------------------------------
110 // ---------------------- END OF GAME-BUSY LOOP ------------------------------
111 // ---------------------------------------------------------------------------
113 LeadOutCounter = LeadOutCounter - 1; // do more lead-out after quit
115 if (LeadOutCounter != 0) // lead-out not ready: more
118 // lead-out done: exit now
119 // ---------------------- END OF GAME-BUSY LOOP (including lead-out) ---------
124 printf("::: locExitMainGameLoop reached [%d]\n", LeadOutCounter);
125 printf("::: [KillMurphyFlag == %d]\n", KillMurphyFlag);
129 /* if the game is not won when reaching this point, then it is lost */
130 if (!game_sp.LevelSolved)
131 game_sp.GameOver = TRUE;
135 void subCalculateScreenScrollPos()
140 int jump_pos = TILEX / 2;
142 if (MurphyScreenXPos < -jump_pos)
144 MurphyScreenXPos = FieldWidth * TILEX + MurphyScreenXPos;
145 MurphyScreenYPos -= TILEY;
147 else if (MurphyScreenXPos >= FieldWidth * TILEX - jump_pos)
149 MurphyScreenXPos = MurphyScreenXPos - FieldWidth * TILEX;
150 MurphyScreenYPos += TILEY;
154 if (ExplosionShake != 0)
156 subGetRandomNumber();
158 // printf("::: ExplosionShake [%d]\n", FrameCounter);
162 ax = MainForm.picPane.Width / 2;
163 Ay = MainForm.picPane.Height / 2;
166 ScreenScrollXPos = Stretch * (MurphyScreenXPos + TILEX / 2) - ax;
167 ScreenScrollYPos = Stretch * (MurphyScreenYPos + TILEY / 2) - Ay;