-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.c
264 lines (202 loc) · 7.3 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
*
* Copyright (c) 1994, 2002, 2003 Johannes Prix
* Copyright (c) 1994, 2002, 2003 Reinhard Prix
*
*
* This file is part of Freedroid
*
* Freedroid is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Freedroid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Freedroid; see the file COPYING. If not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*/
/*----------------------------------------------------------------------
*
* Desc: the main program
*
*----------------------------------------------------------------------*/
#define _main_c
#include "system.h"
#include "defs.h"
#include "struct.h"
#include "global.h"
#include "proto.h"
#include "text.h"
#include "vars.h"
#include "map.h"
int ThisMessageTime;
float LastGotIntoBlastSound = 2;
float LastRefreshSound = 2;
extern bool show_cursor;
void UpdateCountersForThisFrame (void);
/*-----------------------------------------------------------------
* @Desc: the heart of the Game
*
* @Ret: void
*
*-----------------------------------------------------------------*/
int
main (int argc, char * argv[])
{
Uint32 now;
float scale;
GameOver = FALSE;
QuitProgram = FALSE;
debug_level = 0; /* 0=no debug 1=first debug level (at the moment=all) */
joy_sensitivity = 1;
sound_on = TRUE; /* default value, can be overridden by command-line */
init_keystr();
now = SDL_GetTicks();
InitFreedroid (argc, argv); // Initialisation of global variables and arrays
SDL_ShowCursor (SDL_DISABLE);
#ifdef __WIN32__
// spread the word :)
Win32Disclaimer ();
#endif
while (!QuitProgram)
{
InitNewMission ( STANDARD_MISSION );
// scale Level-pic rects
if ( (scale = GameConfig.scale) != 1.0)
{
for (int levelnum = 0; levelnum < curShip.num_levels; levelnum++)
for (int i=0; i<curShip.num_level_rects[levelnum]; i++)
ScaleRect (curShip.Level_Rects[levelnum][i], scale);
for (int i=0; i < curShip.num_lift_rows; i++)
ScaleRect (curShip.LiftRow_Rect[i], scale);
}
// release all keys
wait_for_all_keys_released();
show_droid_info (Me.type, -3, 0); // show unit-intro page
show_droid_portrait (Cons_Droid_Rect, Me.type, DROID_ROTATION_TIME, RESET);
now=SDL_GetTicks();
while ( (SDL_GetTicks() - now < SHOW_WAIT) && (!FirePressedR())) {
show_droid_portrait (Cons_Droid_Rect, Me.type, DROID_ROTATION_TIME, 0);
SDL_Delay(1);
}
ClearGraphMem();
DisplayBanner (NULL, NULL, BANNER_FORCE_UPDATE |BANNER_NO_SDL_UPDATE);
SDL_Flip(ne_screen);
GameOver = FALSE;
SDL_SetCursor (crosshair_cursor); // default cursor is a crosshair
SDL_ShowCursor (SDL_ENABLE);
while (!GameOver && !QuitProgram)
{
StartTakingTimeForFPSCalculation();
UpdateCountersForThisFrame ();
ReactToSpecialKeys();
if (show_cursor) SDL_ShowCursor(SDL_ENABLE);
else SDL_ShowCursor(SDL_DISABLE);
MoveLevelDoors ();
AnimateRefresh ();
ExplodeBlasts (); // move blasts to the right current "phase" of the blast
AlertLevelWarning (); // tout tout, blink blink... Alert!!
DisplayBanner (NULL, NULL, 0 );
MoveBullets (); // leave this in front of graphics output: time_in_frames should start with 1
Assemble_Combat_Picture ( DO_SCREEN_UPDATE );
for (int i = 0; i < MAXBULLETS; i++) CheckBulletCollisions (i);
MoveInfluence (); // change Influ-speed depending on keys pressed, but
// also change his status and position and "phase" of rotation
MoveEnemys (); // move all the enemys:
// also do attacks on influ and also move "phase" or their rotation
CheckInfluenceWallCollisions (); /* Testen ob der Weg nicht durch Mauern verstellt ist */
CheckInfluenceEnemyCollision ();
// control speed of time-flow: dark-levels=emptyLevelSpeedup, normal-levels=1.0
if ( ! CurLevel->empty )
{
set_time_factor ( 1.0 );
}
else
{
if ( CurLevel->color == PD_DARK )
{
set_time_factor ( GameConfig.emptyLevelSpeedup );
} // if level is already dark
else if ( CurLevel->timer <= 0 ) // time to switch off the lights ...
{
CurLevel->color = PD_DARK;
Switch_Background_Music_To (BYCOLOR); // start new background music
} // if wait timer hit 0
} // if level empty
CheckIfMissionIsComplete ();
if (!GameConfig.HogCPU) // don't use up 100% CPU unless requested
SDL_Delay (1);
ComputeFPSForThisFrame();
} /* while !GameOver */
} /* while !QuitProgram */
Terminate (0);
return (0);
} // void main(void)
/*-----------------------------------------------------------------
@Desc: This function updates counters and is called ONCE every frame.
The counters include timers, but framerate-independence of game speed
is preserved because everything is weighted with the Frame_Time()
function.
@Ret: none
*-----------------------------------------------------------------*/
void
UpdateCountersForThisFrame (void)
{
// Here are some things, that were previously done by some periodic */
// interrupt function
ThisMessageTime++;
LastGotIntoBlastSound += Frame_Time ();
LastRefreshSound += Frame_Time ();
Me.LastCrysoundTime += Frame_Time ();
Me.timer += Frame_Time();
if (CurLevel->timer >= 0.0) CurLevel->timer -= Frame_Time ();
Me.LastTransferSoundTime += Frame_Time();
Me.TextVisibleTime += Frame_Time();
LevelDoorsNotMovedTime += Frame_Time();
if (SkipAFewFrames) SkipAFewFrames = FALSE;
if ( Me.firewait > 0 )
{
Me.firewait-=Frame_Time();
if (Me.firewait < 0) Me.firewait=0;
}
if (ShipEmptyCounter > 1)
ShipEmptyCounter--;
if (CurLevel->empty > 2)
CurLevel->empty--;
if (RealScore > ShowScore)
ShowScore++;
if (RealScore < ShowScore)
ShowScore--;
// drain Death-count, responsible for Alert-state
if (DeathCount > 0)
DeathCount -= DeathCountDrainSpeed * Frame_Time();
if (DeathCount < 0) DeathCount = 0;
// and switch Alert-level according to DeathCount
AlertLevel = (int)(DeathCount / AlertThreshold);
if (AlertLevel > AL_RED) AlertLevel = AL_RED;
// player gets a bonus/second in AlertLevel
RealScore += AlertLevel * AlertBonusPerSec * Frame_Time();
for (int i = 0; i < MAX_ENEMYS_ON_SHIP ; i++)
{
if (AllEnemys[i].status == OUT ) continue;
if (AllEnemys[i].warten > 0)
{
AllEnemys[i].warten -= Frame_Time() ;
if (AllEnemys[i].warten < 0) AllEnemys[i].warten = 0;
}
if (AllEnemys[i].firewait > 0)
{
AllEnemys[i].firewait -= Frame_Time() ;
if (AllEnemys[i].firewait <= 0) AllEnemys[i].firewait=0;
}
AllEnemys[i].TextVisibleTime += Frame_Time();
} // for (i=0;...
} /* UpdateCountersForThisFrame() */
#undef _main_c