4
int endgame=0,MouseX,MouseY,MissilesCreated=0,NewMissile=10000,WaveNum=0,
5
NewCity=0,CityNum,pause=0;
6
Uint32 Now,TimeStart,FrameCount=0;
7
double Speed,FramesPerSecond;
10
void AddScore(int ScoreBonus)
14
Score+=ScoreBonus*(WaveNum/2+1);
15
sprintf(text, "Score: %d", Score);
18
rect.w=TextWidth(text)+30;
20
SDL_BlitSurface( BackPic, &rect, BackBuffer, &rect);
21
PutString(BackBuffer,0,0,text);
22
SDL_SetAlpha(BackBuffer,(SDL_SRCALPHA), 255);
23
SDL_BlitSurface( BackBuffer, &rect, Screen, &rect);
30
FramesPerSecond=FrameCount*(float)1000/(SDL_GetTicks()-TimeStart);
31
Speed=SDL_GetTicks()-Now;
32
// limit speed to 10ms per frame
35
Speed=(SDL_GetTicks()-Now);
41
void Pause(const SDL_Event *event)
46
while ( event->type == SDL_KEYDOWN )
47
SDL_PollEvent((SDL_Event *)event);
49
// write message to screen
50
SDL_BlitSurface(Screen,NULL,FadeBuffer,NULL);
51
XCenteredString(Screen,250,"Game Paused");
52
SDL_UpdateRect(Screen,0,0,0,0);
55
while ( event->type != SDL_KEYDOWN )
56
SDL_PollEvent((SDL_Event *)event);
59
SDL_BlitSurface(FadeBuffer,NULL,Screen,NULL);
60
SDL_UpdateRect(Screen,0,0,0,0);
65
int NormalEvents(const SDL_Event *event)
67
switch (event->type) {
69
printf("Quit Requested\n");
73
if ( event->key.keysym.sym == SDLK_ESCAPE )
75
if ( (event->key.keysym.sym == SDLK_RETURN) &&
76
(event->key.keysym.mod & KMOD_ALT) )
77
SDL_WM_ToggleFullScreen(SDL_GetVideoSurface());
86
SDL_SetEventFilter(NormalEvents);
89
int GameEvents(const SDL_Event *event)
94
switch (event->type) {
96
printf("Quit Requested\n");
100
/* JOYAXISMOTION is handled elsewhere. */
101
case SDL_JOYBUTTONDOWN:
102
/* TODO: Let user configure which button does what. */
103
if (event->jbutton.state == SDL_PRESSED) {
104
SDL_GetMouseState(&MouseX, &MouseY);
105
/* Joystick buttons are numbered from 0, mouse
106
buttons are numbered from 1 */
107
CreateShot(MouseX,MouseY,event->button.button+1);
110
#endif /* JOYSTICK */
111
case SDL_MOUSEBUTTONDOWN:
112
SDL_GetMouseState(&MouseX, &MouseY);
113
CreateShot(MouseX,MouseY,event->button.button);
116
keys = SDL_GetKeyState(NULL);
117
if ( event->key.keysym.sym == SDLK_a ) button=1;
118
if ( event->key.keysym.sym == SDLK_s ) button=2;
119
if ( event->key.keysym.sym == SDLK_d ) button=3;
121
CreateShot(MouseX,MouseY,button);
123
if ( event->key.keysym.sym == SDLK_ESCAPE ) {
124
printf("Quit Requested\n");
128
if ( (event->key.keysym.sym == SDLK_RETURN) &&
129
(event->key.keysym.mod & KMOD_ALT) )
130
SDL_WM_ToggleFullScreen(SDL_GetVideoSurface());
132
if (( ( event->key.keysym.sym == SDLK_PAUSE ) ||
133
( event->key.keysym.sym == SDLK_p ) ) &&
142
void UndrawCannon(int x, int y)
146
rect.x=x-(int)(Cannon[0]->w/2);
150
SDL_SetAlpha(BackBuffer,(SDL_SRCALPHA),255);
151
BlitPart(rect.x,rect.y,BackBuffer,rect);
154
void DrawCannon(int x, int y)
159
SDL_GetMouseState(&MouseX, &MouseY);
160
deg=atan((float)(MouseY-(y+20))/(float)(MouseX-x));
165
Blit(x-(int)(Cannon[0]->w/2),y,Cannon[0+add]);
167
Blit(x-(int)(Cannon[0]->w/2),y,Cannon[add-(int)(deg*0.6366*10)]);
170
void DrawCenteredText(int y, char *text)
174
rect.x=400-TextWidth(text)/2;
176
rect.w=TextWidth(text);
178
SDL_SetAlpha(BackBuffer,(SDL_SRCALPHA), 255);
179
SDL_BlitSurface( BackBuffer, &rect, Screen, &rect);
180
PutString(Screen,rect.x,rect.y,text);
190
BlitToBB(0,0,BackPic);
193
if (!CityDestroyed[i]) dummy++;
196
if ((!NewCity)||(ArcadeMode)) {
197
while (!CityDestroyed[i])
201
Blit(70+i*100,490,CityPic);
203
Blit(130+i*100,490,CityPic);
204
PlaySound(CitySound);
214
if (!CityDestroyed[i]) CityNum++;
218
if (CityDestroyed[i])
219
BlitToBB(70+i*100,490,CityHitPic);
221
BlitToBB(70+i*100,490,CityPic);
224
if (CityDestroyed[i+3])
225
BlitToBB(430+i*100,490,CityHitPic);
227
BlitToBB(430+i*100,490,CityPic);
228
// Printf "Staring Wave" message
230
Blit(0,0,BackBuffer);
231
sprintf(text,"Starting Wave #%d",WaveNum+1);
232
PutString(Screen, 400-TextWidth(text)/2, 170, text);
233
sprintf(text,"Score %d x",WaveNum/2+1);
234
PutString(Screen, 400-TextWidth(text)/2, 220, text);
235
DrawCenteredText(370, "Defend Cities!");
237
if ( CannonDestroyed[i] ) {
239
CannonDestroyed[i]=0;
246
WaitWithMouse(2000-1000*ArcadeMode);
247
Blit(0,0,BackBuffer);
248
for (i=0;i<3;i++) DrawShotNum(i);
249
SDL_SetEventFilter(GameEvents);
257
SDL_SetEventFilter(NormalEvents);
258
DrawCenteredText(140,"Wave Scoring");
259
x=400-(ShotNum[0]+ShotNum[1]+ShotNum[2])*4;
260
// printf("1: %d\t2: %d\t3: %d\tE: %d\t\n",ShotNum[0],ShotNum[1],ShotNum[2],x);
264
while(ShotNum[i]>0) {
269
sprintf(text," %d ", Score-OldScore);
270
DrawCenteredText(235, text);
280
if (!CityDestroyed[i]) x-=50;
282
if (!CityDestroyed[i]) {
283
Blit(x,285-ArcadeMode*100,CityPic);
286
sprintf(text," %d ", Score-OldScore);
287
DrawCenteredText(380-ArcadeMode*100, text);
289
WaitWithMouse(400-ArcadeMode*100);
291
WaitWithMouse(3000-ArcadeMode*1500);
293
// sprintf(text,"Starting Wave #%d",WaveNum+1);
294
// PutString(Screen, 400-TextWidth(text)/2, 300, text);
302
if (HighDetail) UndrawShot2(); else UndrawShot();
307
if (!CannonDestroyed[0]) UndrawCannon(40,510);
308
if (!CannonDestroyed[1]) UndrawCannon(400,510);
309
if (!CannonDestroyed[2]) UndrawCannon(760,510);
312
if (HighDetail) HandleShot2(); else HandleShot();
318
if (HighDetail) DrawShot2(); else DrawShot();
322
if (!CannonDestroyed[0]) DrawCannon(40,510);
323
if (!CannonDestroyed[1]) DrawCannon(400,510);
324
if (!CannonDestroyed[2]) DrawCannon(760,510);
329
// Are all cities destroyed?
333
if (CityDestroyed[i]==0)
337
if ((NewMissile<0)&&(Wave[WaveNum].MissilesToDestroy>MissilesCreated)) {
339
if ((Rand<Wave[WaveNum].MirvChance)&&(MissileCount>0)) {
340
i=abrand(0,MissileCount-1);
342
while ((Split(i))&&(b<100)) {
343
i=abrand(0,MissileCount-1);
346
} else if (Rand>99-Wave[WaveNum].FlyerChance) {
348
} else if (Rand>99-Wave[WaveNum].BombChance-Wave[WaveNum].FlyerChance) {
351
CreateMissile(abrand(100,700),0);
352
NewMissile+=Wave[WaveNum].TimeBetweenShots;
358
(MissilesCreated==Wave[WaveNum].MissilesToDestroy)
360
&&(ExplosionCount==0)
378
Blit(70+i*100,490,CityPic);
380
Blit(130+i*100,490,CityPic);
382
XCenteredString(Screen,50,"< Arcade Mode >");
383
PutString(Screen,10,160,"-No extra points for remaining shots.");
384
PutString(Screen,10,200,"-More cities result in faster shot regeneration.");
385
PutString(Screen,10,240,"-One city is regenerated per wave.");
386
PutString(Screen,10,280,"-The game is more difficult.");
387
XCenteredString(Screen,400,"click to continue");
388
SDL_BlitSurface(Screen, NULL, BackBuffer, NULL);
390
while (SDL_GetMouseState(NULL,NULL)==SDL_BUTTON(1)) {
391
SDL_PollEvent(&event);
394
while ((event.type!=SDL_KEYDOWN)&&(event.type!=SDL_MOUSEBUTTONDOWN)) {
395
SDL_PollEvent(&event);
408
for (i=0;i<6;i++) CityDestroyed[i]=0;
409
for (i=0;i<3;i++) CannonDestroyed[i]=0;
420
if (ArcadeMode) ShowRules();
421
SDL_SetEventFilter(GameEvents);
425
while ((!endgame)&&(!Quit)) {
428
SDL_PollEvent(&event);
432
Mix_FadeOutMusic(4000);
433
PlaySound(GameoverSound);
443
printf("FPS %f\n",FramesPerSecond);
444
SDL_SetEventFilter(NormalEvents);