rnd-20100316-1-src
[rocksndiamonds.git] / src / game_sp / MainGameLoop.c
1 // ----------------------------------------------------------------------------
2 // MainGameLoop.c
3 // ----------------------------------------------------------------------------
4
5 #include "MainGameLoop.h"
6
7
8 boolean bPlaying;
9 int LeadOutCounter, EnterRepeatCounter;
10 int ExitToMenuFlag;
11 boolean AutoScrollFlag;
12
13
14 // ==========================================================================
15 //                              SUBROUTINE
16 // Play a game/demo
17 // ==========================================================================
18
19 void subMainGameLoop_Init()
20 {
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.
24
25   RedDiskReleasePhase = 0; // (re-)enable red disk release
26 }
27
28 void subMainGameLoop_Main(byte action, boolean warp_mode)
29 {
30   // ---------------------------------------------------------------------------
31   // --------------------- START OF GAME-BUSY LOOP -----------------------------
32   // ---------------------------------------------------------------------------
33
34   subProcessKeyboardInput(action);      // check keyboard, act on keys
35
36   // ---------------------------------------------------------------------------
37   //
38
39   subDoGameStuff();                     // do all game stuff
40
41   //
42   // ---------------------------------------------------------------------------
43
44   subRedDiskReleaseExplosion();         // Red Disk release and explode
45   subFollowUpExplosions();              // every explosion may cause up to 8 following explosions
46
47   subCalculateScreenScrollPos();        // calculate screen start addrs
48
49   if (AutoScrollFlag)
50     ScrollTowards(ScreenScrollXPos, ScreenScrollYPos);
51
52   TimerVar = TimerVar + 1;
53
54 #if 1
55   if (ExitToMenuFlag == 1)
56   {
57     // happens when demo ends or when Murphy enters exit (to be checked)
58
59 #if 0
60     goto locExitMainGameLoop;
61 #endif
62   }
63 #else
64   if (ExitToMenuFlag == 1)
65     goto locExitMainGameLoop;
66 #endif
67
68   if (LeadOutCounter == 0) // no lead-out: game busy
69     return;
70
71   // ---------------------------------------------------------------------------
72   // ---------------------- END OF GAME-BUSY LOOP ------------------------------
73   // ---------------------------------------------------------------------------
74
75   LeadOutCounter = LeadOutCounter - 1;          // do more lead-out after quit
76
77   if (LeadOutCounter != 0)                      // lead-out not ready: more
78     return;
79
80   // lead-out done: exit now
81   // ---------------------- END OF GAME-BUSY LOOP (including lead-out) ---------
82
83 #if 0
84 locExitMainGameLoop:
85 #endif
86
87 #if 1
88   printf("::: locExitMainGameLoop reached [%d]\n", LeadOutCounter);
89   printf("::: [KillMurphyFlag == %d]\n", KillMurphyFlag);
90 #endif
91
92 #if 1
93   /* if the game is not won when reaching this point, then it is lost */
94   if (!game_sp.LevelSolved)
95     game_sp.GameOver = TRUE;
96 #endif
97 }
98
99 void subCalculateScreenScrollPos()
100 {
101   int ax, Ay;
102
103 #if 1
104   int jump_pos = TILEX / 2;
105
106   if (MurphyScreenXPos < -jump_pos)
107   {
108     MurphyScreenXPos = FieldWidth * TILEX + MurphyScreenXPos;
109     MurphyScreenYPos -= TILEY;
110   }
111   else if (MurphyScreenXPos >= FieldWidth * TILEX - jump_pos)
112   {
113     MurphyScreenXPos = MurphyScreenXPos - FieldWidth * TILEX;
114     MurphyScreenYPos += TILEY;
115   }
116 #endif
117
118   if (ExplosionShake != 0)
119   {
120     subGetRandomNumber();
121
122     // printf("::: ExplosionShake [%d]\n", FrameCounter);
123   }
124
125   {
126     ax = SXSIZE / 2;
127     Ay = SYSIZE / 2;
128   }
129
130   ScreenScrollXPos = Stretch * (MurphyScreenXPos + TILEX / 2) - ax;
131   ScreenScrollYPos = Stretch * (MurphyScreenYPos + TILEY / 2) - Ay;
132 }