1 // ----------------------------------------------------------------------------
3 // ----------------------------------------------------------------------------
5 #include "MainGameLoop.h"
11 boolean AutoScrollFlag;
14 // ==========================================================================
17 // ==========================================================================
19 void subMainGameLoop_Init()
21 // This was a bug in the original Supaplex: sometimes red disks could not
22 // be released. This happened if Murphy was killed DURING a red disk release
23 // and the next try started.
25 RedDiskReleasePhase = 0; // (re-)enable red disk release
28 void subMainGameLoop_Main(byte action, boolean warp_mode)
30 // ---------------------------------------------------------------------------
31 // --------------------- START OF GAME-BUSY LOOP -----------------------------
32 // ---------------------------------------------------------------------------
34 subProcessKeyboardInput(action); // check keyboard, act on keys
36 // ---------------------------------------------------------------------------
39 subDoGameStuff(); // do all game stuff
42 // ---------------------------------------------------------------------------
44 subRedDiskReleaseExplosion(); // Red Disk release and explode
45 subFollowUpExplosions(); // every explosion may cause up to 8 following explosions
47 subCalculateScreenScrollPos(); // calculate screen start addrs
50 ScrollTowards(ScreenScrollXPos, ScreenScrollYPos);
52 TimerVar = TimerVar + 1;
55 if (ExplosionShakeMurphy > 0)
56 ExplosionShakeMurphy--;
60 if (ExitToMenuFlag == 1)
62 // happens when demo ends or when Murphy enters exit (to be checked)
65 goto locExitMainGameLoop;
69 if (ExitToMenuFlag == 1)
70 goto locExitMainGameLoop;
73 if (LeadOutCounter == 0) // no lead-out: game busy
76 // ---------------------------------------------------------------------------
77 // ---------------------- END OF GAME-BUSY LOOP ------------------------------
78 // ---------------------------------------------------------------------------
80 LeadOutCounter = LeadOutCounter - 1; // do more lead-out after quit
82 if (LeadOutCounter != 0) // lead-out not ready: more
85 // lead-out done: exit now
86 // ---------------------- END OF GAME-BUSY LOOP (including lead-out) ---------
93 printf("::: locExitMainGameLoop reached [%d]\n", LeadOutCounter);
94 printf("::: [KillMurphyFlag == %d]\n", KillMurphyFlag);
98 /* if the game is not won when reaching this point, then it is lost */
99 if (!game_sp.LevelSolved)
100 game_sp.GameOver = TRUE;
104 void subCalculateScreenScrollPos()
107 int jump_pos = TILEX / 2;
109 /* handle wrap-around */
110 if (MurphyScreenXPos < -jump_pos)
112 MurphyScreenXPos = FieldWidth * TILEX + MurphyScreenXPos;
113 MurphyScreenYPos -= TILEY;
115 else if (MurphyScreenXPos >= FieldWidth * TILEX - jump_pos)
117 MurphyScreenXPos = MurphyScreenXPos - FieldWidth * TILEX;
118 MurphyScreenYPos += TILEY;
122 if (ExplosionShake != 0)
124 subGetRandomNumber();
126 // printf("::: ExplosionShake [%d]\n", FrameCounter);
129 ScreenScrollXPos = MurphyScreenXPos - (SCR_FIELDX / 2) * TILESIZE;
130 ScreenScrollYPos = MurphyScreenYPos - (SCR_FIELDY / 2) * TILESIZE;