-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmGameProc.bas
5344 lines (4380 loc) · 163 KB
/
mGameProc.bas
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
Attribute VB_Name = "mGameProc"
Option Explicit
' handles most of the inside-game-engine
' Blittings
' ---------------------------------------------------------------
Public Sub UpdateFrame() ' Updates All Animations and Graphics
Select Case g_GameState
' play KenamicK's Logo
Case GAMSTATE_LOGO
Call mGFX.GFXClearBackBuffer
Call mDirectDraw.DDBlitToPrim
Call DoKKLogo
Case GAMSTATE_INTRO
Call UpdateStarTrip
Call UpdateStory(True)
' --- main menu mode
Case GAMSTATE_MAINMENU
Call BltFastGFX_HBM(0, 0, g_Objects.backpaper(1))
Call BltFastGFX_HBM(538, 434, g_Objects.vbc)
Call UpdateStarTrip
Call UpdateMainMenu
Call UpdateLogo
Call DoErrorBox(False) ' update error box messages
If (g_showFPS) Then Call GFXTextOut(lpBack, 10, 470, "Running at: " & CStr(nFPS) & " FPS", 12, RGB(25, 25, 225))
' --- do briefing
Case GAMSTATE_BRIEFING
'...
Call UpdateBriefing
Call UpdateStarTrip
If (g_showFPS) Then Call GFXTextOut(lpBack, 10, 470, "Running at: " & CStr(nFPS) & " FPS", 12, RGB(25, 25, 225))
' --- gamePlay mode
Case GAMSTATE_PLAY
Call GFXFadeInOut
Call UpdateWorld ' update world position
Call PlayerGetInput
Call DoMoonQuake ' update Moon Quakes
Call UpdateStarField
' update objects
If Not bools(1) Then
'Call UpdateBackGround ' update scrolling-background
End If
'Call UpdateStarField ' update persepective-star-field
If Not bools(2) Then
Call UpdateEarth ' update our homeworld ;)
End If
Call UpdateBonus ' draw all bonus objects
Call UpdateParticleLasers ' update plaser
Call UpdateFarEnemies ' update distant ships
Call UpdateWarpGates
'{!}
If (bools(6)) Then Call CShuttle.Update
Call CBattleStation.Update
'{!}
If Not bools(3) Then
Call UpdateMoonSurface ' update close-range moon-surface
End If
Call UpdateMeteors ' update meteor threats
Call UpdateExplosionsFar ' update distant explosions ONLY
Call UpdateCloseEnemies ' update enemy ships classes ( closer )
Call UpdateBunkers ' update friendly bunkers
Call UpdateExplosions
' update weapons and gfx
Call UpdateMissiles ' update fired-missiles
Call UpdateLaserCuts
Call UpdateParticleRemover
Call UpdateChillingPixels ' update missile trails
'Call UpdateExplosions ' update all explosions
Call UpdateParticleExplosions
' handle all-player stuff
If Not bools(4) Then
Call UpdatePlayer
End If
' update mission
'g_Gates = GS_NONE ' {!}
If (g_Gates = GS_NONE) Then
If (g_showFPS) Then Call GFXTextOut(lpBack, 610, 468, CStr(nFPS) & "fps", 12, RGB(15, 180, 15))
If (Not CLevel.Update) Then
' increment mission counter
g_Player.mission = g_Player.mission + 1
Call StartBriefing
' copy scores
g_arChar(g_nPlayerIndex) = g_Player
' precalc levels
Dim cn As Long
For cn = 0 To g_nChars
g_arChar(cn).level = CHARExperienceToLevel(g_arChar(cn).Exp)
Next
End If
End If
' --- Finished game
Case GAMSTATE_EPILOGUE
Call UpdateStarTrip
Call UpdateStory(False)
' --- QuitGame mode
Case GAMSTATE_QUIT
'...
Debug.Print "GAME LEVEL DONE"
bRunning = False
Case Else
Debug.Print "Invalid Game State!"
End Select
' gates need to be opened/closed here, before backbuffer's data is copied to the frontbuffer
If (g_Gates = GS_OPEN) Then
Call DoGates(False)
ElseIf (g_Gates = GS_CLOSE Or g_Gates = GS_CLOSEOPEN) Then
Call DoGates(True)
End If
End Sub
'/////////////////////////////////////////////////////////////////
'//// Update player-input interaction
'/////////////////////////////////////////////////////////////////
Public Sub _
PlayerGetInput()
Dim bPlayerFire As Boolean
Dim cn As Long
' get all mouse actions (left,right,pos)
Call CMouse.GetActions
Call mDirectInput.DICheckKeys
' change weapon
If (CMouse.GetRight = MS_Up) Then
PlayerWeapon = PlayerWeapon + 1
If (PlayerWeapon > PW_MISSILE_LONGRANGE) Then PlayerWeapon = PW_LASER
End If
If CMouse.GetLeft = MS_Up Then
bPlayerFire = True
End If
' get keyboard interaction
If (DIKeyState(DIK_ESCAPE) = KS_KEYUP) Then
g_Gates = GS_CLOSEOPEN
g_GameState = GAMSTATE_MAINMENU
g_arChar(g_nPlayerIndex) = g_Player
' precalc levels
For cn = 0 To g_nChars
g_arChar(cn).level = CHARExperienceToLevel(g_arChar(cn).Exp)
Next
End If
If (DIKeyState(DIK_LEFT) = KS_KEYDOWN Or DIKeyState(DIK_A)) Then UpdateWorld True
If (DIKeyState(DIK_RIGHT) = KS_KEYDOWN Or DIKeyState(DIK_D)) Then UpdateWorld , True
If (DIKeyState(DIK_1) = KS_KEYUP) Then PlayerWeapon = PW_LASER
If (DIKeyState(DIK_2) = KS_KEYUP) Then PlayerWeapon = PW_MISSILE_CLOSERANGE
If (DIKeyState(DIK_3) = KS_KEYUP) Then PlayerWeapon = PW_MISSILE_LONGRANGE
If (DIKeyState(DIK_SPACE) = KS_KEYUP) Then bPlayerFire = True
If (DIKeyState(DIK_F) = KS_KEYDOWN) Then
If (g_showFPS) Then g_showFPS = False Else g_showFPS = True
End If
' sound volume
If (DIKeyState(DIK_MINUS) = KS_KEYDOWN) Then
If (m_nGlobalVol > SFX_VOLUMEMIN) Then m_nGlobalVol = m_nGlobalVol - 5
End If
If (DIKeyState(DIK_EQUALS) = KS_KEYDOWN) Then
If (m_nGlobalVol < SFX_VOLUMEMAX) Then m_nGlobalVol = m_nGlobalVol + 5
End If
' play/stop music
If (DIKeyState(DIK_M) = KS_KEYUP) Then
If (g_bmusPlaying) Then Call mFMod.STOPmus Else _
mFMod.PLAYmus True
End If
' debug keys
If (g_bDebug) Then
If DIKeyState(DIK_F1) = KS_KEYUP Then bools(1) = True
If DIKeyState(DIK_F2) = KS_KEYUP Then bools(2) = True
If DIKeyState(DIK_F3) = KS_KEYUP Then bools(3) = True
If DIKeyState(DIK_F4) = KS_KEYUP Then bools(4) = True
If DIKeyState(DIK_F9) = KS_KEYUP Then bools(6) = True
If DIKeyState(DIK_F5) = KS_KEYUP Then bools(1) = False
If DIKeyState(DIK_F6) = KS_KEYUP Then bools(2) = False
If DIKeyState(DIK_F7) = KS_KEYUP Then bools(3) = False
If DIKeyState(DIK_F8) = KS_KEYUP Then bools(4) = False
If DIKeyState(DIK_F10) = KS_KEYUP Then bools(6) = False
If DIKeyState(DIK_F11) = KS_KEYUP Then CBunker(0).DoDamage = 100
If DIKeyState(DIK_F12) = KS_KEYUP Then CBunker(3).DoDamage = 100
If DIKeyState(DIK_R) = KS_KEYUP Then Call DDSetGamma(0, 0, 142)
If DIKeyState(DIK_B) = KS_KEYUP Then CreateBonus (CMouse.GetX) + wx, (CMouse.GetY) + wy
If (DIKeyState(DIK_H) = KS_KEYUP) Then Call GFXFadeInOut(2)
End If
' Cheater keys !
If (g_Player.cheater = 123) Then
Dim objbns As stBonus
If DIKeyState(DIK_NUMPAD7) = KS_KEYUP Then CreateBonus (CMouse.GetX) - wx, (CMouse.GetY) - wy, BONUS_PREMOVER
If DIKeyState(DIK_NUMPAD8) = KS_KEYUP Then CreateBonus (CMouse.GetX) - wx, (CMouse.GetY) - wy, BONUS_RANGEKILL
If DIKeyState(DIK_NUMPAD4) = KS_KEYUP Then
objbns.kind = BONUS_REVIVEBUNKER
Call GiveBonus(objbns)
ElseIf DIKeyState(DIK_NUMPAD5) = KS_KEYUP Then
objbns.kind = BONUS_RAPIDFIRE
Call GiveBonus(objbns)
ElseIf DIKeyState(DIK_NUMPAD6) Then
objbns.kind = BONUS_MEGADAMAGE
Call GiveBonus(objbns)
ElseIf DIKeyState(DIK_NUMPAD1) Then
objbns.kind = BONUS_ANNIHILATE
Call GiveBonus(objbns)
End If
End If
' activate actions
If (bPlayerFire And CMouse.GetY < TARGET_AREA) Then
' create missiles shot
If (PlayerWeapon <> PW_LASER) Then
Call Player_CreateMissile(CMouse.GetX, _
CMouse.GetY, 1, 1)
g_Player.score = g_Player.score - 2 ' weaponary
Call DSPlaySound(g_dsSfx(SFX_PLAYERROCKETFIRE), False)
cpy = 6
' create laser shot
Else
Static lTimeLaser As Long
If (lTimeLaser < GetTicks) Then
lTimeLaser = 150 + GetTicks + g_PlayerFireDelay
g_Player.score = g_Player.score - 1 ' weaponary
Call Player_CreateLaser(CMouse.GetX, CMouse.GetY, 1, 1)
' do cockpit offset
cpx = 4
cpy = 10
'DSPlaySound g_dsCannon(SFX_CANNONPLAYER), False
DSPlaySound g_dsCannon(nGetRnd(SFX_CANNONPLAYER1, SFX_CANNONPLAYER2)), False
End If
End If
End If
End Sub
Public Sub UpdatePlayer()
' Desc: Update player actions and stuff
'Call Player_UpdateMissiles
'Call Player_UpdateLasers
Call Player_UpdateShots ' refresh all shots
Call UpdateCockPit ' redraw cockpit
Call UpdateSMQ ' check and output scrolling-messages
' blit cursor
If (CMouse.GetY > TARGET_AREA) Then
Call BltFastGFX_HBM(CMouse.GetCenterX, CMouse.GetCenterY, g_Objects.Cursor(1))
Else
Call BltFastGFX_HBM(CMouse.GetCenterX, CMouse.GetCenterY, g_Objects.Cursor(0))
End If
' draw info
Dim strWeapon As String
'Dim strAmmo As String
If (PlayerWeapon = PW_LASER) Then
strWeapon = arText(MENU_COCKPIT_WEAPON_LASER) '"Laser"
' strAmmo = "Infinite"
ElseIf (PlayerWeapon = PW_MISSILE_CLOSERANGE) Then
strWeapon = arText(MENU_COCKPIT_WEAPON_MISFAR) '"Mis_Close"
' strAmmo = "10"
ElseIf (PlayerWeapon = PW_MISSILE_LONGRANGE) Then
strWeapon = arText(MENU_COCKPIT_WEAPON_MISCLOSE) '"Mis_Far"
' strAmmo = "10"
End If
Call DrawTextCP(0, arText(MENU_COCKPIT_WEAPON) & strWeapon)
'Call DrawTextCP(0, "BS: " & CBattleStation.GetHitPoints)
' Call DrawTextCP(1, "Ammo: " & strAmmo)
Call DrawTextCP(1, arText(MENU_COCKPIT_EARTH) & g_hpEarth)
Call DrawTextCP(2, arText(MENU_PLAYERSCORE) & g_Player.score)
Call DrawTextCP(3, arText(MENU_COCKPIT_TIMELEFT) & CLevel.GetTimeLeft())
' earth dies -> you die...
If (g_hpEarth <= 0 Or (CBattleStation.GetHitPoints <= 0 And g_Player.mission = 4)) Then
g_Gates = GS_CLOSEOPEN
g_GameState = GAMSTATE_MAINMENU
' copy scores
g_arChar(g_nPlayerIndex) = g_Player
' precalc levels
Dim cn As Long
For cn = 0 To g_nChars
g_arChar(cn).level = CHARExperienceToLevel(g_arChar(cn).Exp)
Next
End If
End Sub
'///////////////////////////////////////////////////////////////
'//// Play Logo Animation
'///////////////////////////////////////////////////////////////
Public Sub _
DoKKLogo()
On Local Error GoTo StartMenu:
Dim lTimeLogo As Long
Dim xavi As Integer
Dim yavi As Integer
Dim sfilename As String
Dim ff As Integer
Dim header As Long
' stop bgmusic
'mFMod.STOPmus
' set movie path
sfilename = App.Path & "\data\logo.avi"
ff = FreeFile()
Open (sfilename) For Binary Access Write Lock Read Write As #ff
Put #ff, , &H46464952
Close #ff
Call mAvi.OpenAVI(frmMain.hwnd, sfilename, "KL")
If (mAvi.GetAVIWindow("KL") = -1) Then
'call errormsg("Could not locate logo file")
AppendToLog ("Error loading logo movie.")
GoTo StartMenu
End If
' set timer
lTimeLogo = 12900 + GetTicks()
' setup avi position
xavi = (MAX_CX / 2) - 200 '(mAvi.GetAVIRect("KL").Right / 2)
yavi = (MAX_CY / 2) - (mAvi.GetAVIRect("KL").Bottom / 2)
Call mAvi.MoveAVIWindow("KL", xavi, yavi, 400)
frmMain.BackColor = &H0
'frmMain.AutoRedraw = True
frmMain.Cls
' star movie
Call mAvi.PlayAVI("KL", FromStart)
Do While (lTimeLogo > GetTicks())
Call DICheckKeys
If (DIKeyState(DIK_ESCAPE) = KS_KEYUP Or _
DIKeyState(DIK_SPACE) = KS_KEYUP Or _
DIKeyState(DIK_RETURN) = KS_KEYUP) Then Exit Do
'frmMain.Cls
DoEvents
Loop
StartMenu:
' set logo passed key in registry
Call mUtil.RegSetKey(&H80000002, "SOFTWARE\KenamicK Entertainment\DD2\", "logo", "1")
frmMain.AutoRedraw = False
Call mAvi.CloseAVI("KL")
Call mAvi.CloseAllAVI
Open (sfilename) For Binary Access Write Lock Read Write As #ff
Put #ff, , KVID
Close #ff
g_GameState = GAMSTATE_INTRO
'AppendToLog ("Error playing logo!")
' {!} to remove
'mDirectSound.m_nGlobalVol = -1000
'DSPlaySound g_dsSfx(SFX_SPACEMYST1), True
End Sub
'///////////////////////////////////////////////////////////////
'//// Show Game Story - Intro/Epilogue
'///////////////////////////////////////////////////////////////
Public Sub _
UpdateStory(bIntro As Boolean)
Static lTime As Long
'Static bmus_load As Boolean
Dim lClr As Long
Dim lClr1 As Long
Dim x As Integer
Dim y As Integer
Dim msg As String
Dim cn As Long
' get input
Call DICheckKeys
Call CMouse.GetActions
If (lTime = 0 And bIntro) Then
lTime = GetTicks() + 300000
ElseIf (lTime = 0 And (Not bIntro)) Then
lTime = GetTicks() + 60000
End If
' on keypress
If (DIKeyState(DIK_ESCAPE) = KS_KEYUP Or _
DIKeyState(DIK_SPACE) = KS_KEYUP Or _
DIKeyState(DIK_RETURN) = KS_KEYUP Or _
CMouse.GetLeft = MS_Up Or _
lTime < GetTicks()) Then
lTime = 0
g_GameState = GAMSTATE_MAINMENU
' start music after intro_story
If (bIntro) Then
Call mFMod.PLAYmus(True)
g_bmusPlaying = True
g_Gates = GS_NONE
Else
g_Gates = GS_CLOSEOPEN
' bmus_load = False
' mFMod.STOPmus
' mFMod.CLOSEmus
' ' load back main menu music
' If (Not mFMod.OPENmus(App.Path & "\data\ar.it")) Then
' Call ErrorMsg("Could not load music file!")
' Else
' AppendToLog ("FMod: loaded \ar.it")
' End If
g_bmusPlaying = False
End If
Else
lClr = RGB(0, 215, 15)
lClr1 = RGB(75, 215, 15)
Call BltFastGFX_HBM(0, 0, g_Objects.backpaper(0))
If (Not bIntro) Then
' update epilogue
'If (Not bmus_load) Then
'
' mFMod.STOPmus
' mFMod.CLOSEmus
' If (Not mFMod.OPENmus(App.Path & "\data\wheni.it")) Then
' Call ErrorMsg("Could not load music file!")
' Else
' AppendToLog ("FMod: loaded \wheni.it")
' End If
'
' mFMod.PLAYmus True
' bmus_load = True
' End If
x = rScreen.Right / 2 - 4
y = rScreen.Top + 50
Call GFXTextOut(lpBack, x, y, g_arEpilogue(0), 24, lClr, , True)
x = 50
y = rScreen.Top + 90
For cn = 1 To UBound(g_arEpilogue)
Call GFXTextOut(lpBack, x, y + cn * 20, g_arEpilogue(cn), 20, lClr, , True)
Next
Else
x = 5
y = rScreen.Top + 65
For cn = 0 To UBound(g_arIntro)
Call GFXTextOut(lpBack, x, y + cn * 16, g_arIntro(cn), 18, lClr, , True)
Next
End If
End If
End Sub
'///////////////////////////////////////////////////////////////
'//// Show mission briefing
'///////////////////////////////////////////////////////////////
Public Sub _
UpdateBriefing()
Dim cn As Integer
Dim lvlDur As Single
Dim lClr As Long
Dim lClr1 As Long
Dim strDur As String
' get input
Call DICheckKeys
Call CMouse.GetActions
' user cancel
If (DIKeyState(DIK_ESCAPE) = KS_KEYUP) Then
g_GameState = GAMSTATE_MAINMENU
g_Gates = GS_CLOSEOPEN
End If
If (CLevel.ElapsedBriefingTime() Or DIKeyState(DIK_SPACE) = KS_KEYUP Or CMouse.GetLeft = MS_Up) Then
' start game
g_GameState = GAMSTATE_PLAY
g_Gates = GS_CLOSEOPEN
'bRunning = False
' update breifing
Else
' draw briefing text
lvlDur = (CLevel.m_lDuration / 60000)
lClr = RGB(200, 15, 15)
lClr1 = RGB(175, 15, 15)
Call BltFastGFX_HBM(0, 0, g_Objects.backpaper(0))
Call GFXTextOut(lpBack, 15, 50 + (cn * 20), CLevel.m_strName, 24, lClr, , True)
strDur = Format$(lvlDur, "#.##")
strDur = "Duration: " & strDur & " mins."
Call GFXTextOut(lpBack, 15, 100, strDur, 20, lClr, , True)
Call GFXTextOut(lpBack, 15, 130, "Briefing...", 20, lClr, , True)
For cn = 0 To CLevel.GetBriefingLines
Call GFXTextOut(lpBack, 15, 180 + (cn * 20), CLevel.GetBriefingLine(cn), 20, lClr1, , True)
Next
End If
End Sub
'///////////////////////////////////////////////////////////////
'//// Setup next game mission
'///////////////////////////////////////////////////////////////
Public Sub _
StartBriefing()
Dim strMissionFile As String
' bound mission
If (g_Player.mission < 1) Then g_Player.mission = 1
If (g_Player.mission > 6) Then g_Player.mission = 6
If (g_Language = LANG_BULGARIAN) Then strMissionFile = "cmp" _
Else strMissionFile = "eng"
Select Case (g_Player.mission)
Case 1
strMissionFile = strMissionFile & "1.ks"
Case 2
strMissionFile = strMissionFile & "2.ks"
Case 3
strMissionFile = strMissionFile & "3.ks"
Case 4
strMissionFile = strMissionFile & "4.ks"
Case 5
strMissionFile = strMissionFile & "5.ks"
Case 6
g_GameState = GAMSTATE_EPILOGUE
g_Gates = GS_CLOSEOPEN
g_Player.mission = 1
g_arChar(g_nPlayerIndex).mission = g_Player.mission
Exit Sub
Case Else
' reset mission counter
Debug.Print "Invalid mission!"
g_Player.mission = 1
g_arChar(g_nPlayerIndex).mission = g_Player.mission
strMissionFile = "cmp1.ks"
Exit Sub
End Select
' load the mission script
Call CLevel.Init
If (Not CLevel.LoadScript(App.Path & "\script\" & strMissionFile)) Then
AppendToLog ("Error loading level script! 'StartBreifing() Proc'")
'Call mMain.ErrorMsg("Error loading level!")
Call mMain.MakeError("Error loading mission! " & vbCr & "Please reinstall game!")
Exit Sub
End If
g_GameState = GAMSTATE_BRIEFING
' close and open gates
g_Gates = GS_CLOSEOPEN
' stop music
If (g_bmusPlaying) Then
g_bmusPlaying = False
Call mFMod.STOPmus
End If
' start space sound
Call mDirectSound.DSPlaySound(g_dsSfx(SFX_SPACEMYST1), True)
' resetgame
Call ResetGame
End Sub
'///////////////////////////////////////////////////////////////
'//// Refresh logo animation
'///////////////////////////////////////////////////////////////
Public Static Sub _
UpdateLogo()
Dim lFPSTime As Long
Dim bytlogoframe As Byte
Dim dx As Long
Dim dy As Long
If (lFPSTime < GetTicks) Then
lFPSTime = GetTicks + (FPS_ANIMS + FPS_ANIMS)
bytlogoframe = bytlogoframe + 1
If (bytlogoframe > 20) Then bytlogoframe = 0
End If
dx = MAX_CX \ 2 - g_Objects.Title(bytlogoframe).cx \ 2
dy = -20
' update menu
Call BltFastGFX_HBM(dx, dy, g_Objects.Title(bytlogoframe))
'Call BltFastGFX_HBM(0, 0, g_Objects.menu)
End Sub
'///////////////////////////////////////////////////////////////
'//// Refresh main menu gfx and actions
'///////////////////////////////////////////////////////////////
Public Sub _
UpdateMainMenu()
Dim cn As Integer
Dim ltxtColor As Long
Dim lcnsttxtColor As Long
Dim ltxtselColor As Long
Dim ltxtbkColor As Long
Dim bytFontSize As Byte
' animation vars.
Dim bUpdateFrame As Boolean
Static lFPSTime As Long
Static bytlogoframe As Byte
' menu commands
Static bytMenuState As Byte
'Static nkeyX As Integer ' selection position
Static nkeySel As Integer
Static bSelected As Boolean ' user pressed Enter or MouseKey
' get input only if dialog box's not on the screen
Call CMouse.GetActions
Call mDirectInput.DICheckKeys
If (DIKeyState(DIK_F) = KS_KEYDOWN) Then
If (g_showFPS) Then g_showFPS = False Else g_showFPS = True
End If
If (DIKeyState(DIK_ESCAPE) = KS_KEYUP) Then bytMenuState = 4 'bRunning = False
If (DIKeyState(DIK_UP) = KS_KEYUP) Then
' move selection
nkeySel = nkeySel - 1
' play sound
Call DSPlaySound(g_dsSfx(SFX_MENUSELECT), False)
End If
If (DIKeyState(DIK_DOWN) = KS_KEYUP) Then
' move selection
nkeySel = nkeySel + 1
' play sound
Call DSPlaySound(g_dsSfx(SFX_MENUSELECT), False)
End If
' do color var. calcs
Static nrc As Integer
Static nv As Integer
If (nrc >= 50) Then nv = -1
If (nrc <= 0) Then nv = 1
nrc = nrc + nv
' do precalcs
ltxtColor = RGB(250 - (nrc * 4), 100 + (nrc * 2), 10) ' textcolor
lcnsttxtColor = RGB(250, 50, 10) ' constant textcolor
ltxtselColor = RGB(255, 255, 5) ' selection textcolor
ltxtbkColor = RGB(50, 50, 225) ' selection bk text color
bytFontSize = 28 ' letter font size
'bytmenustate 0 - main menu, 1 - options, 2-hall of fame, 3-help , 4-exit, 5-play opts.
' start music
If (Not g_bmusPlaying) Then
' stop space sound
Call mDirectSound.DSStopSound(g_dsSfx(SFX_SPACEMYST1), 0)
g_bmusPlaying = True
Call mFMod.PLAYmus(True)
End If
' check menu state
Select Case bytMenuState
' main menu
Case 0
' update right panel
Call UpdateInfoBox(1)
If (nkeySel > 5) Then nkeySel = 0
If (nkeySel < 0) Then nkeySel = 5
If (nkeySel = 0) Then ' start new game
Call GFXTextOut(lpBack, g_MenuPos(0).x, g_MenuPos(0).y, arText(MENU_START), bytFontSize, ltxtselColor, ltxtbkColor)
If (DIKeyState(DIK_RETURN) = KS_KEYUP) Then
bytMenuState = 5
Call DSPlaySound(g_dsSfx(SFX_MENUCHOICE), False)
End If
Else
Call GFXTextOut(lpBack, g_MenuPos(0).x, g_MenuPos(0).y, arText(MENU_START), bytFontSize, ltxtColor)
End If
If (nkeySel = 1) Then ' options
Call GFXTextOut(lpBack, g_MenuPos(1).x, g_MenuPos(1).y, arText(MENU_OPTIONS), bytFontSize, ltxtselColor, ltxtbkColor)
' selected
If (DIKeyState(DIK_RETURN) = KS_KEYDOWN) Then
bytMenuState = 1
Call DSPlaySound(g_dsSfx(SFX_MENUCHOICE), False)
End If
Else
Call GFXTextOut(lpBack, g_MenuPos(1).x, g_MenuPos(1).y, arText(MENU_OPTIONS), bytFontSize, ltxtColor)
End If
If (nkeySel = 2) Then ' hall of fame
Call GFXTextOut(lpBack, g_MenuPos(2).x, g_MenuPos(2).y, arText(MENU_HALLOFFAME), bytFontSize, ltxtselColor, ltxtbkColor)
If (DIKeyState(DIK_RETURN) = KS_KEYUP) Then
Call DSPlaySound(g_dsSfx(SFX_MENUCHOICE), False)
bytMenuState = 2
End If
Else
Call GFXTextOut(lpBack, g_MenuPos(2).x, g_MenuPos(2).y, arText(MENU_HALLOFFAME), bytFontSize, ltxtColor)
End If
If (nkeySel = 3) Then ' help
Call GFXTextOut(lpBack, g_MenuPos(3).x, g_MenuPos(3).y, arText(MENU_HELP), bytFontSize, ltxtselColor, ltxtbkColor)
If (DIKeyState(DIK_RETURN) = KS_KEYUP) Then
Call DSPlaySound(g_dsSfx(SFX_MENUCHOICE), False)
bytMenuState = 3
End If
Else
Call GFXTextOut(lpBack, g_MenuPos(3).x, g_MenuPos(3).y, arText(MENU_HELP), bytFontSize, ltxtColor)
End If
If (nkeySel = 4) Then ' replay intro
Call GFXTextOut(lpBack, g_MenuPos(4).x, g_MenuPos(4).y, arText(MENU_INTRO), bytFontSize, ltxtselColor, ltxtbkColor)
'If (bSelected) Then bytMenuState = 4
If (DIKeyState(DIK_RETURN) = KS_KEYUP) Then
mFMod.STOPmus
g_GameState = GAMSTATE_INTRO
Call DSPlaySound(g_dsSfx(SFX_MENUCHOICE), False)
End If
Else
Call GFXTextOut(lpBack, g_MenuPos(4).x, g_MenuPos(4).y, arText(MENU_INTRO), bytFontSize, ltxtColor)
End If
If (nkeySel = 5) Then ' exit
Call GFXTextOut(lpBack, g_MenuPos(5).x, g_MenuPos(5).y, arText(MENU_EXIT), bytFontSize, ltxtselColor, ltxtbkColor)
'If (bSelected) Then bytMenuState = 4
If (DIKeyState(DIK_RETURN) = KS_KEYUP) Then
bytMenuState = 4
Call DSPlaySound(g_dsSfx(SFX_MENUCHOICE), False)
End If
Else
Call GFXTextOut(lpBack, g_MenuPos(5).x, g_MenuPos(5).y, arText(MENU_EXIT), bytFontSize, ltxtColor)
End If
' options
Case 1
' update right panel
Call UpdateInfoBox(1)
If (nkeySel > 5) Then nkeySel = 0
If (nkeySel < 0) Then nkeySel = 5
If (nkeySel = 0) Then ' calibrate gamma
If ((Not bGamma)) Then
nkeySel = nkeySel + 1
Call GFXTextOut(lpBack, g_MenuPos(0).x, g_MenuPos(0).y, arText(MENU_GAMMAUNAVAILABLE), bytFontSize, RGB(&HAA, &HAA, &HAA))
'Exit Sub
End If ' else do normal gamma-text blit
Call GFXTextOut(lpBack, g_MenuPos(0).x, g_MenuPos(0).y, arText(MENU_GAMMA), bytFontSize, ltxtselColor, ltxtbkColor)
' gamma down
If (DIKeyState(DIK_LEFT) = KS_KEYUP) Then
m_gfxGammaRGB.r = m_gfxGammaRGB.r - 5
If (m_gfxGammaRGB.r < -20) Then m_gfxGammaRGB.r = -20
m_gfxGammaRGB.G = m_gfxGammaRGB.G - 5
If (m_gfxGammaRGB.G < -20) Then m_gfxGammaRGB.G = -20
m_gfxGammaRGB.B = m_gfxGammaRGB.B - 5
If (m_gfxGammaRGB.B < -20) Then m_gfxGammaRGB.B = -20
' set new vals
Call mDirectDraw.DDSetGamma(m_gfxGammaRGB.r, m_gfxGammaRGB.G, m_gfxGammaRGB.B)
'' play calb. sound
'Call DSPlaySound(g_dsSfx(SFX_MENUCALIBRATE), False)
End If
' gamma up
If (DIKeyState(DIK_RIGHT) = KS_KEYUP) Then
m_gfxGammaRGB.r = m_gfxGammaRGB.r + 5
If (m_gfxGammaRGB.r > 20) Then m_gfxGammaRGB.r = 20
m_gfxGammaRGB.G = m_gfxGammaRGB.G + 5
If (m_gfxGammaRGB.G > 20) Then m_gfxGammaRGB.G = 20
m_gfxGammaRGB.B = m_gfxGammaRGB.B + 5
If (m_gfxGammaRGB.B > 20) Then m_gfxGammaRGB.B = 20
' set new vals
Call mDirectDraw.DDSetGamma(m_gfxGammaRGB.r, m_gfxGammaRGB.G, m_gfxGammaRGB.B)
'' play calb. sound
'Call DSPlaySound(g_dsSfx(SFX_MENUCALIBRATE), False)
End If
Else
If ((Not bGamma)) Then
Call GFXTextOut(lpBack, g_MenuPos(0).x, g_MenuPos(0).y, arText(MENU_GAMMAUNAVAILABLE), bytFontSize, RGB(&HAA, &HAA, &HAA))
Else
Call GFXTextOut(lpBack, g_MenuPos(0).x, g_MenuPos(0).y, arText(MENU_GAMMA), bytFontSize, ltxtColor)
End If
End If
If (nkeySel = 1) Then ' set sound vol.
Call GFXTextOut(lpBack, g_MenuPos(1).x, g_MenuPos(1).y, arText(MENU_SOUND), bytFontSize, ltxtselColor, ltxtbkColor)
' volume down
If (DIKeyState(DIK_LEFT) = KS_KEYDOWN) Then
mDirectSound.m_nGlobalVol = mDirectSound.m_nGlobalVol - 20
If (m_nGlobalVol < SFX_VOLUMEMIN) Then m_nGlobalVol = SFX_VOLUMEMIN
Call DSPlaySound(g_dsSfx(SFX_MENUCALIBRATE), False)
End If
' volume up
If (DIKeyState(DIK_RIGHT) = KS_KEYDOWN) Then
mDirectSound.m_nGlobalVol = mDirectSound.m_nGlobalVol + 20
If (m_nGlobalVol > SFX_VOLUMEMAX) Then m_nGlobalVol = SFX_VOLUMEMAX
Call DSPlaySound(g_dsSfx(SFX_MENUCALIBRATE), False)
End If
Else
Call GFXTextOut(lpBack, g_MenuPos(1).x, g_MenuPos(1).y, arText(MENU_SOUND), bytFontSize, ltxtColor)
End If
If (nkeySel = 2) Then ' set music vol.
Call GFXTextOut(lpBack, g_MenuPos(2).x, g_MenuPos(2).y, arText(MENU_MUSIC), bytFontSize, ltxtselColor, ltxtbkColor)
' volume down
If (DIKeyState(DIK_LEFT) = KS_KEYDOWN) Then
g_nMusicVol = g_nMusicVol - 1
If (g_nMusicVol < MUSIC_VOLUMEMIN) Then g_nMusicVol = MUSIC_VOLUMEMIN
' set FMOD music volume
Call mFMod.VOLUMEmus(g_nMusicVol)
End If
' volume up
If (DIKeyState(DIK_RIGHT) = KS_KEYDOWN) Then
g_nMusicVol = g_nMusicVol + 1
If (g_nMusicVol > MUSIC_VOLUMEMAX) Then g_nMusicVol = MUSIC_VOLUMEMAX
' set FMOD music volume
Call mFMod.VOLUMEmus(g_nMusicVol)
End If
Else
Call GFXTextOut(lpBack, g_MenuPos(2).x, g_MenuPos(2).y, arText(MENU_MUSIC), bytFontSize, ltxtColor)
End If
If (nkeySel = 3) Then ' VSync On/Off
If (g_bNotRetrace) Then
Call GFXTextOut(lpBack, g_MenuPos(3).x, g_MenuPos(3).y, arText(MENU_VSYNCOFF), bytFontSize, ltxtselColor, ltxtbkColor)
Else
Call GFXTextOut(lpBack, g_MenuPos(3).x, g_MenuPos(3).y, arText(MENU_VSYNCON), bytFontSize, ltxtselColor, ltxtbkColor)
End If
' user pressed enter
If (DIKeyState(DIK_RETURN) = KS_KEYUP) Then
If (g_bNotRetrace) Then g_bNotRetrace = False _
Else g_bNotRetrace = True
' play on/off soud
Call DSPlaySound(g_dsSfx(SFX_MENUCALIBRATE), False)
End If
Else
If (g_bNotRetrace) Then
Call GFXTextOut(lpBack, g_MenuPos(3).x, g_MenuPos(3).y, arText(MENU_VSYNCOFF), bytFontSize, ltxtColor)
Else
Call GFXTextOut(lpBack, g_MenuPos(3).x, g_MenuPos(3).y, arText(MENU_VSYNCON), bytFontSize, ltxtColor)
End If
End If
If (nkeySel = 4) Then ' Solid Health Bars
If (g_bsolidbars) Then
Call GFXTextOut(lpBack, g_MenuPos(4).x, g_MenuPos(4).y, arText(MENU_SOLIDBARSON), bytFontSize, ltxtselColor, ltxtbkColor)
Else
Call GFXTextOut(lpBack, g_MenuPos(4).x, g_MenuPos(4).y, arText(MENU_SOLIDBARSOFF), bytFontSize, ltxtselColor, ltxtbkColor)
End If
If (DIKeyState(DIK_RETURN) = KS_KEYUP) Then
Call DSPlaySound(g_dsSfx(SFX_MENUCALIBRATE), False)
If (g_bsolidbars) Then g_bsolidbars = False Else g_bsolidbars = True
End If
Else
If (g_bsolidbars) Then
Call GFXTextOut(lpBack, g_MenuPos(4).x, g_MenuPos(4).y, arText(MENU_SOLIDBARSON), bytFontSize, ltxtColor)
Else
Call GFXTextOut(lpBack, g_MenuPos(4).x, g_MenuPos(4).y, arText(MENU_SOLIDBARSOFF), bytFontSize, ltxtColor)
End If
End If
If (nkeySel = 5) Then ' back
Call GFXTextOut(lpBack, g_MenuPos(5).x, g_MenuPos(5).y, arText(MENU_BACK), bytFontSize, ltxtselColor, ltxtbkColor)
' return to main menu mode
If (DIKeyState(DIK_RETURN) = KS_KEYUP) Then
Call DSPlaySound(g_dsSfx(SFX_MENUCHOICE), False)
bytMenuState = 0
End If
Else
Call GFXTextOut(lpBack, g_MenuPos(5).x, g_MenuPos(5).y, arText(MENU_BACK), bytFontSize, ltxtColor)
End If
' blit status bars
' gamma ramp
If (bGamma) Then
Call BltFastGFX_HBM(g_MenuPos(0).x + 100, g_MenuPos(0).y + 10, g_Objects.caline)
cn = ((m_gfxGammaRGB.r) + 50) '+ (Sgn(m_gfxGammaRGB.R) * 30)
Call BltFastGFX_HBM(g_MenuPos(0).x + 100 + cn, g_MenuPos(0).y + 8, g_Objects.seline)
End If
' sound fx
Call BltFastGFX_HBM(g_MenuPos(1).x + 100, g_MenuPos(1).y + 10, g_Objects.caline)
cn = 100 + ((mDirectSound.m_nGlobalVol) / 100)
Call BltFastGFX_HBM(g_MenuPos(1).x + 100 + cn, g_MenuPos(1).y + 8, g_Objects.seline)
' music
Call BltFastGFX_HBM(g_MenuPos(2).x + 100, g_MenuPos(2).y + 10, g_Objects.caline)
cn = 100 + (g_nMusicVol - MUSIC_VOLUMEMAX)
Call BltFastGFX_HBM(g_MenuPos(2).x + 100 + cn, g_MenuPos(2).y + 8, g_Objects.seline)
' hall of fame
Case 2
' update infobox (right panel)
Call UpdateInfoBox(2)
If (nkeySel > 0 Or nkeySel < 0) Then nkeySel = 0
If (nkeySel = 0) Then ' back