-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathProjectF.GameForm.pas
More file actions
3973 lines (3672 loc) · 127 KB
/
ProjectF.GameForm.pas
File metadata and controls
3973 lines (3672 loc) · 127 KB
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
unit ProjectF.GameForm;
interface
uses
System.Classes,
System.DateUtils,
System.Devices,
System.Generics.Collections,
System.ImageList,
System.Notification,
System.SysUtils,
System.IOUtils,
System.Types,
System.UITypes,
System.Variants,
FMX.Ani,
FMX.Controls,
FMX.Controls.Presentation,
FMX.Dialogs,
FMX.Effects,
FMX.Filter.Effects,
FMX.Forms,
FMX.Graphics,
FMX.ImgList,
FMX.Layouts,
FMX.Media,
FMX.Objects,
FMX.Platform,
FMX.StdCtrls,
FMX.Types,
ProjectF.GameUtils.Clipper,
ProjectF.GameUtils.Clipper.PathData,
ProjectF.Types,
ProjectF.PathAnimation,
Skia,
Skia.FMX;
type
TRectangle = class(FMX.Objects.TRectangle)
public
AnimationStep : Single;
Data : Integer;
Direction : Integer;
ImageIndex : Integer;
Kind : Integer;
ImageCount : Integer;
Speed : Single;
ClipperPathDataIndex : Integer;
ImageList : TCustomImageList;
public
procedure FillImage;
procedure NextImage; virtual;
end;
TEatingEffectRectangle = class(TRectangle)
public
procedure NextImage; override;
end;
TGameObjectList = TList<TRectangle>;
TGameForm = class(TForm)
AniAlert : TFloatAnimation;
AniAngryProgress : TColorAnimation;
AniBomb : TFloatAnimation;
AniEffectAngry : TFloatAnimation;
AniFishingLineStep1 : TFloatAnimation;
AniFishingLineStep2 : TFloatAnimation;
AniShieldProgress : TColorAnimation;
AniTorpedo : TFloatAnimation;
Background1 : TRectangle;
Background2 : TRectangle;
Background3 : TRectangle;
Banner : TRectangle;
BannerContainer : TRectangle;
BombEffect : TRippleEffect;
BtnBages : TRectangle;
BtnExit : TRectangle;
BtnGameCompleteFacebook : TRectangle;
BtnGameCompleteHome : TRectangle;
BtnGameCompleteReplay : TRectangle;
BtnGameCompleteTwitter : TRectangle;
BtnGameLeave : TRectangle;
BtnGameLeaveImage : TRectangle;
BtnGamePausedExit : TRectangle;
BtnGamePausedResume : TRectangle;
BtnGameSettingBack : TRectangle;
BtnGameSettingForward : TRectangle;
BtnGameStatsReturn : TRectangle;
BtnPlay : TRectangle;
BtnPopupLeaveNo : TRectangle;
BtnPopupLeaveYes : TRectangle;
BtnSetting : TRectangle;
BtnSettingReturn : TRectangle;
Bubble : TRectangle;
CircleAlert : TCircle;
CircleAngryProgress : TCircle;
CircleShieldProgress : TCircle;
ClamShell : TRectangle;
DarkPigment : TRectangle;
DarkPigment1 : TRectangle;
DarkPigment2 : TRectangle;
DarkPigment3 : TRectangle;
DarkPigmentContainer : TRectangle;
EffectAngry : TGlowEffect;
FishingHook : TRectangle;
FishingLine : TLine;
FloatAnimation1 : TFloatAnimation;
FloatAnimation2 : TFloatAnimation;
FloatAnimation3 : TFloatAnimation;
FloatAnimation4 : TFloatAnimation;
FloatAnimation5 : TFloatAnimation;
FloatAnimation6 : TFloatAnimation;
AniShieldAlert: TFloatAnimation;
AniBestScore: TFloatAnimation;
GameComplete : TRectangle;
GameMenu : TRectangle;
GamePopupLeave : TRectangle;
GamePopupPaused : TRoundRect;
GameSetting : TRectangle;
GameSettingFishPlaceHolder : TRectangle;
GameStats : TRectangle;
GlowEffect1 : TGlowEffect;
GlowEffect2 : TGlowEffect;
GlowEffect3 : TGlowEffect;
GlowEffect4 : TGlowEffect;
IlButtonActive : TImageList;
IlButtonNormal : TImageList;
IlClamShell : TImageList;
IlCoin : TImageList;
IlCuttle : TImageList;
IlEatingEffect : TImageList;
IlFish : TImageList;
IlFishRight : TImageList;
IlJellyFish : TImageList;
IlMainFish : TImageList;
IlShark : TImageList;
Layout : TRectangle;
LblCoinCount : TSkLabel;
LblExclamation : TSkLabel;
LblExit : TSkLabel;
LblFishCount : TSkLabel;
LblGameCompleteCoin : TSkLabel;
LblGameCompleteFishCount : TSkLabel;
LblGameCompleteIcon1 : TRectangle;
LblGameCompleteIcon2 : TRectangle;
LblGameCompleteIcon3 : TRectangle;
LblGameCompletelTitle : TSkLabel;
LblGameCompleteScore : TSkLabel;
LblGameCompleteTime : TSkLabel;
LblGameMenuTitle : TSkLabel;
LblGameScore : TSkLabel;
LblGameScoreSuper : TSkLabel;
LblGameSettingBtnReturn : TSkLabel;
LblGameSettingMusic : TSkLabel;
LblGameSettingSound : TSkLabel;
LblGameSettingTitle : TSkLabel;
LblGameStatsBestScore : TSkLabel;
LblGameStatsCoin : TSkLabel;
LblGameStatsFish : TSkLabel;
LblGameStatsLabel1 : TSkLabel;
LblGameStatsLabel2 : TSkLabel;
LblGameStatsLabel3 : TSkLabel;
LblGameStatsLabel4 : TSkLabel;
LblGameStatsLabel5 : TSkLabel;
LblGameStatsPearl : TSkLabel;
LblGameStatsReturn : TSkLabel;
LblGameStatsShark : TSkLabel;
LblGameStatsTitle : TSkLabel;
LblHealth : TSkLabel;
LblPlay : TSkLabel;
LblPopupLeaveText : TSkLabel;
LblPopupLeaveTitle : TSkLabel;
LblSetting : TSkLabel;
Line1 : TLine;
MpBackgroundMusic : TMediaPlayer;
MpSoundBomb : TMediaPlayer;
MpSoundClick : TMediaPlayer;
MpSoundCoin1 : TMediaPlayer;
MpSoundCoin2 : TMediaPlayer;
MpSoundCoin3 : TMediaPlayer;
MpSoundDie : TMediaPlayer;
MpSoundEating : TMediaPlayer;
MpSoundFishingReel : TMediaPlayer;
MpSoundLevelUp : TMediaPlayer;
MpSoundMagic : TMediaPlayer;
MpSoundPowerUp : TMediaPlayer;
MpSoundReel : TMediaPlayer;
MpSoundShark : TMediaPlayer;
NonVisualControls : TRectangle;
NotificationCenter : TNotificationCenter;
PieAngryProgress : TPie;
PieShieldProgress : TPie;
RectBestScore : TRectangle;
RectGameScore : TRectangle;
RectString1 : TRectangle;
RectString2 : TRectangle;
RectString3 : TRectangle;
RectString4 : TRectangle;
SeaHorse : TRectangle;
ShieldEffect : TCircle;
TheBattleShip : TRectangle;
TheFish : TRectangle;
TheFishImage : TRectangle;
TheFishImageWrapper : TRectangle;
TheFishingShip : TRectangle;
TheShark : TRectangle;
TheTorpedo : TRectangle;
TimerAngry : TTimer;
TimerClamShellCreation : TTimer;
TimerCoinCreatation : TTimer;
TimerDarkPigment : TTimer;
TimerEatingEffect : TTimer;
TimerFishCreation : TTimer;
TimerFisherManCreation : TTimer;
TimerGameSpeed : TTimer;
TimerHealth : TTimer;
TimerJellyOrCuttleFishCreation : TTimer;
TimerMusic : TTimer;
TimerPlayingDurationCounter : TTimer;
TimerSeaHorseCreation : TTimer;
TimerSharkCreation : TTimer;
TimerShield : TTimer;
TimerShipCreation : TTimer;
TimerSmallFishCreation : TTimer;
ToggleMusic : TRectangle;
ToggleSound : TRectangle;
Coral1: TRectangle;
Coral2: TRectangle;
Coral3: TRectangle;
Coral4: TRectangle;
Coral5: TRectangle;
Coral6: TRectangle;
TimerCoralCreation: TTimer;
Coral8: TRectangle;
Coral7: TRectangle;
Coral9: TRectangle;
LayoutWrapper: TLayout;
MpSoundCuttle: TMediaPlayer;
TimerHideSuperDotTip: TTimer;
TimerCollisionProcess: TTimer;
procedure AniAlertFinish(Sender: TObject);
procedure AniBombFinish(Sender: TObject);
procedure AniFishingLineStep1Finish(Sender: TObject);
procedure AniFishingLineStep2Finish(Sender: TObject);
procedure AniTorpedoFinish(Sender: TObject);
procedure AppBecameActive(Sender: TObject);
procedure AppEnteredBackground(Sender: TObject);
procedure AppEventsBecameActive(Sender: TObject);
procedure AppFinishedLaunching(Sender: TObject);
procedure AppWillTerminate(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure LayoutMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
procedure LayoutMouseLeave(Sender: TObject);
procedure LayoutMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Single);
procedure LayoutMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
procedure OnBtnBagesClick(Sender: TObject);
procedure OnGameCompleteButtonClick(Sender: TObject);
procedure OnGameLeaveClick(Sender: TObject);
procedure OnGamePausedButtonClick(Sender: TObject);
procedure OnGameSettingMainFishKindClick(Sender: TObject);
procedure OnLeavePopupButtonClick(Sender: TObject);
procedure OnMenuButtonClick(Sender: TObject);
procedure OnToggleClick(Sender: TObject);
procedure TheFishResize(Sender: TObject);
procedure TimerAngryTimer(Sender: TObject);
procedure TimerClamShellCreationTimer(Sender: TObject);
procedure TimerCoinCreatationTimer(Sender: TObject);
procedure TimerDarkPigmentTimer(Sender: TObject);
procedure TimerEatingEffectTimer(Sender: TObject);
procedure TimerFishCreationTimer(Sender: TObject);
procedure TimerGameSpeedTimer(Sender: TObject);
procedure TimerHealthTimer(Sender: TObject);
procedure TimerJellyOrCuttleFishCreationTimer(Sender: TObject);
procedure TimerMusicTimer(Sender: TObject);
procedure TimerPlayingDurationCounterTimer(Sender: TObject);
procedure TimerSeaHorseCreationTimer(Sender: TObject);
procedure TimerShieldTimer(Sender: TObject);
procedure TimerSmallFishCreationTimer(Sender: TObject);
procedure TimerCoralCreationTimer(Sender: TObject);
procedure TimerHideSuperDotTipTimer(Sender: TObject);
procedure TimerCollisionProcessTimer(Sender: TObject);
private
// Biến lưu trữ trạng thái game
class var FGameState: TGameState;
private
FAppIsActive: Boolean;
// Đối tượng xử lý cá va chạm nhau
FClipper: TClipper;
// Biến lưu trữ loại cá chính
FMainFishImageIndex: Integer;
// Tọa độ của chú cá theo chiều thẳng đứng
FFishVerticalCoordinate: Single;
// Tọa độ nhấn chuột (dùng để di chuyển cá)
FTapPosition: TPointF;
// Đang nhấn chuột
FDragging: Boolean;
// Đang thay đổi kích thước của chú cá
FFishResizing: Boolean;
// Cờ báo hiệu đã thả lưỡi câu cá chưa
FStartFishingLineIsStarted: Boolean;
// Chu kì chuyển động của dãi đất + đá phía trước
FDuration1: Single;
// Chu kì chuyển động của dãi san hô phía sau
FDuration2: Single;
// Bước dịch chuyển của dãi đất + đá phía trước
FStep1: Single;
// Bước dịch chuyển của dãi san hô phía sau
FStep2: Single;
// Bước dịch chuyển của tiền xu
FStep3: Single;
// Sức mạnh siêu nhiên cho cá
FShield: Integer;
// Ngưỡng bật Shield cho cá
FShieldThreshold: Integer;
// Khu vực cho phép con cá di chuyển
FAllowedArea: TRectF;
// Danh sách chứa toàn bộ các con cá
FFishes: TGameObjectList;
// Danh sách cache các cong cá
FCachedFishes: array [0..6, DIRECTION_LEFT..DIRECTION_RIGHT] of TGameObjectList;
// Danh sách chứa các con sứa
FJellyFishes, FCachedJellyFishes: TGameObjectList;
// Danh sách các con mực
FCuttleFishes, FCachedCuttleFishes: TGameObjectList;
// Danh sách hiệu ứng ăn cá
FEatingEffectList: TGameObjectList;
// Danh sách hiệu ứng ăn cá đã cache
FCachedEatingEffectList: TGameObjectList;
// Danh sách các bong bóng
FBubbleList: TGameObjectList;
// Danh sách các bong bóng đã cache
FCachedBubbleList: TGameObjectList;
// Danh sách các đồng xu
FCoins: array [1..9] of TRectangle;
// Danh sách các cây san hô
FCorals: array [0..8] of TRectangle;
// Mảng chứa những con cá nhỏ
FSmallFishes: array [1..10] of TRectangle;
// Mảng chứa những Animation điều khiển cá nhỏ
FSmallFishAnimations: array [1..10] of TPathAnimationFX;
// Mảng chứa dữ liệu cho FSmallFishAnimations
FSmallFishAnimationData: array [1..5] of TPathAnimationFXData;
// Hướng xuất phát của con cá mập
FTheSharkDirection: Integer;
// Biến lưu điểm
FGameScore: Integer;
// Biến lưu số lượng tiền vàng
FCoinCount: Integer;
// Biến lưu trữ số kg cá ăn được
FFishCount: Integer;
// Biến lưu khoản thời gian di chuyển được
FPlayingDuration: Integer;
// Biến lưu trữ sức khỏe của con cá (mỗi 1s ko ăn được cá sẽ giảm 1, ăn cá sẽ tăng lên)
FHealth: Integer;
// Biến lưu trữ cấp độ hiện tại của con cá
FLevel: Integer;
// Cờ xem có đang dùng "sự giận dữ" không
FAngry: Integer;
// Tốc độ chơi game
FGameSpeed: Real;
// Mức độ tích lũy sự giận dữ
FAngryThreshold: Integer;
// Tỉ lệ màn hình game/design
FScreenScale: Single;
// Thread tạo hiệu ứng chuyển động cho dãi đất + san hô
FBackdropThread: TThread;
// Thread tạo hiệu ứng chuyển động cho đồng xu và con mực
FCoinAndCuttleFishAnimationThread: TThread;
// Thread tạo hiệu ứng chuyển động của các con sứa
FJellyFishAnimationThread: TThread;
// Thread tạo hiệu ứng chuyển động cho cá mập
FSharkThread: TThread;
// Thread tạo tàu cá/tàu quân sự
FShipThread: TThread;
// Cờ báo hiệu đã thả bom chưa
FBombFlag: Boolean;
// Cờ báo hiệu đã hiển thị báo động
FAlertSignAlreadyShown: Boolean;
// Màn hình đang được hiển thị
FActiveScreen: TRectangle;
// Âm thanh
FSoundEnabled: Boolean;
// Nhạc nền
FMusicEnabled: Boolean;
// Ngôn ngữ
FLanguage: TGameLanguage;
// Thống kê chơi game
FGameData: TGameData;
// Mảng chứa các media player phát âm "ăn tiền"
FCoinSoundMediaPlayer: array [0..2] of TMediaPlayer;
// Hàm hiệu chỉnh thời gian các đối tượng chuyển động so với BackgroundBottom1
function AjustedDuration(const ADuration: Single): Single;
// Thủ tục hiệu chỉnh tốc độ sinh cá
procedure AjustFishCreationSpeed;
// Thủ tục đặt giá trị cho FAngry
procedure SetAngry(const AValue: Integer);
// Thủ tục đặt giá trị cho FAngryThreshold
procedure SetAngryThreshold(const AVAlue: Integer);
// Thủ tục gán thời gian hiệu lực cho Shield
procedure SetShield(const AValue: Integer);
// Thủ tục đặt giá trị cho FShieldThreshold
procedure SetShieldThreshold(const AValue: Integer);
// Thủ tục đổi trạng thái game
procedure SetGameState(const AValue: TGameState);
// Thủ tục đổi giá trị game speed
procedure SetGameSpeed(const AValue: Real);
// Thủ tục đặt giá trị cho FCoinCount
procedure SetCoinCount(const AValue: Integer);
// Thủ tục đặt giá trị cho FFishCount
procedure SetFishCount(const AValue: Integer);
// Thủ tục đặt giá trị cho FPlayingDuration
procedure SetPlayingDuration(const AValue: Integer);
// Thủ tục đặt giá trị cho FHealth
procedure SetHealth(const AValue: Integer);
// Thủ tục đặt giá trị cho FLevel
procedure SetLevel(const AValue: Integer);
// Thủ tục đặt giá trị cho FSoundEnabled
procedure SetSound(const AValue: Boolean);
// Thủ tục đặt giá trị cho FMusicEnabled
procedure SetMusic(const AValue: Boolean);
// Thủ tục đặg giá trị cho FLanguage
procedure SetLanguage(const AValue: TGameLanguage);
// Thủ tục đặt trạng thái cho các Timer
procedure SetTimerStatus(const AStatus: Boolean);
// Thủ tục đặt giá trị cho FMainFishImageIndex
procedure SetMainFishImageIndex(const AValue: Integer);
/// <summary>
/// Thủ tục đặt trạng thái cho các thread <br>
/// AStatus = True: kích hoạt<br>
/// AStatus = False: đóng băng
/// </summary>
procedure SetGameThreadStatus(const AStatus: Boolean);
// Thủ tục bật tắt chuyển động của đàn cá nhỏ
procedure SetSmallFishAniStatus(const AStatus: Boolean);
// Thủ tục tạo các Thread của game
procedure CreateGameThreads;
// Tính toán tọa độ theo chiều thẳng đứng của con cá
procedure CalculateVerticalCoordinateOfTheFish;
// Thủ tục tính Step cho backdrop
procedure CalculateBackdropAmimationStepValues;
// Thủ tục tính độ co giãn của màn hình
procedure CalculateScreenScale;
// Thủ tục khởi tạo dữ liệu liên quan đến chuyển động
procedure InitAnimationData;
// Thủ tục khởi tạo dữ liệu liên quan đến chuyển động của những đồng xu
procedure InitCoinAnimationData;
// Thủ tục khởi tạo dữ liệu cho các cây san hô
procedure InitCoralData;
// Thủ tục khởi tạo dữ liệu cho đàn cá nhỏ
procedure InitSmallFishes;
// Thủ tục khởi tạo dữ liệu cho nhạc + âm thanh
procedure InitMusicAndSound;
// Thủ tục nạp thông tin game
procedure LoadGameData;
// Thủ tục lưu lại thông tin game
procedure SaveGameData;
// Thủ tục bắt đầu game
procedure StartGame;
// Thủ tục kết thúc game
procedure StopGame(const AShowTheResult: Boolean = True; const AHideTheFish: Boolean = True);
// Thủ tục dừng game (sẽ gọi lại EndGame
procedure StopGameDelay;
// Thủ tục tạm dừng game
procedure PauseGame(const AShowPausedDialog: Boolean = False);
// Thủ tục khởi động lại game
procedure ResumeGame;
// Thủ tục phát âm thanh
procedure PlaySound(const ASound: TGameSound);
// Thủ tục hiển thị kết chơi
procedure ShowGameResult;
// Thủ tục bật bộ tạo ngọc trai
procedure ShowClamShell;
// Thủ tục sinh cá
procedure CreateFish;
// Thủ tục xóa toàn bộ cá (giải phóng bộ nhớ)
procedure ClearFishes;
// Thủ tục sinh tiền xu
procedure CreateCoins;
// Thủ tục sinh đàn cá nhỏ
procedure CreateSmallFishes;
// Thủ tục sinh bọt bong bóng
procedure CreateBubble(const X, Y: Single);
// Thủ tục tạo hiệu ứng cá ăn cá
procedure CreateEatingEffect(const X, Y: Single);
// Thủ tục xử lý khi đồng xu tới bảng điểm
procedure CoinAnimationFinish(Sender: TObject);
// Thủ tục cập nhật lại level
procedure UpdateLevel;
// Thủ tục cập nhật điểm
procedure UpdateScore;
// Thủ tục cập nhật thống kê lên GameStats
procedure UpdateStats;
// Thủ tục cập nhật kích thước + hình ảnh của cá chính
procedure UpdateMainFishImage;
// Thủ tục xử lý hậu chuyển động (xử lý ăn cá)
procedure AniAfterProcessingAll(ASender: TObject);
// Thủ tục xử lý cá ăn tiền xu
procedure ProcessCoins;
// Thủ tục xử lý cá ăn cá (không phải cá nhỏ)
procedure ProcessFishCollision;
// Thủ tục tăng tốc độ chơi game
procedure IncreaseGameSpeed;
// Thủ tục tạo hiệu ứng thả ngư lôi
procedure DropBomb;
// Thủ tục tạo hiệu ứng thả lưỡi câu
procedure ThrowFishingLure;
// Thủ tục hiển thị biểu tượng báo động
procedure ShowAlertSign;
// Thủ tục hiển thị đám đen trên màn hình
procedure ShowDarkPigment(const X, Y: Single);
// Thử tục cache ảnh
procedure CreateImageCache;
// Thủ tục hiển thị màn hình trong game
procedure ShowScreen(const AScreen: TRectangle);
// Thủ tục đặt ảnh cho toggle
procedure SetToggleImage(const AToggle: TRectangle; const AValue: Boolean);
// Thủ tục đặt ảnh cho 1 Rectangle
procedure FillRectangle(const ARectangle: TRectangle; const AImageList: TCustomImageList; const AImageIndex: TImageIndex);
// Thủ tục tạo hiệu ứng nút bấm bị nhấn xuống
procedure ButtonClickWithEffect(const AButton: TRectangle; const AProc: TProc<TRectangle>);
// Thủ tục dàn lại các thành phần của game để phù hợp với kích thước màn hình
procedure AlignControls;
// Thủ tục hiển thị hộp thoại để người dùng xác nhận thoát game
procedure PauseGameAndShowLeavePopup;
// Thủ tục ẩn hộp thoại LeavePopup
procedure HideLeavePopup;
// Thủ tục rung điện thoại
procedure Viberate(const ADuration: Integer);
// Hàm kiểm tra xem đối tượng có chồng con cá hay không
function IsOverlap(const AObject: TRectangle; const AUseClipper: Boolean = True): Boolean;
// Hàm trả về điểm chính giữa của con cá (theo chiều cao)
function MidPositionOfTheFish: Single;
function GetDeviceLanguage: TGameLanguage;
///////////////////////
procedure OnSmallFishFinished(Sender: TObject);
public
class property GameState : TGameState read FGameState;
public
property Angry : Integer read FAngry write SetAngry;
property AngryThreshold : Integer read FAngryThreshold write SetAngryThreshold;
property CoinCount : Integer read FCoinCount write SetCoinCount;
property FishCount : Integer read FFishCount write SetFishCount;
property GameScore : Integer read FGameScore;
property GameSpeed : Real read FGameSpeed write SetGameSpeed;
property Health : Integer read FHealth write SetHealth;
property Language : TGameLanguage read FLanguage write SetLanguage;
property Level : Integer read FLevel write SetLevel;
property Music : Boolean read FMusicEnabled write SetMusic;
property PlayingDuration : Integer read FPlayingDuration write SetPlayingDuration;
property Shield : Integer read FShield write SetShield;
property ShieldThreshold : Integer read FShieldThreshold write SetShieldThreshold;
property Sound : Boolean read FSoundEnabled write SetSound;
property MainFishImageIndex: Integer read FMainFishImageIndex write SetMainFishImageIndex;
end;
var
GameForm: TGameForm;
implementation
uses
System.Math, System.SyncObjs;
{$R *.fmx}
{$HINTS OFF}
{$WARNINGS OFF}
type
TGameUIThread = class(TThread)
private
class function GetTickCountInMicroSecond: Cardinal; static;
protected
FTickcount: Cardinal;
procedure ResumeGame;
procedure PauseGame;
procedure SetActiveValue(const AValue: Boolean);
procedure Release;
procedure CustomSleep(const ASecond: Integer);
public
constructor CreateGameThread;
procedure ShowAlertSign;
public
property Active: Boolean write SetActiveValue;
end;
TBackdropThread = class(TGameUIThread)
protected
procedure Execute; override;
end;
TCoinAndCuttleFishAnimationThread = class(TGameUIThread)
protected
procedure Execute; override;
end;
TJellyFishAnimationThread = class(TGameUIThread)
protected
procedure Execute; override;
end;
TSharkMovingThread = class(TGameUIThread)
protected
procedure Execute; override;
end;
TShipThread = class(TGameUIThread)
protected
procedure Execute; override;
end;
TCollisionProcessThread = class(TGameUIThread)
protected
procedure Execute; override;
end;
function TGameForm.AjustedDuration(const ADuration: Single): Single;
begin
Result := ADuration;
end;
procedure TGameForm.ShowAlertSign;
begin
if (FGameState = TGameState.Running) and not FAlertSignAlreadyShown then
begin
FAlertSignAlreadyShown := True;
CircleAlert.Opacity := 0;
CircleAlert.Visible := True;
AniAlert.Start;
end;
end;
procedure TGameForm.AjustFishCreationSpeed;
var
LInterval: Integer;
begin
case FLevel of
1: LInterval := 3000;
2: LInterval := 2500;
3: LInterval := 2000;
4: LInterval := 1500;
5: LInterval := 1250;
6: LInterval := 1000;
else LInterval := 750;
end;
TimerFishCreation.Interval := Trunc(LInterval * FGameSpeed);
end;
procedure TGameForm.AlignControls;
{$J+}
const
FirstTime: Boolean = True;
{$J-}
var
LDelta: Single;
LCoral: TRectangle;
LScale: Single;
begin
LScale := Width / GAME_FORM_WIDTH;
LayoutWrapper.Scale.X := LScale;
LayoutWrapper.Scale.Y := LScale;
LDelta := Height - GAME_FORM_HEIGHT * LScale;
if FirstTime then
begin
for LCoral in FCorals do
LCoral.TagFloat := LCoral.Position.Y;
FirstTime := False;
end;
for LCoral in FCorals do
LCoral.Position.Y := LCoral.TagFloat + LDelta / LScale / 1.5;
end;
procedure TGameForm.AniAfterProcessingAll(ASender: TObject);
{$J+}
const
LCount: Cardinal = 0;
{$J-}
var
LFish: TRectangle;
begin
if FGameState = TGameState.Running then
begin
Inc(LCount);
if LCount mod 2 = 0 then
begin
// Toàn bộ là cá nhỏ nên sẽ bị cá chính ăn hết
for LFish in FSmallFishes do
begin
if IsOverlap(LFish) then
begin
PlaySound(TGameSound.Eating);
// Tạo hiệu ứng ăn cá
CreateEatingEffect(LFish.Position.X + LFish.Width / 2, LFish.Position.Y + LFish.Height / 2);
// Cập nhật lại sức khỏe
Health := Health + 1; // Cá nhỏ nên 1 = LFish.Tag
// Tăng tích lũy sự giận dữ
AngryThreshold := AngryThreshold + 1; // Đưa cái này lên trước FishCoun để bật Angry trước khi Level thay đổi
// Tăng số cá ăn được
FishCount := FishCount + 1; // Cá nhỏ nên 1 = LFish.Tag
// Ẩn cá bị ăn đi
LFish.Visible := False;
// Lưu vào thống kê
Inc(FGameData.Fish);
end;
end;
end
else
begin
Canvas.BeginScene;
// Xử lý ăn tiền xu
ProcessCoins;
// Xử lý ăn cá thường
ProcessFishCollision;
// Cập nhật lại màn hình
Canvas.EndScene;
end;
end;
end;
procedure TGameForm.AniAlertFinish(Sender: TObject);
begin
FAlertSignAlreadyShown := False;
CircleAlert.Visible := False;
end;
procedure TGameForm.AniBombFinish(Sender: TObject);
begin
BombEffect.Enabled := False;
FBombFlag := False;
end;
procedure TGameForm.AniFishingLineStep1Finish(Sender: TObject);
begin
AniFishingLineStep2.Start;
end;
procedure TGameForm.AniFishingLineStep2Finish(Sender: TObject);
begin
FStartFishingLineIsStarted := False;
end;
procedure TGameForm.AniTorpedoFinish(Sender: TObject);
var
LFish, LCoin: TRectangle;
LCenter: TPointF;
LRadius: Integer;
begin
if not BombEffect.Enabled then
begin
LCenter := TPointF.Create(Layout.Width / 2, Layout.Height / 2);
BombEffect.Center := TPointF.Create(Layout.Width * FScreenScale / 2, Layout.Height * FScreenScale / 2);
BombEffect.Enabled := True;
PlaySound(TGameSound.Bomb);
Viberate(250);
AniBomb.Start;
// Ẩn để tiết kiệm CPU
TheTorpedo.Visible := False;
// Chỉ xử lý khi game đang chạy
if FGameState = TGameState.Running then
begin
case Level of
0..3: LRadius := 125;
4: LRadius := 137;
5..10: LRadius := 150;
end;
// Xử lý cá nhỏ
for LFish in FSmallFishes do
if TPointF.PointInCircle(TPointF.Create(LFish.Position.X + LFish.Width / 2, LFish.Position.Y + LFish.Height / 2), LCenter, LRadius) then
LFish.Visible := False;
// Xử lý cá thường
for LFish in FFishes do
if TPointF.PointInCircle(TPointF.Create(LFish.Position.X + LFish.Width / 2, LFish.Position.Y + LFish.Height / 2), LCenter, LRadius) then
begin
FFishes.Remove(LFish);
LFish.Visible := False;
FCachedFishes[LFish.Kind, LFish.Direction].Add(LFish);
end;
// Xử lý các con sứa
for LFish in FJellyFishes do
if TPointF.PointInCircle(TPointF.Create(LFish.Position.X + LFish.Width / 2, LFish.Position.Y + LFish.Height / 2), LCenter, LRadius) then
begin
FJellyFishes.Remove(LFish);
LFish.Visible := False;
FCachedJellyFishes.Add(LFish);
end;
// Xử lý các con mực
for LFish in FCuttleFishes do
if TPointF.PointInCircle(TPointF.Create(LFish.Position.X + LFish.Width / 2, LFish.Position.Y + LFish.Height / 2), LCenter, LRadius) then
begin
FCuttleFishes.Remove(LFish);
LFish.Visible := False;
FCachedCuttleFishes.Add(LFish);
end;
// Xử lý các đồng xu
for LCoin in FCoins do
if TPointF.PointInCircle(TPointF.Create(LFish.Position.X + LFish.Width / 2, LFish.Position.Y + LFish.Height / 2), LCenter, LRadius) then
begin
LCoin.Tag := GAME_COIN_HIDDEN;
LCoin.Position.X := -100;
end;
// Xử lý cá mập
if TPointF.PointInCircle(TPointF.Create(TheShark.Position.X + TheShark.Width / 2, TheShark.Position.Y + TheShark.Height / 2), LCenter, LRadius) then
begin
TheShark.Data := 1;
TheShark.Visible := False;
TheShark.Position.X := -1000;
end;
// Xử lý cá chính
if (Shield <= 0) and TPointF.PointInCircle(TPointF.Create(TheFish.Position.X + TheFish.Width / 2, TheFish.Position.Y + TheFish.Height / 2), LCenter, LRadius) then
StopGameDelay;
end;
end;
end;
procedure TGameForm.OnGameCompleteButtonClick(Sender: TObject);
var
LButton: TRectangle;
begin
LButton := TRectangle(Sender);
// Tạo hiệu ứng nhấn xuống và xử lý lệnh
ButtonClickWithEffect(LButton,
procedure (AButton: TRectangle)
begin
if AButton = BtnGameCompleteHome then
ShowScreen(GameMenu)
else if AButton = BtnGameCompleteReplay then
begin
ShowScreen(nil);
StartGame;
end;
end
);
end;
procedure TGameForm.OnLeavePopupButtonClick(Sender: TObject);
var
LButton: TRectangle;
begin
LButton := TRectangle(Sender);
// Hiển thị ảnh nhấn nút bấm và xử lý lệnh
ButtonClickWithEffect(LButton,
procedure (AButton: TRectangle)
begin
// Ẩn hộp thoại trước khi ẩn những cái khác ở StopGame;
HideLeavePopup;
// Xử lý lệnh cho nút bấm
if AButton = BtnPopupLeaveYes then
begin
// Cho các con cá hoạt động lại
SetSmallFishAniStatus(True);
// Dừng game (không hiển thị kết quả)
StopGame(False);
// Ở StopGame tắt TimerSmallFishCreation nên phải bật lại để tạo hiệu ứng cá bơi
TimerSmallFishCreation.Enabled := True;
end
else
ResumeGame;
end
);
end;
procedure TGameForm.OnGameLeaveClick(Sender: TObject);
begin
// Nếu popup đang hiển thị thì không làm gì hết
if GamePopupLeave.Visible or (GameState = TGameState.Paused) then
Exit;
// Hiển thị ảnh nhấn xuống
ButtonClickWithEffect(BtnGameLeaveImage, nil);
// Tạm dừng game và hiển thị popup
PauseGameAndShowLeavePopup;
end;
procedure TGameForm.OnMenuButtonClick(Sender: TObject);
var
LButton: TRectangle;
begin
// Ép sang kiểu TRectangle để xử lý
LButton := TRectangle(Sender);
// Cho chữ nhấn xuống theo hình nền
LButton.Padding.Top := 0;
ButtonClickWithEffect(LButton,
procedure (AButton: TRectangle)
begin
AButton.Padding.Top := -4;
// Nếu là nút Play
if AButton = BtnPlay then
begin
ShowScreen(nil);
StartGame;
end;
// Nếu là nút Setting
if AButton = BtnSetting then
ShowScreen(GameSetting);
// Nếu là nút Back ở trang Setting
if AButton = BtnSettingReturn then
ShowScreen(GameMenu);
// Nếu là nút Back ở trang Statistics
if AButton = BtnGameStatsReturn then
ShowScreen(GameMenu);
// Nếu là nút Exit
if AButton = BtnExit then
Application.Terminate;
end
);
end;
procedure TGameForm.OnSmallFishFinished(Sender: TObject);
begin
TControl((Sender as TAnimation).Parent).Visible := False;
end;
procedure TGameForm.DropBomb;
begin
if not FBombFlag then
begin
FBombFlag := True;
TheTorpedo.Visible := True;
AniTorpedo.Start;
end;
end;
procedure TGameForm.CalculateBackdropAmimationStepValues;
begin
FStep1 := GAME_FORM_WIDTH / FDuration1;
FStep2 := GAME_FORM_WIDTH / FDuration2;
FStep3 := GAME_FORM_WIDTH / FDuration1;
end;
procedure TGameForm.CalculateScreenScale;
begin
if Layout.Scene <> nil then
FScreenScale := Layout.Scene.GetSceneScale * Width / GAME_FORM_WIDTH
else
FScreenScale := 1;
end;
procedure TGameForm.CalculateVerticalCoordinateOfTheFish;
begin
FFishVerticalCoordinate := TheFish.Position.Y + TheFish.Height / 2;
end;
procedure TGameForm.ClearFishes;
var
LFish: TRectangle;
begin
for LFish in FFishes do
begin
FFishes.Remove(LFish);
LFish.DisposeOf;
end;
end;
procedure TGameForm.CoinAnimationFinish(Sender: TObject);
var
LAnimation: TPathAnimation;
begin
LAnimation := TPathAnimation(Sender);
LAnimation.DisposeOf;
end;
procedure TGameForm.CreateGameThreads;
begin
////////////////////////////
FBackdropThread := TBackdropThread.Create(False);
////////////////////////////
FCoinAndCuttleFishAnimationThread := TCoinAndCuttleFishAnimationThread.Create(True);
FJellyFishAnimationThread := TJellyFishAnimationThread.Create(True);
FSharkThread := TSharkMovingThread.Create(True);
FShipThread := TShipThread.Create(True);
end;
procedure TGameForm.CreateBubble(const X, Y: Single);
const
{$J+}
LastTime: Cardinal = 0;
{$J-}
var
r: Cardinal;
LNow: Cardinal;
LBubble: TRectangle;
begin
LNow := TThread.GetTickCount;
if LNow - LastTime > 1500 then
begin
LastTime := LNow;
if FCachedBubbleList.Count = 0 then
begin