1
/************************************************************************************
3
AstroMenace (Hardcore 3D space shooter with spaceship upgrade possibilities)
4
Copyright © 2006-2012 Michael Kurinnoy, Viewizard
7
AstroMenace is free software: you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation, either version 3 of the License, or
10
(at your option) any later version.
12
AstroMenace is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with AstroMenace. If not, see <http://www.gnu.org/licenses/>.
21
Web Site: http://www.viewizard.com/
22
Project: http://sourceforge.net/projects/openastromenace/
23
E-mail: viewizard@viewizard.com
25
*************************************************************************************/
32
//------------------------------------------------------------------------------------
34
//------------------------------------------------------------------------------------
36
eParticleSystem *psSpace = 0;
38
float LastMenuUpdateTime = 0.0f;
39
float MenuContentTransp = 0.0f;
40
float LastMenuOnOffUpdateTime = 0.0f;
41
float MenuBlackTransp = 0.0f;
42
bool NeedOnMenu = false;// если нужно выйти из черного
43
bool NeedOffMenu = false;// если нужно выйти из черного
44
bool NeedShowMenu = false;
45
bool NeedHideMenu = false;
47
eGameStatus PrevMenu = MAIN_MENU;
49
float Button1Transp = 1.0f;
50
float LastButton1UpdateTime = 0.0f;
51
float Button2Transp = 1.0f;
52
float LastButton2UpdateTime = 0.0f;
53
float Button3Transp = 1.0f;
54
float LastButton3UpdateTime = 0.0f;
55
float Button4Transp = 1.0f;
56
float LastButton4UpdateTime = 0.0f;
57
float Button5Transp = 1.0f;
58
float LastButton5UpdateTime = 0.0f;
59
float Button6Transp = 1.0f;
60
float LastButton6UpdateTime = 0.0f;
61
float Button7Transp = 1.0f;
62
float LastButton7UpdateTime = 0.0f;
63
float Button8Transp = 1.0f;
64
float LastButton8UpdateTime = 0.0f;
65
float Button9Transp = 1.0f;
66
float LastButton9UpdateTime = 0.0f;
67
float Button10Transp = 1.0f;
68
float LastButton10UpdateTime = 0.0f;
69
float Button11Transp = 1.0f;
70
float LastButton11UpdateTime = 0.0f;
71
float Button12Transp = 1.0f;
72
float LastButton12UpdateTime = 0.0f;
73
float Button13Transp = 1.0f;
74
float LastButton13UpdateTime = 0.0f;
75
float Button14Transp = 1.0f;
76
float LastButton14UpdateTime = 0.0f;
79
// для прорисовки подложки с тайловой анимацией
80
extern float StarsTileUpdateTime;
81
extern float StarsTileUpdateTime2;
88
//------------------------------------------------------------------------------------
90
//------------------------------------------------------------------------------------
95
// установка курсора на центр
96
// получаем размер клиентской области
98
vw_GetViewport(0, 0, &W, &H);
103
vw_GetAspectWH(&ARWidth, &ARHeight);
104
// установка мышки, чтобы не учитывать перемещения в меню
105
SDL_WarpMouse((int)((512.0f+256.0f)/(ARWidth/AWw)), (int)(384.0f/(ARHeight/AHw)));
109
Button1Transp = 1.0f;
110
LastButton1UpdateTime = 0.0f;
111
Button2Transp = 1.0f;
112
LastButton2UpdateTime = 0.0f;
113
Button3Transp = 1.0f;
114
LastButton3UpdateTime = 0.0f;
115
Button4Transp = 1.0f;
116
LastButton4UpdateTime = 0.0f;
117
Button5Transp = 1.0f;
118
LastButton5UpdateTime = 0.0f;
119
Button6Transp = 1.0f;
120
LastButton6UpdateTime = 0.0f;
121
Button7Transp = 1.0f;
122
LastButton7UpdateTime = 0.0f;
123
Button8Transp = 1.0f;
124
LastButton8UpdateTime = 0.0f;
125
Button9Transp = 1.0f;
126
LastButton9UpdateTime = 0.0f;
127
Button10Transp = 1.0f;
128
LastButton10UpdateTime = 0.0f;
129
Button11Transp = 1.0f;
130
LastButton11UpdateTime = 0.0f;
131
Button12Transp = 1.0f;
132
LastButton12UpdateTime = 0.0f;
133
Button13Transp = 1.0f;
134
LastButton13UpdateTime = 0.0f;
135
Button14Transp = 1.0f;
136
LastButton14UpdateTime = 0.0f;
137
LastMenuUpdateTime = 0.0f;
138
MenuContentTransp = 0.0f;
141
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
142
// иним камеру, всегда до работы со скриптом (!!!)
143
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
144
vw_ResizeScene(45.0f, Setup.fAspectRatioWidth/Setup.fAspectRatioHeight, 1.0f, 2000.0f);
146
vw_SetCameraLocation(VECTOR3D(-50,30,-50));
147
vw_SetCameraMoveAroundPoint(VECTOR3D(0,0,0), 0.0f, VECTOR3D(0.0f, 0.0f, 0.0f));
150
if (Script != 0){delete Script; Script = 0;}
151
Script = new ScriptEngine;
153
if (Setup.MenuScript > 2) Setup.MenuScript = 0;
154
switch (Setup.MenuScript)
156
case 0: Script->RunScript("DATA/SCRIPT/menu1.xml", vw_GetTime()); break;
157
case 1: Script->RunScript("DATA/SCRIPT/menu2.xml", vw_GetTime()); break;
158
case 2: Script->RunScript("DATA/SCRIPT/menu3.xml", vw_GetTime()); break;
160
default: Script->RunScript("DATA/SCRIPT/menu1.xml", vw_GetTime()); break;
164
// немного прокручиваем скрипт
165
float Time1 = vw_GetTime();
166
Script->StartTime = Time1-30;
167
Script->TimeLastOp = Time1-30;
168
for (float i=Time1-30; i<Time1;i+=1.0f)
170
UpdateAllObject3D(i);
173
Script->StartTime = Time1;
174
Script->TimeLastOp = Time1;
178
// активные частицы космоса
180
if (psSpace==0) psSpace = new eParticleSystem;
181
psSpace->ColorStart.r = 0.80f;
182
psSpace->ColorStart.g = 0.80f;
183
psSpace->ColorStart.b = 1.00f;
184
psSpace->ColorEnd.r = 0.70f;
185
psSpace->ColorEnd.g = 0.70f;
186
psSpace->ColorEnd.b = 1.00f;
187
psSpace->AlphaStart = 1.00f;
188
psSpace->AlphaEnd = 0.00f;
189
psSpace->SizeStart = 0.10f;
190
psSpace->SizeVar = 0.05f;
191
psSpace->SizeEnd = 0.30f;
192
psSpace->Speed = 4.00f;
193
psSpace->SpeedVar = 8.00f;
194
psSpace->Theta = 0.00f;
195
psSpace->Life = 10.00f;
196
psSpace->LifeVar = 0.00f;
197
psSpace->CreationType = 1;
198
psSpace->CreationSize = VECTOR3D(2.0f,50.0f,30.0f);
199
psSpace->ParticlesPerSec = 140;
200
psSpace->Texture[0] = vw_FindTextureByName("DATA/GFX/flare3.tga");
201
psSpace->Direction = VECTOR3D(1.0f, 0.0f, 0.0f);
202
psSpace->Resize = 0.1f;
203
psSpace->SetStartLocation(VECTOR3D(-50,10,-20));
205
// немного "прокручиваем", чтобы сразу по появлению было заполнено
206
float Time = psSpace->TimeLastUpdate;
207
for (float i=Time; i<Time+20;i+=1.0f)
211
psSpace->TimeLastUpdate = Time;
214
LastMenuUpdateTime = vw_GetTime();
216
NeedHideMenu = false;
217
LastMenuOnOffUpdateTime = vw_GetTime();
218
MenuBlackTransp = 1.0f;
220
// подстраховка, если не укажем меню, перейдем в основное
221
GameStatus = MAIN_MENU;
223
DrawGameCursor = true;
225
StarsTileUpdateTime = vw_GetTime();
226
StarsTileUpdateTime2 = vw_GetTime();
237
//------------------------------------------------------------------------------------
239
//------------------------------------------------------------------------------------
240
void SetMenu(eGameStatus Menu)
242
Audio_PlaySound2D(3,1.0f);
247
Options_FontNumber = Setup.FontNumber;
252
Options_Width = Setup.Width;
253
Options_Height = Setup.Height;
254
Options_BPP = Setup.BPP;
255
Options_VSync = Setup.VSync;
256
Options_iAspectRatioWidth = Setup.iAspectRatioWidth;
259
case OPTIONS_ADVANCED:
260
Options_TexturesCompression = Setup.TexturesCompression;
261
Options_UseGLSL = Setup.UseGLSL;
262
Options_MSAA = Setup.MSAA;
263
Options_CSAA = Setup.CSAA;
264
Options_TexturesQuality = Setup.TexturesQuality;
265
Options_ShadowMap = Setup.ShadowMap;
269
if (Setup.KeyBoardUp == 0) Setup.KeyBoardUp = SDLK_UP;
270
if (Setup.KeyBoardDown == 0) Setup.KeyBoardDown = SDLK_DOWN;
271
if (Setup.KeyBoardLeft == 0) Setup.KeyBoardLeft = SDLK_LEFT;
272
if (Setup.KeyBoardRight == 0) Setup.KeyBoardRight = SDLK_RIGHT;
273
if (Setup.KeyBoardPrimary == 0) Setup.KeyBoardPrimary = SDLK_LCTRL;
274
if (Setup.KeyBoardSecondary == 0) Setup.KeyBoardSecondary = SDLK_SPACE;
275
if (Setup.MousePrimary == 0) Setup.MousePrimary = SDL_BUTTON_LEFT;
276
if (Setup.MouseSecondary == 0) Setup.MouseSecondary = SDL_BUTTON_RIGHT;
277
if (Setup.JoystickPrimary == -1) Setup.JoystickPrimary = 0;
278
if (Setup.JoystickSecondary == -1) Setup.JoystickSecondary = 1;
282
// копируем исходные данные
283
for (int i=0; i<10; i++)
285
strcpy(GameName[i], Setup.TopScores[i].Name);
286
GameScore[i] = Setup.TopScores[i].Score;
289
// проверяем профайлы
290
for (int j=0; j<5; j++)
291
if (Setup.Profile[j].Used)
293
AddTopScores(Setup.Profile[j].Experience, Setup.Profile[j].Name, true);
298
// ставим нужный лист миссий
301
if (CurrentMission != -1)
302
while (!(StartMission<=CurrentMission && CurrentMission<=EndMission))
310
CreditsCurrentPos = 0.0f;
311
LastCreditsCurrentPosUpdateTime = vw_GetTime();
321
// прячем текущее меню
322
NeedShowMenu = false;
324
LastMenuUpdateTime = vw_GetTime();
332
void SetMenu2(eGameStatus Menu)
351
WorkshopDestroyData();
352
VoiceNeedMoreEnergy = 0;
356
// ставим нужный лист миссий
359
if (CurrentMission != -1)
360
while (!(StartMission<=CurrentMission && CurrentMission<=EndMission))
372
PrevMenu = GameStatus;
375
float Time = vw_GetTime();
376
Button1Transp = 1.0f;
377
LastButton1UpdateTime = Time;
378
Button2Transp = 1.0f;
379
LastButton2UpdateTime = Time;
380
Button3Transp = 1.0f;
381
LastButton3UpdateTime = Time;
382
Button4Transp = 1.0f;
383
LastButton4UpdateTime = Time;
384
Button5Transp = 1.0f;
385
LastButton5UpdateTime = Time;
386
Button6Transp = 1.0f;
387
LastButton6UpdateTime = Time;
388
Button7Transp = 1.0f;
389
LastButton7UpdateTime = Time;
390
Button8Transp = 1.0f;
391
LastButton8UpdateTime = Time;
392
Button9Transp = 1.0f;
393
LastButton9UpdateTime = Time;
394
Button10Transp = 1.0f;
395
LastButton10UpdateTime = Time;
396
Button11Transp = 1.0f;
397
LastButton11UpdateTime = Time;
398
Button12Transp = 1.0f;
399
LastButton12UpdateTime = Time;
400
Button13Transp = 1.0f;
401
LastButton13UpdateTime = Time;
402
Button14Transp = 1.0f;
403
LastButton14UpdateTime = Time;
411
//------------------------------------------------------------------------------------
413
//------------------------------------------------------------------------------------
417
// делаем плавное появление меню
420
MenuContentTransp = 2.4f*(vw_GetTime()-LastMenuUpdateTime);
421
if (MenuContentTransp >= 1.0f)
423
MenuContentTransp = 1.0f;
424
NeedShowMenu = false;
425
LastMenuUpdateTime = vw_GetTime();
427
// выводим подсказку, если нужно
428
if (GameStatus == PROFILE)
429
if (Setup.NeedShowHint[0]) SetCurrentDialogBox(9);
430
if (GameStatus == WORKSHOP)
432
if (CurrentWorkshop == 1)
433
if (Setup.NeedShowHint[1]) SetCurrentDialogBox(10);
434
if (CurrentWorkshop == 2)
435
if (Setup.NeedShowHint[2]) SetCurrentDialogBox(11);
436
if (CurrentWorkshop == 3)
437
if (Setup.NeedShowHint[3]) SetCurrentDialogBox(12);
439
if (GameStatus == MISSION)
441
// проверяем, если в одном из профайлов уже открыли 3 миссии - выводим хинт с пожертвованием
442
bool NeedShowDonate = false;
443
for (int i=0; i<5; i++)
445
if (Setup.Profile[i].Used)
446
if (Setup.Profile[i].ByMissionExperience[2] > 0) NeedShowDonate = true;
450
if (Setup.NeedShowHint[6]) SetCurrentDialogBox(15);
456
// делаем полавное угасание меню
459
MenuContentTransp = 1.0f - 2.4f*(vw_GetTime() - LastMenuUpdateTime);
460
if (MenuContentTransp <= 0.0f)
462
MenuContentTransp = 0.0f;
464
LastMenuUpdateTime = vw_GetTime();
466
NeedHideMenu = false;
471
vw_SetCameraMoveAroundPoint(VECTOR3D(0,0,0), 0.0f, VECTOR3D(0.0f, 0.0f, 0.0f));
477
// всегда первым рисуем скайбокс и "далекое" окружение
484
// рисуем название игры, чтобы звезды и корабли пролетали перед ним
485
vw_Start2DMode(-1,1);
486
// надпись AstroMenace
487
RECT SrcRest, DstRest;
488
SetRect(&SrcRest,0,0,863,128 );
489
int StartX = (Setup.iAspectRatioWidth - 863)/2;
490
SetRect(&DstRest,StartX,10,StartX+863,10+128);
492
if (GameStatus != WORKSHOP &&
493
GameStatus != INFORMATION &&
494
GameStatus != INTERFACE &&
495
GameStatus != OPTIONS &&
496
GameStatus != CONFCONTROL &&
497
GameStatus != OPTIONS_ADVANCED)
499
vw_DrawTransparent(&DstRest, &SrcRest, vw_FindTextureByName("DATA/MENU/astromenace.tga"),
500
true, MenuContentTransp, 0.0f, RI_UL_CORNER, 1.0f, 1.0f, 1.0f);
507
// рисуем все 3д объекты
512
// после полной прорисовки делаем обновление данных
513
UpdateAllObject3D(vw_GetTime());
514
vw_UpdateAllParticleSystems(vw_GetTime());
519
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
520
// работаем со скриптом, пока он есть
521
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
523
if (!Script->Update(vw_GetTime()))
526
delete Script; Script = 0;
533
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
534
// переходим в 2д режим для прорисовки всех 2д частей
535
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
536
vw_Start2DMode(-1,1);
543
case MAIN_MENU: MainMenu(); break;
544
case TOP_SCORES: TopScoresMenu(); break;
545
case INTERFACE: InterfaceMenu(); break;
546
case OPTIONS: OptionsMenu(); break;
547
case OPTIONS_ADVANCED: OptionsAdvMenu(); break;
548
case INFORMATION: InformationMenu(); break;
549
case CREDITS: CreditsMenu(); break;
550
case CONFCONTROL: ConfControlMenu(); break;
551
case PROFILE: ProfileMenu(); break;
552
case DIFFICULTY: DifficultyMenu(); break;
553
case MISSION: MissionMenu(); break;
554
case WORKSHOP: WorkshopMenu(); break;
563
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
564
// последнее - вывод версии и копирайта
565
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
568
vw_DrawFont(6, 740, 0, 0, 1.0f, 1.0f,1.0f,1.0f, 0.99f, "%s %s %s %i", vw_GetText("11_Version"), GAME_VERSION, vw_GetText("11_build"), GAME_BUILD);
571
int CSize = vw_FontSize("%s © 2007-2012, Viewizard", vw_GetText("11_Copyright"));
572
vw_DrawFont(Setup.iAspectRatioWidth-7-CSize, 740, 0, 0, 1.0f, 1.0f,1.0f,1.0f, 0.99f, "%s © 2007-2012, Viewizard", vw_GetText("11_Copyright"));
577
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
578
// завершение прорисовки
579
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
583
// если нужно - рисуем в окошке еще одном
586
case MAIN_MENU: break;
587
case TOP_SCORES: break;
591
case INFORMATION: InformationDrawObject(); break;
600
// черное затемнение, если нужно
603
MenuBlackTransp = 1.0f - 2.4f*(vw_GetTime() - LastMenuOnOffUpdateTime);
604
if (MenuBlackTransp <= 0.0f)
606
MenuBlackTransp = 0.0f;
608
LastMenuOnOffUpdateTime = vw_GetTime();
611
vw_Start2DMode(-1,1);
613
RECT SrcRest, DstRest;
614
SetRect(&SrcRest,0,0,2,2);
615
SetRect(&DstRest,0,0,Setup.iAspectRatioWidth,768);
616
vw_DrawTransparent(&DstRest, &SrcRest, vw_FindTextureByName("DATA/MENU/blackpoint.tga"), true, MenuBlackTransp);
621
// черное затемнение, если нужно
624
MenuBlackTransp = 2.4f*(vw_GetTime() - LastMenuOnOffUpdateTime);
625
if (MenuBlackTransp >= 1.0f)
627
MenuBlackTransp = 1.0f;
629
LastMenuOnOffUpdateTime = vw_GetTime();
631
WorkshopDestroyData();
635
vw_Start2DMode(-1,1);
637
RECT SrcRest, DstRest;
638
SetRect(&SrcRest,0,0,2,2);
639
SetRect(&DstRest,0,0,Setup.iAspectRatioWidth,768);
640
vw_DrawTransparent(&DstRest, &SrcRest, vw_FindTextureByName("DATA/MENU/blackpoint.tga"), true, MenuBlackTransp);
658
//------------------------------------------------------------------------------------
659
// прорисовка основного меню
660
//------------------------------------------------------------------------------------
665
int X = (Setup.iAspectRatioWidth - 384)/2;
668
if (DrawButton384(X,Y, vw_GetText("1_START_GAME"), MenuContentTransp, &Button1Transp, &LastButton1UpdateTime))
678
if (DrawButton384(X,Y, vw_GetText("1_TOP_SCORES"), MenuContentTransp, &Button2Transp, &LastButton2UpdateTime)) ComBuffer = TOP_SCORES;
681
if (DrawButton384(X,Y, vw_GetText("1_OPTIONS"), MenuContentTransp, &Button3Transp, &LastButton3UpdateTime)) ComBuffer = OPTIONS;
684
if (DrawButton384(X,Y, vw_GetText("1_INFORMATION"), MenuContentTransp, &Button4Transp, &LastButton4UpdateTime)) ComBuffer = INFORMATION;
687
if (DrawButton384(X,Y, vw_GetText("1_CREDITS"), MenuContentTransp, &Button5Transp, &LastButton5UpdateTime)) ComBuffer = CREDITS;
690
if (DrawButton384(X,Y, vw_GetText("1_QUIT"), MenuContentTransp, &Button6Transp, &LastButton6UpdateTime))SetCurrentDialogBox(0);