This repository has been archived by the owner on Jul 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathFireMadness.pas
1693 lines (1500 loc) · 60.4 KB
/
FireMadness.pas
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{Copyright (C) 2015-2016 Yevhen Loza
This program 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 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.}
Unit FireMadness;
{$IFDEF Windows}{$Apptype GUI}{$ENDIF}
interface
Uses CastleWindow;
var Window:TCastleWindowCustom;
implementation
uses Classes, SysUtils, fgl, CastleLog, {CastleAndroidInternalLog,}
{castle_base,} castleFilesUtils,
CastleGLImages, CastleGlUtils,
castleVectors, castleImages,
CastleKeysMouse, CastleJoysticks,
CastleFreeType, CastleFonts, CastleUnicode, CastleStringUtils,
Game_controls, general_var, Sound_Music, botsdata,
map_manager, Translation, GL_button, MyFont;
const MinWindowWidth=320;
minWindowHeight=240;
type game_context_type=(gameplay_title,gameplay_play);
Current_title_type=(currentTitle_title,currentTitle_prologue,currenttitle_bestiary, currentTitle_credits, currentTitle_mapselect);
TTouchType=(FireTouch,MoveTouch,OtherTouch,CancelTouch);
type TMyTouch=class (TObject)
FingerIndex:integer;
touchType:TTouchType;
LastAction:TTouchType;
LastPlayer:integer;
//x,y:integer;
constructor create(const ThisFingerIndex:integer{const Event: TInputPressRelease});
//procedure update(x1,y1:single);
procedure doMouseFire(const XX,YY:single);
procedure doMouseMove(const XX,YY:single);
procedure doMouseCtrl(const XX,YY:single);
end;
type TMyTouchList = specialize TFPGObjectList<TMyTouch>;
TEventsHandler = class
procedure JoyMove(const Joy: PJoy; const Axis: Byte; const Value: Single);
procedure JoyButtonDown(const Joy: PJoy; const Button: Byte);
end;
{---------------------------}
var TouchArray:TMyTouchList;
startNewGame:boolean;
firstrender:boolean;
Current_game_context:game_context_type=gameplay_title;
//images
wall,pass: TGLimage;
// healthBarHorizontal,emptyBarHorizontal,leftCapHorizontal,RightCapHorizontal:TGlImage;
HealthBarVertical,EmptyBarVertical,TopCapVertical,BottomCapVertical:TGlImage;
imgControl,imgControlBackground:TGLImage;
imgControlsFire,imgControlsMove:array[0..3] of TGLImage;
FIWIhealthempty,FIWIhealthfull:TGlImage;
imgPause:TGLimage;
//GUI
TitleBackground:TGLIMage;
BlackScreenImg,flamesTextImage:TGLImage;
BlackScreenIntensity:integer;{0..100}
CGE_icon:TGLImage;
Screen_fadeOut,Screen_fadeIn:boolean;
ShowBestiary:integer=0;
ShowPrologue:integer=0;
CurrentTitleDisplay:Current_Title_type=currentTitle_title;
Story_stage:integer=0;
Story_rollback:integer;
VictoryTimer:TDateTime;
buttons:array of TGLButton;
buttonIMg:TGLImage;
MouseMenuPress:boolean=false;
UserPortraits:Array[0..3] of TGLImage;
Player1Portrait:integer=0;
Player2Portrait:integer=2;
TitleReady:boolean;
RescaleWindow:boolean;
LeftInterface:integer=0;
RightInterface:integer=32;
LargeInterfaceSize:integer=128;
//fonts
BoldFont,NormalFont: TTextureFont;
{$R+}{$Q+}
procedure NextStoryStage(setStoryStage:integer=-1); forward;
{------------------------------------------------------------------------------------}
{====================================================================================}
{------------------------------------------------------------------------------------}
constructor TMyTouch.create(const ThisFingerIndex:integer{const Event: TInputPressRelease});
begin
FingerIndex:=ThisFingerIndex;
LastPlayer:=-1;
LastAction:=CancelTouch;
{x:=round(event.position[0]);
y:=round(event.position[1]);}
end;
{procedure TMyTouch.update(x1,y1:single);
begin
x:=round(x1);
y:=round(y1);
end; }
{----------------------------------------}
const maxBlackIntensity=120;
BlackTransparency=0.90;
var blackPhase:integer=0;
procedure doBlackScreen(myAlpha:integer);
var MyShade:TVector4Single;
blackPhaseScaled:integer;
begin
MyShade[0]:=1;
MyShade[1]:=1;
MyShade[2]:=1;
MyShade[3]:=BlackTransparency*(MyAlpha+10*sin(2*Pi*blackPhase/BlackScreenImg.width))/(maxBlackIntensity+10);
if random<0.9 then inc(blackPhase);
if blackPhase>blackScreenImg.width then blackPhase:=0;
BlackScreenImg.Color:=MyShade;
blackPhaseScaled:=round(blackPhase*window.width/blackScreenImg.width);
blackScreenImg.Draw(0,0,blackPhaseScaled,window.height,
BlackScreenImg.width-blackPhase,0,blackPhase,blackScreenImg.height);
blackScreenImg.Draw(blackPhaseScaled,0,window.width-blackPhaseScaled,window.height,
0,0,BlackScreenImg.width-blackPhase,blackScreenImg.height);
{ blackScreenImg.Draw(0,0,blackPhaseScaled,window.height,0,0,blackPhase,blackScreenImg.height);
blackScreenImg.Draw(blackPhaseScaled,0,window.width-blackPhaseScaled,window.height,blackPhase,0,BlackScreenImg.width-blackPhase,blackScreenImg.height);}
end;
procedure StartGame(MapIt:TMapType);
var i:integer;
begin
map:=MapIt;
Current_Game_context:=gameplay_play;
startNewGame:=true;
//stop fire and movement if there were any before
for i:=low(PlayerControls) to high(PlayerControls) do PlayerControls[i].StopControls;
end;
{========================= menu controls ====================================}
procedure MenuKeyRelease(Container: TUIContainer; const Event: TInputPressRelease);
var i:integer;
begin
if (Event.EventType = itMouseButton) and (mouseMenuPress) then begin
for i:=low(buttons) to high(buttons) do if buttons[i]<>nil then buttons[i].checkClick(round(event.Position[0]),round(event.position[1]));
end;
end;
procedure MenuKeyPress(Container: TUIContainer; const Event: TInputPressRelease);
begin
case event.key of
k_1:StartGame(map_bedRoom);
k_2:StartGame(map_LivingRoom);
k_3:StartGame(map_cellar);
k_4:StartGame(map_kitchen);
k_5:StartGame(map_FiWi);
k_6:StartGame(map_test);
k_7:StartGame(map_Crossfire);
k_9:NextStoryStage(1);
k_f5:difficultyLevel:=Singleplayer_easy;
k_f6:difficultyLevel:=Singleplayer_normal;
k_f7:difficultyLevel:=Singleplayer_hard;
k_f8:difficultyLevel:=Singleplayer_insane;
k_none:if (Event.EventType = itMouseButton) then MouseMenuPress:=true;
end;
end;
procedure HideAllButtons;
var i:integer;
begin
for i:=low(buttons) to high(buttons) do if buttons[i]<>nil then buttons[i].hidden:=true;
end;
procedure ShowMainButtons;
var i:integer;
begin
HideAllButtons;
buttons[0].hidden:=false;
buttons[3].hidden:=false;
for i:=14 to 17 do begin
buttons[i].Alpha:=0.4;
buttons[i].hidden:=false;
end;
case CurrentDifficultyLevel of
difficulty_easy: buttons[14].Alpha:=0.9;
difficulty_normal: buttons[15].Alpha:=0.9;
difficulty_hard: buttons[16].Alpha:=0.9;
difficulty_insane: buttons[17].Alpha:=0.9;
end;
end;
Procedure ShowTitleScreenButtons;
var i:integer;
begin
ShowMainButtons;
for i:=0 to 22 do if buttons[i]<>nil then buttons[i].hidden:=false;
//player 1 portraits
if Player1Portrait=0 then buttons[8].Alpha:=0.9 else buttons[8].Alpha:=0.4;
if Player1Portrait=1 then buttons[9].Alpha:=0.9 else buttons[9].Alpha:=0.4;
//player 2 and portrait
if Player2Active then begin
buttons[5].Alpha:=0.9;
if Player2Portrait=2 then buttons[6].Alpha:=0.9 else buttons[6].Alpha:=0.4;
if Player2Portrait=3 then buttons[7].Alpha:=0.9 else buttons[7].Alpha:=0.4;
buttons[12].Alpha:=0.9;
buttons[13].Alpha:=0.9;
end else begin
buttons[5].Alpha:=0.4;
buttons[6].Alpha:=0.4;
buttons[7].Alpha:=0.4;
buttons[12].Alpha:=0.4;
buttons[13].Alpha:=0.4;
end;
buttons[10].image:=GetControlImage(playercontrols[0].FireStyle);
buttons[11].image:=GetControlImage(playercontrols[0].MoveStyle);
buttons[12].image:=GetControlImage(playercontrols[1].FireStyle);
buttons[13].image:=GetControlImage(playercontrols[1].MoveStyle);
for i:=18 to 20 do buttons[i].Alpha:=0.4;
case CurrentLanguage of
Language_English: buttons[18].Alpha:=0.9;
Language_Russian: buttons[19].Alpha:=0.9;
Language_Ukrainian: buttons[20].Alpha:=0.9;
end;
end;
procedure ShowMapSelectionButtons;
var i:integer;
begin
ShowMainButtons;
for i:=23 to 32 do if buttons[i]<>nil then
if buttons[i].ClickMe<>nil then buttons[i].hidden:=false;
end;
procedure ReturnToTitle;
begin
Screen_fadein:=true;
currentTitleDisplay:=currentTitle_title;
MouseMenuPress:=false;
window.OnPress:=@MenuKeyPress;
HideAllButtons;
end;
procedure SimpleKeyOfReturn(Container: TUIContainer; const Event: TInputPressRelease);
begin
ReturnToTitle;
end;
procedure SimpleKeyOfContinue(Container: TUIContainer; const Event: TInputPressRelease);
begin
NextStoryStage;
end;
{------------------------------------------------------------------------}
const startY=0;
normalFontSize=16;
boldFontSize=18;
FontScaleCoefficient=0.6;
var tmpScale:integer;
procedure StoryButtonClick;
begin
HideAllButtons;
NextStoryStage(1);
end;
procedure CreditsButtonClick;
begin
HideAllButtons;
CurrentTitleDisplay:=CurrentTitle_credits;
screen_fadeout:=true;
end;
procedure ExitButtonClick;
begin
Window.close;
end;
procedure DoShowMainTitle;
var scaledY:integer;
i:integer;
begin
Screen_fadeOut:=false;
Screen_fadein:=true;
ScaledY:=round(Window.height*FlamesTextImage.height/FlamesTextImage.width);
flamesTextImage.Draw(20,Window.height-ScaledY,window.width-40,scaledY);
if CurrentTitleDisplay= currentTitle_mapselect
then ShowMapSelectionButtons
else ShowTitleScreenButtons;
for i:=low(buttons) to high(buttons) do if buttons[i]<>nil then buttons[i].drawMe;
end;
procedure doShowCredits;
var s:string;
x,y:integer;
begin
Screen_fadeOut:=true;
x:=10;
Y:=Window.height-10-boldFontSize;
BoldFont.print(window.width div 2 - 100,Y,Vector4Single(1,1,1,1), txt[61]);
Y-=boldFontSize+30;
BoldFont.print(x,Y,Vector4Single(0.9,0.9,0.9,1),txt[53]);
Y-=BoldFontSize*2;
CGE_icon.Draw(x,Y-64+10,64,64);
s:=txt[49]+slinebreak+txt[50]+slinebreak+txt[51]+slinebreak+txt[52];
Y-=NormalFontSize*NormalFont.PrintBrokenString(x+64+10,Y,Vector4Single(0.9,0.9,0.9,1),s,(window.width-X)-10,true,1);
Y-=NormalFontSize;
NormalFont.Print(x,y,Vector4Single(0.9,0.9,0.9,1),txt[93]);
Y-=NormalFontSize*3;
NormalFont.Print(x,y,Vector4Single(0.9,0.9,0.9,1),txt[54]);
Y-=NormalFontSize*2;
NormalFont.Print(x,y,Vector4Single(0.9,0.9,0.9,1),txt[55]);
Y-=NormalFontSize*2;
NormalFont.Print(x,y,Vector4Single(0.9,0.9,0.9,1),txt[56]);
Y-=NormalFontSize;
NormalFont.Print(x,y,Vector4Single(0.9,0.9,0.9,1),txt[57]);
Y-=NormalFontSize;
NormalFont.Print(x,y,Vector4Single(0.9,0.9,0.9,1),txt[58]);
Y-=NormalFontSize*2;
NormalFont.Print(x,y,Vector4Single(0.9,0.9,0.9,1),txt[59]);
Y-=NormalFontSize*2;
NormalFont.Print(x,y,Vector4Single(0.9,0.9,0.9,1),txt[60]);
NormalFont.print(Window.width-round(FontScaleCoefficient*UTF8length(txt[63])*NormalFontSize),10,Vector4Single(0.9,0.9,0.9,1),txt[63]);
window.OnPress:=@SimpleKeyOfReturn;
end;
procedure doShowPrologue(PrologueRecord:integer);
var txt_index:integer;
Y,X:integer;
begin
HideAllButtons;
if music_context<>music_TitleScreen then begin
music_context:=music_TitleScreen;
if not isMusicCrossfade then doLoadNewMusic;
end;
Story_rollback:=Story_stage;
CurrentTitleDisplay:=currentTitle_prologue;
ShowPrologue:=PrologueRecord;
Screen_fadeOut:=true;
Y:=window.height-startY-10-2*BoldFontSize;
X:=10+30*4+20;
UserPortraits[Player1Portrait].Draw(10,Y-10-40*4,30*4,40*4);
case PrologueRecord of
1:txt_index:=1;
2:txt_index:=3;
3:txt_index:=5;
4:txt_index:=7;
5:txt_index:=9;
6:txt_index:=11;
7:txt_index:=13;
end;
boldFont.Print(x+(Window.width-X) div 4,Y,Vector4Single(1,1,1,1),txt[txt_index]);
try NormalFont.PrintBrokenString(x,Y-50,Vector4Single(0.9,0.9,0.9,1),txt[txt_index+1],(window.width-X)-10,true,1);
finally end;
NormalFont.print(Window.width-round(FontScaleCoefficient*UTF8length(txt[62])*NormalFontSize),10,Vector4Single(0.9,0.9,0.9,1),txt[62]);
if (player2active) and (PrologueRecord>1) then begin
case PrologueRecord of
2:txt_index:=71;
3:txt_index:=72;
4:txt_index:=73;
5:txt_index:=74;
6:txt_index:=75;
7:txt_index:=76;
end;
UserPortraits[Player2Portrait].Draw(10,Y-10-40*4-40*4-40,30*4,40*4);
NormalFont.Print(x,Y-10-40*4-40-50,Vector4Single(0.9,0.9,0.9,1),txt[txt_index]);
end;
end;
function doShowBotInfo(botType:TBotType;y:integer):integer;
var txt_index:integer;
t_x,t_y:integer;
y_text:integer;
begin
BotsImg[bottype].Draw(10,y,tmpscale,tmpscale);
case bottype of
bot1 :txt_index:=15;
bot2 :txt_index:=17;
bot3 :txt_index:=19;
botdisabler :txt_index:=21;
heavybot :txt_index:=23;
botautohealer :txt_index:=25;
botshielder :txt_index:=27;
bothealer :txt_index:=29;
botteleporter :txt_index:=31;
botBossCrossFire :txt_index:=33;
botBossMiner :txt_index:=35;
botMine :txt_index:=37;
botBossCarrier :txt_index:=39;
botfighter :txt_index:=41;
botFIWI :txt_index:=43;
botplayer1 :txt_index:=45;
botplayer2 :txt_index:=47;
end;
t_x:=tmpscale+10+10;
t_y:=y+tmpscale-BoldFontSize;
BoldFont.print(t_x,t_y,Vector4Single(1,1,1,1),txt[txt_index]);
try y_Text:=BoldFontSize+20+NormalFontSize*NormalFont.PrintBrokenString(t_x,t_y-BoldFontSize,Vector4Single(0.9,0.9,0.9,1),txt[txt_index+1],window.width-10-t_x,true,1);
finally end;
if y_text<tmpscale+10 then result:=tmpscale+10 else result:=y_text;
end;
procedure doShowBestiary(BestiaryRecord:integer);
var new_y:integer;
begin
HideAllButtons;
if music_context<>music_TitleScreen then begin
music_context:=music_TitleScreen;
if not isMusicCrossfade then doLoadNewMusic;
end;
CurrentTitleDisplay:=currenttitle_bestiary;
ShowBestiary:=BestiaryRecord;
Screen_fadeOut:=true;
if player2Active then tmpScale:= (window.height-20) div 6 -10 else
tmpScale:= (window.height-20) div 5 -10;
new_y:=window.height-startY-10-tmpscale;
case BestiaryRecord of
1: begin
new_y-=doShowBotInfo(bot1,new_y);
new_y-=doShowBotInfo(bot2,new_y);
new_y-=doShowBotInfo(bot3,new_y);
new_y-=doShowBotInfo(botdisabler,new_y);
new_y-=doShowBotInfo(botplayer1,new_y);
if player2active then
new_y-=doShowBotInfo(botplayer2,new_y);
end;
2: begin
new_y-=doShowBotInfo(heavybot,new_y);
new_y-=doShowBotInfo(botteleporter,new_y);
new_y-=doShowBotInfo(botbosscrossfire,new_y);
end;
3: begin
new_y-=doShowBotInfo(botshielder,new_y);
new_y-=doShowBotInfo(botautohealer,new_y);
new_y-=doShowBotInfo(botbossminer,new_y);
new_y-=doShowBotInfo(botmine,new_y);
end;
4: begin
new_y-=doShowBotInfo(bothealer,new_y);
new_y-=doShowBotInfo(botbosscarrier,new_y);
new_y-=doShowBotInfo(botfighter,new_y);
end;
5: begin
new_y-=doShowBotInfo(botfiwi,new_y);
end;
end;
NormalFont.print(Window.width-round(FontScaleCoefficient*UTF8length(txt[62])*NormalFontSize),10,Vector4Single(0.9,0.9,0.9,1),txt[62]);
end;
{===========================================================}
procedure NextStoryStage(setStoryStage:integer=-1);
begin
Current_game_context:=gameplay_title;
window.OnPress:=@SimpleKeyOfContinue;
if setStoryStage>0 then Story_stage:=SetStoryStage else inc(Story_stage);
case Story_stage of
1: doShowPrologue(1);
2: doShowPrologue(2);
3: doShowBestiary(1);
4: StartGame(map_bedroom);
5: doShowPrologue(3);
6: doShowBestiary(2);
7: StartGame(map_LivingRoom);
8: doShowPrologue(4);
9: doShowBestiary(3);
10: StartGame(map_Cellar);
11: doShowPrologue(5);
12: doShowBestiary(4);
13: StartGame(map_Kitchen);
14: doShowPrologue(6);
15: doShowBestiary(5);
16: StartGame(map_FIWI);
17: doShowPrologue(7);
else begin CurrentTitleDisplay:=CurrentTitle_title;Current_game_context:=gameplay_title; window.OnPress:=@MenuKeyPress; window.OnRelease:=@MenuKeyRelease end;
end;
end;
{---------------------------------------------------------------------------}
procedure SetPlayerPortrait0;
begin
Player1Portrait:=0;
end;
procedure SetPlayerPortrait1;
begin
Player1Portrait:=1;
end;
procedure SetPlayerPortrait2;
begin
Player2Portrait:=2;
end;
procedure SetPlayerPortrait3;
begin
Player2Portrait:=3;
end;
procedure TogglePlayer1;
begin
largeInterfaceSize:=2*window.height div 5;
case CurrentDifficultyLevel of
difficulty_easy: difficultyLevel:=Singleplayer_easy;
difficulty_normal: difficultyLevel:=Singleplayer_normal;
difficulty_hard: difficultyLevel:=Singleplayer_hard;
difficulty_insane: difficultyLevel:=Singleplayer_insane;
end;
Player2Active:=false;
{$ifdef Android}
RightInterface:=largeInterfaceSize+32;
{$else}
RightInterface:=32;
{$endif}
LeftInterface:=0;
PlayerControls[0]:=PlayerControls[2];
end;
procedure TogglePlayer2;
begin
if Player2Active then begin
TogglePlayer1
end else begin
DifficultyLevel.EnemyFirePowerMultiplier*=hotSeatDifficultyMultiplier;
DifficultyLevel.EnemyHealthMultiplier*=2;
DifficultyLevel.EnemySpawnRateMultiplier*=hotSeatDifficultyMultiplier;
DifficultyLevel.simultaneous_active+=1;
Player2Active:=true;
{$ifdef Android}
LeftInterface:=largeInterfaceSize+32;
RightInterface:=largeInterfaceSize+32;
{$else}
LeftInterface:=32;
RightInterface:=32;
{$endif}
PlayerControls[0]:=PlayerControls[3];
end;
end;
procedure SetDifficultyLevelEasy;
begin
difficultyLevel:=Singleplayer_easy;
currentDifficultyLevel:=DifficultyLevel.DifficultyStyle;
end;
procedure SetDifficultyLevelNormal;
begin
difficultyLevel:=Singleplayer_Normal;
currentDifficultyLevel:=DifficultyLevel.DifficultyStyle;
end;
procedure SetDifficultyLevelHard;
begin
difficultyLevel:=Singleplayer_Hard;
currentDifficultyLevel:=DifficultyLevel.DifficultyStyle;
end;
procedure SetDifficultyLevelInsane;
begin
difficultyLevel:=Singleplayer_Insane;
currentDifficultyLevel:=DifficultyLevel.DifficultyStyle;
end;
procedure ResizeButtons;
var StartY,EndY,spanY,startX,EndX,SpanX:integer;
Span74,spanL:integer;
NewFontSize:integer;
i:integer;
begin
NewFontSize:=round(30*Window.width/800);
for i:=low(buttons) to high(buttons) do if buttons[i]<>nil then
if buttons[i].fontSize<>newFontSize then buttons[i].setFontSize(newFontSize);
startY:=10;
EndY:= Window.height-round(Window.height*FlamesTextImage.height/FlamesTextImage.width)-10;
SpanY:=(EndY-StartY) div 6-10;
startX:=10;
EndX:=window.Width-10;
SpanX:=(EndX-StartX) div 10-10;
if SpanY<30 then begin inc(SpanY,8-SpanY div 4); inc(SpanX,8-SpanY div 4) end;
buttons[0].ResizeMe(StartX,EndY-SpanY,5*SpanX,spanY);
buttons[1].ResizeMe(StartX,StartY,3*SpanX,spanY);
buttons[2].ResizeMe(endX-SpanX*3,StartY,3*SpanX,spanY);
buttons[3].ResizeMe(endX-SpanX*5,EndY-SpanY,5*SpanX,spanY);
//Player1
buttons[4].ResizeMe(StartX,EndY-4*SpanY,3*SpanX,2*spanY);
buttons[8].ResizeMe(StartX+3*spanX,EndY-4*SpanY,2*SpanX,2*spanY);
buttons[9].ResizeMe(StartX+5*spanX,EndY-4*SpanY,2*SpanX,2*spanY);
buttons[10].ResizeMe(StartX+7*spanX,EndY-4*SpanY,2*SpanX,2*spanY);
buttons[11].ResizeMe(StartX+9*spanX,EndY-4*SpanY,2*SpanX,2*spanY);
//Player2
buttons[5].ResizeMe(StartX,EndY-6*SpanY,3*SpanX,2*spanY);
buttons[6].ResizeMe(StartX+3*spanX,EndY-6*SpanY,2*SpanX,2*spanY);
buttons[7].ResizeMe(StartX+5*spanX,EndY-6*SpanY,2*SpanX,2*spanY);
buttons[12].ResizeMe(StartX+7*spanX,EndY-6*SpanY,2*SpanX,2*spanY);
buttons[13].ResizeMe(StartX+9*spanX,EndY-6*SpanY,2*SpanX,2*spanY);
//difficulty
Span74:=round(SpanX*7/4);
buttons[14].ResizeMe(StartX ,EndY-SpanY*2,Span74,spanY);
buttons[15].ResizeMe(StartX+Span74 ,EndY-SpanY*2,Span74,spanY);
buttons[16].ResizeMe(StartX+Span74*2,EndY-SpanY*2,Span74,spanY);
buttons[17].ResizeMe(StartX+Span74*3,EndY-SpanY*2,Span74,spanY);
for i:=14 to 17 do buttons[i].setFontSize(2*NewFontSize div 3);
//language
spanL:=3*SpanX div 2;
buttons[18].ResizeMe(StartX+(EndX-StartX-spanL) div 2-SpanL,StartY,SpanL,spanY div 2);
buttons[19].ResizeMe(StartX+(EndX-StartX-spanL) div 2,StartY,SpanL,spanY div 2);
buttons[20].ResizeMe(StartX+(EndX-StartX-spanL) div 2+SpanL,StartY,SpanL,spanY div 2);
for i:=18 to 20 do buttons[i].setFontSize(NewFontSize div 2);
buttons[21].ResizeMe(StartX+7*spanX,EndY-4*SpanY+9*SpanY div 5,2*SpanX,spanY div 2);
buttons[22].ResizeMe(StartX+9*spanX,EndY-4*SpanY+9*SpanY div 5,2*SpanX,spanY div 2);
for i:=21 to 22 do buttons[i].setFontSize(NewFontSize div 2);
//maps
for i:=0 to 4 do buttons[23+i].resizeMe(StartX,EndY-SpanY*(i+3),5*SpanX,spanY);
for i:=0 to 4 do buttons[28+i].resizeMe(EndX-5*SpanX,EndY-SpanY*(i+3),5*SpanX,spanY);
end;
procedure MakeButtonsText;
var i:integer;
begin
buttons[0].caption:=txt[68]; //play story
buttons[1].caption:=txt[69]; //show credits
buttons[2].caption:=txt[70]; //exit
buttons[3].caption:=txt[77]; //custom map
//Players
buttons[4].caption:=txt[45];
buttons[5].caption:=txt[47];
//Difficulty
buttons[14].Caption:=txt[64];
buttons[15].Caption:=txt[65];
buttons[16].Caption:=txt[66];
buttons[17].Caption:=txt[67];
//language
buttons[18].Caption:=txt[78];
buttons[19].Caption:=txt[79];
buttons[20].Caption:=txt[80];
//move&fire
buttons[21].frame:=nil;
buttons[21].caption:=txt[81];
buttons[22].frame:=nil;
buttons[22].caption:=txt[82];
//custom map titles
for i:=23 to 32 do buttons[i].caption:=txt[i+83-23];
end;
procedure SetTranslationEnglish;
begin
loadTranslation(Language_English);
MakeButtonsText;
end;
Procedure SetTranslationRussian;
begin
loadTranslation(Language_Russian);
MakeButtonsText;
end;
Procedure SetTranslationUkrainian;
begin
loadTranslation(Language_Ukrainian);
MakeButtonsText;
end;
Procedure playMap_1;
begin
NextStoryStage(1)
end;
Procedure playMap_2;
begin
NextStoryStage(5)
end;
Procedure playMap_3;
begin
NextStoryStage(8)
end;
Procedure playMap_4;
begin
NextStoryStage(11)
end;
Procedure playMap_5;
begin
NextStoryStage(14)
end;
Procedure PlayMap_crossfire;
begin
StartGame(map_Crossfire);
end;
Procedure playMap_narrow;
begin
StartGame(map_NarrowCellar)
end;
procedure CustomMap;
begin
currentTitleDisplay:=CurrentTitle_mapSelect;
end;
procedure ClickToTitle;
begin
currentTitleDisplay:=CurrentTitle_title;
end;
procedure MakeButtons;
var i:integer;
begin
//create buttons
setLength(buttons,32+1);
for i:=0 to 32 do begin
buttons[i]:=TGLButton.create;
buttons[i].Frame:=ButtonImg;
end;
SetTranslationEnglish;
buttons[0].ClickMe:=@StoryButtonClick;
buttons[1].ClickMe:=@CreditsButtonClick;
buttons[2].ClickMe:=@ExitButtonClick;
buttons[3].ClickMe:=@CustomMap;
//player 1
buttons[4].ClickMe:=@TogglePlayer1;
buttons[8].Image:=UserPortraits[0];
buttons[8].content:=button_img;
buttons[8].ClickMe:=@SetPlayerPortrait0;
buttons[9].Image:=UserPortraits[1];
buttons[9].content:=button_img;
buttons[9].ClickMe:=@SetPlayerPortrait1;
buttons[10].content:=button_img;
buttons[10].ClickMe:=@cyclePlayer1Fire;
buttons[11].content:=button_img;
buttons[11].ClickMe:=@cyclePlayer1Move;
//player 2
buttons[5].ClickMe:=@TogglePlayer2;
buttons[6].Image:=UserPortraits[2];
buttons[6].content:=button_img;
buttons[6].ClickMe:=@SetPlayerPortrait2;
buttons[7].Image:=UserPortraits[3];
buttons[7].content:=button_img;
buttons[7].ClickMe:=@SetPlayerPortrait3;
buttons[12].content:=button_img;
buttons[12].ClickMe:=@CyclePlayer2Fire;
buttons[13].content:=button_img;
buttons[13].ClickMe:=@CyclePlayer2Move;
//difficulty
buttons[14].clickMe:=@SetDifficultyLevelEasy;
buttons[15].clickMe:=@SetDifficultyLevelNormal;
buttons[16].clickMe:=@SetDifficultyLevelHard;
buttons[17].clickMe:=@SetDifficultyLevelInsane;
//language
buttons[18].clickMe:=@SetTranslationEnglish;
buttons[19].clickMe:=@SetTranslationRussian;
buttons[20].clickMe:=@SetTranslationUkrainian;
//CustomMap
buttons[23].clickMe:=@playMap_1;
buttons[24].clickMe:=@playMap_2;
buttons[25].clickMe:=@playMap_3;
buttons[26].clickMe:=@playMap_4;
buttons[27].clickMe:=@playMap_5;
buttons[28].clickMe:=@PlayMap_crossfire;
buttons[29].clickMe:=@playMap_narrow;
buttons[30].ClickMe:=nil;
buttons[31].ClickMe:=nil;
buttons[32].clickMe:=@ClickToTitle;
ResizeButtons;
end;
procedure MakeTitleScreen;
begin
showBestiary:=0;
ShowPrologue:=0;
TitleBackground:=TGLImage.Create(ApplicationData(TitlescreenFolder+'FireMadness.jpg'),true);
BlackScreenImg:=TGLImage.Create(ApplicationData(TitlescreenFolder+'Black.jpg'),true);
BlackScreenImg.Alpha:=acFullRange;
CGE_icon:=TGLImage.Create(ApplicationData(TitlescreenFolder+'castle_game_engine_icon_transparent.png'),true);
FlamesTextImage:=TGLImage.Create(ApplicationData(TitlescreenFolder+'flames.png'),true);
buttonIMg:=TGLImage.create(ApplicationData(TitlescreenFolder+'button.png'),true);
makeButtons;
TitleReady:=false;
end;
procedure ShowTitle;
begin
music_context:=music_TitleScreen;
// CurrentTitleDisplay:=currentTitle_title;
ShowTitleScreenButtons;
BlackScreenIntensity:=0;
doLoadNewMusic;
TitleReady:=true;
mouseMenuPress:=false;
end;
procedure hideTitle;
begin
//Window.Controls.remove(label1);
TitleReady:=false;
end;
{------------------------------------------------------------------------------------}
{====================================================================================}
{------------------------------------------------------------------------------------}
procedure TMyTouch.doMouseFire(const XX,YY:single);
var dx,dy:single;
PlayerBot:TPlayerBot;
begin
PlayerBot:=bots[0] as TPlayerBot;
dx:=(XX-GameScreenStartX)-(PlayerBot.x+0.5)*scale;
dy:=(YY-GameScreenStartY)-(PlayerBot.y+0.5)*scale;
if abs(dx)>abs(dy) then begin
if (dx<0) then PlayerBot.PlayerFire(-1,0) else PlayerBot.PlayerFire(+1,0);
end else begin
if (dy<0) then PlayerBot.PlayerFire(0,-1) else PlayerBot.PlayerFire(0,+1);
end;
end;
procedure TMyTouch.doMouseMove(const XX,YY:single);
var dx,dy:single;
PlayerBot:TPlayerBot;
begin
PlayerBot:=bots[0] as TPlayerBot;
dx:=(XX-GameScreenStartX)-(PlayerBot.x+0.5)*scale;
dy:=(YY-GameScreenStartY)-(PlayerBot.y+0.5)*scale;
if abs(dx)>abs(dy) then begin
if (dx<0) then PlayerBot.PlayerMove(-1,0) else PlayerBot.PlayerMove(+1,0);
end else begin
if (dy<0) then PlayerBot.PlayerMove(0,-1) else PlayerBot.PlayerMove(0,+1);
end;
end;
procedure TMyTouch.doMouseCtrl(const XX,YY:single);
type TouchControlStyle=(controlmove,controlfire);
var PlayerBot:TPlayerBot;
dx,dy:integer;
mirrorControl:boolean;
ThisControl:TouchControlStyle;
begin
if (XX>GameScreenStartX+largeInterfaceSize) and (XX<GameScreenEndX-largeInterfaceSize) then exit;
if XX>=GameScreenEndX-largeInterfaceSize then begin
if lastPlayer=1 then exit;
PlayerBot:=bots[0] as TPlayerBot;
dx:=round(XX)-(Window.Width-largeInterfaceSize div 2);
MirrorControl:=false;
LastPlayer:=0;
end
else begin
if not Player2Active then exit;
if lastPlayer=0 then exit;
PlayerBot:=bots[1] as TPlayerBot;
dx:=round(XX)-largeInterfaceSize div 2;
MirrorControl:=true;
LastPlayer:=1;
end;
if (YY<(GameScreenEndY-GameScreenStartY)/2) {and (YY>=GameScreenStartY)} then begin
dy:=round(YY)-largeInterfaceSize div 2;
if MirrorControl then ThisControl:=controlmove else ThisControl:=controlfire;
end else
{if (YY>GameScreenEndY-largeInterfaceSize) and (YY<=GameScreenEndY) then} begin
dy:=round(YY)-(Window.height-largeInterfaceSize div 2);
if MirrorControl then ThisControl:=controlfire else ThisControl:=controlmove;
end;
if ThisControl=controlmove then begin
if LastAction=FireTouch then exit;
LastAction:=MoveTouch;
if abs(dx)>abs(dy) then begin
if (dx<0) then PlayerBot.PlayerMove(-1,0) else PlayerBot.PlayerMove(+1,0);
end else begin
if (dy<0) then PlayerBot.PlayerMove(0,-1) else PlayerBot.PlayerMove(0,+1);
end;
end else begin
if LastAction=MoveTouch then exit;
LastAction:=FireTouch;
if abs(dx)>abs(dy) then begin
if (dx<0) then PlayerBot.PlayerFire(-1,0) else PlayerBot.PlayerFire(+1,0);
end else begin
if (dy<0) then PlayerBot.PlayerFire(0,-1) else PlayerBot.PlayerFire(0,+1);
end;
end;
end;
procedure GameKeyPress(Container: TUIContainer; const Event: TInputPressRelease);
var
PlayerBot:TPlayerBot;
NewEventTouch:TMyTouch;
i:integer;
begin
PauseMode:=false;
if Event.EventType = itMouseButton then begin
NewEventTouch:=TMyTouch.create(event.FingerIndex);
NewEventTouch.touchType:=FireTouch;
for i:=0 to TouchArray.Count-1 do
if TouchArray[i].touchType=FireTouch then NewEventTouch.touchType:=MoveTouch else
if TouchArray[i].touchType=MoveTouch then NewEventTouch.touchType:=CancelTouch;
if (LeftInterface>=largeInterfaceSize) and (event.Position[0]<GameScreenStartX) then begin
newEventTouch.touchType:=OtherTouch;
end else
if (RightInterface>=largeInterfaceSize) and (event.Position[0]>GameScreenEndX) then begin
newEventTouch.touchType:=OtherTouch;
end;
if NewEventTouch.touchType=FireTouch then NewEventTouch.doMouseFire(event.Position[0],event.Position[1]) else
if NewEventTouch.touchType=MoveTouch then NewEventTouch.doMouseMove(event.Position[0],event.Position[1]) else
if NewEventTouch.touchType=OtherTouch then NewEventTouch.doMouseCtrl(event.Position[0],event.Position[1]);
if NewEventTouch.touchType<>CancelTouch then
TouchArray.Add(NewEventTouch);
end else begin
if event.key=K_Pause then pauseMode:=not PauseMode;
if event.key=K_f10 then begin Current_game_context:=gameplay_title; CurrentTitleDisplay:=currentTitle_title; window.OnPress:=@MenuKeyPress; window.OnRelease:=@MenuKeyRelease end;
// if event.key=K_f9 then for i:= low(bots) to high(bots) do if bots[i] is THostileBot then bots[i].hitme(bots[i].maxhp);
if event.key=k_f5 then doLoadNewMusic;
for i:=0 to nplayers-1 do begin
PlayerBot:=bots[i] as TPlayerBot;
if not firstrender then begin
{ mouseFire:=false;}
if PlayerBot.hp>0 then with PlayerControls[i] do begin
if event.key=MoveKeys.up then begin PlayerBot.PlayerMove(0,+1); lastMoveKeyPress:=Event.Key; end;
if event.key=MoveKeys.down then begin PlayerBot.PlayerMove(0,-1); lastMoveKeyPress:=Event.Key; end;
if event.key=MoveKeys.right then begin PlayerBot.PlayerMove(+1,0); lastMoveKeyPress:=Event.Key; end;
if event.key=MoveKeys.left then begin PlayerBot.PlayerMove(-1,0); lastMoveKeyPress:=Event.Key; end;
if event.key=FireKeys.up then begin PlayerBot.PlayerFire(0,+1); lastFireKeyPress:=Event.Key; end;
if event.key=FireKeys.down then begin PlayerBot.PlayerFire(0,-1); lastFireKeyPress:=Event.Key; end;
if event.key=FireKeys.right then begin PlayerBot.PlayerFire(+1,0); lastFireKeyPress:=Event.Key; end;
if event.key=FireKeys.left then begin PlayerBot.PlayerFire(-1,0); lastFireKeyPress:=Event.Key; end;
end;
end;
end;{for i 0 to nplayers}
end;
end;
procedure GameKeyRelease(Container: TUIContainer; const Event: TInputPressRelease);
var playerBot:TPlayerBot;
i:integer;
begin
if Event.EventType = itMouseButton then begin
if touchArray.count>0 then begin
i:=0;
repeat
if touchArray[i].fingerindex=event.fingerindex then begin
if touchArray[i].touchType=FireTouch then playerControls[0].FirePressed:=false else
if touchArray[i].touchType=MoveTouch then playerControls[0].MovePressed:=false else begin
if TouchArray[i].LastPlayer=0 then begin
if touchArray[i].LastAction=FireTouch then playerControls[0].FirePressed:=false else
if touchArray[i].LastAction=MoveTouch then playerControls[0].MovePressed:=false;
end else begin