1 // ----------------------------------------------------------------------------
3 // ----------------------------------------------------------------------------
5 #include "MainGameLoop.h"
11 boolean AutoScrollFlag;
14 // ==========================================================================
17 // ==========================================================================
19 void subMainGameLoop_Init(void)
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)
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;
54 if (ExplosionShakeMurphy > 0)
55 ExplosionShakeMurphy--;
57 if (ExitToMenuFlag == 1)
59 // happens when demo ends or when Murphy enters exit (to be checked)
62 if (LeadOutCounter == 0) // no lead-out: game busy
65 // ---------------------------------------------------------------------------
66 // ---------------------- END OF GAME-BUSY LOOP ------------------------------
67 // ---------------------------------------------------------------------------
69 LeadOutCounter = LeadOutCounter - 1; // do more lead-out after quit
71 if (LeadOutCounter != 0) // lead-out not ready: more
74 // lead-out done: exit now
75 // ---------------------- END OF GAME-BUSY LOOP (including lead-out) ---------
77 // if the game is not won when reaching this point, then it is lost
78 if (!game_sp.level_solved)
79 game_sp.game_over = TRUE;
82 void subCalculateScreenScrollPos(void)
84 int jump_pos = TILEX / 2;
87 if (MurphyScreenXPos < -jump_pos)
89 MurphyScreenXPos = FieldWidth * TILEX + MurphyScreenXPos;
90 MurphyScreenYPos -= TILEY;
92 else if (MurphyScreenXPos >= FieldWidth * TILEX - jump_pos)
94 MurphyScreenXPos = MurphyScreenXPos - FieldWidth * TILEX;
95 MurphyScreenYPos += TILEY;
98 if (ExplosionShake != 0)
100 subGetRandomNumber();
102 // Debug("game:playing:SP", "ExplosionShake [%d]", FrameCounter);
105 ScreenScrollXPos = MurphyScreenXPos - (SCR_FIELDX / 2) * TILESIZE;
106 ScreenScrollYPos = MurphyScreenYPos - (SCR_FIELDY / 2) * TILESIZE;