# Correct the needed linklibs in curl-config also.
[AROS-Contrib.git] / Games / Bomber / Game.c
blobb9014117ceb8d6ba76dc68846715a7bacbb2aff6
1 //State indicators
2 #define IN_MENU 1
3 #define IN_GAME 2
4 #define IN_WNLS 3
5 #define IN_SETUP 4
6 int State = IN_MENU;
8 //For graphics
9 unsigned char *SpriteBuf;
10 unsigned char *BlocksBuf;
11 ULONG Palette [256];
13 //Variables
14 unsigned char Grid [17][17],
15 BonusGrid [17][17];
16 int PlayerX [5],
17 PlayerY [5],
18 MaxRange [5],
19 MaxBombs [5],
20 PlayerDead [5],
21 PlayerDir [5],
22 PlayerFrame [5],
23 PlayerWon [5];
24 int AllowBombs,
25 TimeOut,
26 Frame,
27 ComputerPlays = 0,
28 Players = 2;
30 //Startup directory
31 char StartDir [1024];
33 #include <stdlib.h>
35 //Function prototypes
36 #include "BomberInclude.c"
38 #include "BomberVarious.c"
39 #include "BomberSounds.c"
40 #include "BomberKeyboard.c"
41 #include "BomberSprites.c"
42 #include "BomberMap.c"
43 #include "BomberPlayers.c"
44 #include "BomberExpl.c"
45 #include "BomberBonus.c"
46 #include "BomberBombs.c"
47 #include "BomberMidi.c"
48 #include "BomberSetup.c"
49 #include "BomberWinLose.c"
50 #include "BomberMenu.c"
52 //Clear all scores
53 void ClearGame ()
55 int p;
57 //Nobody has won yet
58 for (p = 0; p < Players; p++) PlayerWon [p] = 0;
61 //Start a new game
62 void NewGame ()
64 int p;
66 //Player one, start at bottom right
67 PlayerX [0] = PlayerY [0] = (15 << 4) + 8;
68 //Player two start at top left
69 PlayerX [1] = PlayerY [1] = (1 << 4) + 8;
70 //Player three, start at bottom left
71 PlayerX [2] = PlayerX [1];
72 PlayerY [2] = PlayerY [0];
73 //Player four start at top right
74 PlayerX [3] = PlayerX [0];
75 PlayerY [3] = PlayerY [1];
76 //Draw to the backbuffer
77 TargetData = BackBitmapData;
78 //Initialize bombs
79 InitBombs ();
80 //Clear the map
81 CreateMap ();
82 //Clear the bonuses
83 ClearBonus ();
84 //Set time out at 3 minutes = 2770 frames
85 TimeOut = 2770;
86 AllowBombs = -1;
87 //Player is not dead, looking down
88 for (p = 0; p < Players; p++) {
89 PlayerDead [p] = 0;
90 PlayerDir [p] = 0;
92 //Wait until enter has been released
95 HandleIntuiMessages();
96 } while (GetAsyncKeyState (VK_RETURN));
98 CheckKeyboard ();
101 //Check whether the game should end
102 void CheckEndGame ()
104 int LivingPlayers = Players, p;
106 //Move towards timeout
107 TimeOut--;
109 //Count amount of living players
110 for (p = 0; p < Players; p++)
111 if (PlayerDead [p]) LivingPlayers--;
112 //Set timeout and disallow bombs
113 if (LivingPlayers < 2) {
114 if (TimeOut > 60) TimeOut = 60;
115 AllowBombs = 0;
118 //If timeout has been reached, show win/lose screen
119 if (TimeOut == 0) {
120 State = IN_WNLS;
121 InitWinLose ();
125 //Initialize the game
126 void InitGame ()
128 srand ((unsigned)time (NULL));
129 InitKeyboard ();
130 CheckKeyboard ();
131 GetStartDir ();
132 LoadSprites ();
133 LoadBlocks ();
134 LoadSounds ();
135 InitMenu ();
138 //Shut down the game
139 void CloseGame ()
141 UnloadMidi ();
144 //The actual game itself
145 void GameLoop ()
147 StartWait ();
149 //Repeat music
150 if (!Playing) PlayMidi ("BOMBER.MID");
152 //The game logic
153 DrawMap ();
154 MovePlayers ();
155 DropBombs ();
156 CheckBonus ();
157 CheckBombs ();
158 DoExpl ();
159 DrawBonus ();
160 DrawBombs ();
161 DrawPlayers ();
162 CheckEndGame ();
163 FadeOut ();
164 Frame++;
166 //Limit to 15fps
167 WaitFor (65); /* 65 */ /* 1000 / FPS */
168 //Escape quits to menu
169 if (Esc) {
170 StopMidi ();
171 InitMenu ();
172 State = IN_MENU;
176 //Do one game frame
177 void GameFrame ()
179 //Read from keyboard
180 CheckKeyboard ();
182 //Call appropriate frame
183 if (State == IN_MENU) MenuLoop ();
184 if (State == IN_SETUP) SetupLoop ();
185 if (State == IN_GAME) GameLoop ();
186 if (State == IN_WNLS) WinLoseLoop ();