forked from LegendsUnchained/vpx-standalone-alp4k
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkylab (Williams 1974).vbs
2191 lines (1908 loc) · 60.2 KB
/
Skylab (Williams 1974).vbs
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
' ******************************************************************
' VPX7 - version by Klodo81 2023, Skylab version 1.3
'
' VISUAL PINBALL X EM Script Based on
' JPSalas Basic EM script up to 4 players
' JPSalas Physics 4.3.0
'
' Skylab / IPD No.2202 / June 14, 1974 / 1 Player
'
'Version 1.1
' - Added rolling sound
'
'Version 1.2
' - "Balls To Play" on the Backglass counting down rather than up
' - HorseshoeTimer must be disabled by default to have 2/3 balls instead of 0/5 balls in Horseshoe
' - If 100000 Lit, it stay lit until attrack mode stop
'
'Version 1.3
' - Added Playfield Mesh
' - Updated sound files fx_ballrolling2 to 7 as ballrolling1
' - Some others things
' ******************************************************************
Option Explicit
Randomize
' DOF config
'
' Flippers L/R - 101/102
' Slingshots L/R - 103/104
' Bumpers L to R - 105/106
' Triggers - 201 to 208
' Knocker - 110
' Chimes - 301/302/303
' Drain - 250
' Bonus - 210
' core.vbs constants
Const BallSize = 50 ' 50 is the normal size
Const BallMass = 1 ' 1 is the normal ball mass.
' load extra vbs files
LoadCoreFiles
Sub LoadCoreFiles
On Error Resume Next
ExecuteGlobal GetTextFile("core.vbs")
If Err Then MsgBox "Can't open core.vbs"
On Error Resume Next
ExecuteGlobal GetTextFile("controller.vbs")
If Err Then MsgBox "Can't open controller.vbs"
End Sub
'****************** Options you can change *******************
Const BallsPerGame = 5 ' to play with 3 or 5 balls
Const AttractMode = 1 ' 0 = no attract mode
Const FreePlay = False ' Free play or coins
'*************************************************************
' Constants
Const TableName = "Skylab_74VPX" ' file name to save highscores and other variables
Const cGameName = "Skylab1974" ' B2S name
Const MaxPlayers = 1 ' Only 1 can play
Const MaxMultiplier = 2 ' limit bonus multiplier
Const Special1 = 73000 ' 3 Balls award credit
Const Special2 = 94000 ' 3 Balls award credit
Const Special3 = 137000 ' 5 Balls award credit
Const Special4 = 178000 ' 5 Balls award credit
' Global variables
Dim PlayersPlayingGame
Dim CurrentPlayer
Dim Credits
Dim Bonus
Dim BallsRemaining(4)
Dim BonusMultiplier
Dim ExtraBallsAwards(4)
Dim Special1Awarded(4)
Dim Special2Awarded(4)
Dim Special3Awarded(4)
Dim Special4Awarded(4)
Dim Score(4)
Dim HighScore
Dim Match
Dim Tilt
Dim TiltSensitivity
Dim Tilted
Dim Add10
Dim Add100
Dim Add1000
Dim Add10000
Dim CBonus
Dim x
Dim LeftBalls, RightBalls
' Control variables
Dim BallsOnPlayfield
' Boolean variables
Dim bAttractMode
Dim bFreePlay
Dim bGameInPlay
Dim bOnTheFirstBall
Dim bExtraBallWonThisBall
Dim bJustStarted
Dim bBallInPlungerLane
Dim bBallSaverActive
' core.vbs variables
' *********************************************************************
' Common rutines to all the tables
' *********************************************************************
Sub Table1_Init()
Dim x
' Init som objects, like walls, targets
VPObjects_Init
LoadEM
' load highscores and credits
Loadhs
If HSScore(1) >= 100000 Then
RolloverReel1.setvalue 1
ScoreReel1.SetValue (HSScore(1) - 100000)
Else
ScoreReel1.SetValue HSScore(1)
End If
If B2SOn then
If HSScore(1) >= 100000 then
Controller.B2SSetScoreRolloverPlayer1 1
Controller.B2SSetScorePlayer 1, (HSScore(1) - 100000)
Else
Controller.B2SSetScorePlayer 1, HSScore(1)
end if
end if
UpdateCredits
' init all the global variables
bFreePlay = FreePlay
bAttractMode = False
bOnTheFirstBall = False
bGameInPlay = False
bBallInPlungerLane = False
BallsOnPlayfield = 0
Tilt = 0
TiltSensitivity = 6
Tilted = False
Match = 0
bJustStarted = True
Add10 = 0
Add100 = 0
Add1000 = 0
Add10000 = 0
' select Card instruction on Apron
If BallsPerGame = 3 Then
Flasher3balls.visible = 1
Flasher5balls.visible = 0
Else 'BallsPerGame = 5
Flasher3balls.visible = 0
Flasher5balls.visible = 1
End If
'Test position Match on desktop screen
'Match = 90 '(00 to 90)
'Display_Match
' setup table in game over mode
EndOfGame
'turn on GI lights
vpmtimer.addtimer 1000, "GiOn '"
' Remove desktop items in FS mode
If Table1.ShowDT then
For each x in aReels
x.Visible = 1
Next
Else
For each x in aReels
x.Visible = 0
Next
End If
' LUT
LoadLUT
'Init Horseshoe
leftballs=2
rightballs=3
KcaptiveL.uservalue=1
KcaptiveL.timerenabled=1
End Sub
' **************
' Horseshoe
' **************
Sub KcaptiveL_timer 'create 5 new balls in the horseshoe
Select Case (me.uservalue)
Case 1:
if leftballs>0 then
KcaptiveL.createball
KcaptiveL.kick 180,1
end if
if rightballs>0 then
KcaptiveR.createball
kcaptiveR.kick 180,1
end if
Case 2:
if leftballs>1 then
KcaptiveL.createball
KcaptiveL.kick 180,1
end if
if rightballs>1 then
KcaptiveR.createball
kcaptiveR.kick 180,1
end if
Case 3:
if leftballs>2 then
KcaptiveL.createball
KcaptiveL.kick 180,1
end if
if rightballs>2 then
KcaptiveR.createball
kcaptiveR.kick 180,1
end if
Case 4:
if leftballs>3 then
KcaptiveL.createball
KcaptiveL.kick 180,1
end if
if rightballs>3 then
KcaptiveR.createball
kcaptiveR.kick 180,1
end if
Case 5:
if leftballs>4 then
KcaptiveL.createball
KcaptiveL.kick 180,1
end if
if rightballs>4 then
KcaptiveR.createball
kcaptiveR.kick 180,1
end if
Case 6:
me.timerenabled=0
HorseshoeTimer.enabled=1
End Select
me.uservalue=me.uservalue+1
end sub
Sub HorseshoeTimer_timer 'track balls number on leftballs and RightBalls
select case (TGcaptiveL.BallCntOver+TGcaptiveL1.BallCntOver+TGcaptiveL2.BallCntOver)
Case 0:
LeftBalls=0
RightBalls=5
Case 1:
select case (TGcaptiveR.BallCntOver+TGcaptiveR1.BallCntOver+TGcaptiveR2.BallCntOver)
Case 2:
LeftBalls=2
RightBalls=3
Case 3:
LeftBalls=1
RightBalls=4
end Select
case 2:
LeftBalls=3
RightBalls=2
Case 3:
select case (TGcaptiveR.BallCntOver)
Case 0:
LeftBalls=5
RightBalls=0
Case 1:
LeftBalls=4
RightBalls=1
end Select
end Select
end sub
'******
' Keys
'******
Sub Table1_KeyDown(ByVal Keycode)
If EnteringInitials then
CollectInitials(keycode)
Exit Sub
End If
If keycode = LeftMagnaSave Then bLutActive = True:SetLUTLine "Color LUT image " & table1.ColorGradeImage
If keycode = RightMagnaSave AND bLutActive Then NextLUT:End If
' add coins
If Keycode = AddCreditKey Then
If(Tilted = False) Then
AddCredits 1
PlaySound "fx_coin"
End If
End If
' plunger
If keycode = PlungerKey Then
Plunger.Pullback
PlaySoundAt "fx_plungerpull", plunger
End If
' tilt keys
If keycode = LeftTiltKey Then Nudge 90, 5:PlaySound "fx_nudge", 0, 1, -0.1, 0.25:CheckTilt
If keycode = RightTiltKey Then Nudge 270, 5:PlaySound "fx_nudge", 0, 1, 0.1, 0.25:CheckTilt
If keycode = CenterTiltKey Then Nudge 0, 6:PlaySound "fx_nudge", 0, 1, 1, 0.25:CheckTilt
' keys during game
If bGameInPlay AND NOT Tilted Then
If keycode = LeftFlipperKey Then SolLFlipper 1
If keycode = RightFlipperKey Then SolRFlipper 1
If keycode = StartGameKey Then
If((PlayersPlayingGame <MaxPlayers) AND(bOnTheFirstBall = True) ) Then
If(bFreePlay = True) Then
PlayersPlayingGame = PlayersPlayingGame + 1
UpdateBallsToPlay
UpdatePlayers
Else
If(Credits> 0) then
PlayersPlayingGame = PlayersPlayingGame + 1
Credits = Credits - 1
UpdateCredits
UpdateBallsToPlay
UpdatePlayers
Playsound"BallyStartButtonPlayers2-4 plus 10dB"
End If
End If
End If
End If
Else ' (GameInPlay)
If keycode = StartGameKey Then
If(bFreePlay = True) Then
If(BallsOnPlayfield = 0) Then
ResetScores
ResetForNewGame()
End If
Else
If(Credits> 0) Then
If(BallsOnPlayfield = 0) Then
Credits = Credits - 1
UpdateCredits
ResetScores
ResetForNewGame()
Playsound"BallyStartButtonPlayer1+3dB"
End If
End If
End If
End If
End If
End Sub
Sub Table1_KeyUp(ByVal keycode)
If EnteringInitials then
Exit Sub
End If
If keycode = LeftMagnaSave Then bLutActive = False:HideLUT
If bGameInPlay AND NOT Tilted Then
If keycode = LeftFlipperKey Then SolLFlipper 0
If keycode = RightFlipperKey Then SolRFlipper 0
End If
If keycode = PlungerKey Then
Plunger.Fire
If bBallInPlungerLane Then
PlaySoundAt "fx_plunger", plunger
Else
PlaySoundAt "fx_plunger_empty", plunger
End If
End If
End Sub
'******************
' Table stop/pause
'******************
Sub table1_Paused
End Sub
Sub table1_unPaused
End Sub
Sub table1_Exit
Savehs
'Controller.Stop
End Sub
'************************************
' LUT - Darkness control
' 10 normal level & 10 warmer levels
'************************************
Dim bLutActive, LUTImage
Sub LoadLUT
Dim x
bLutActive = False
x = LoadValue(cGameName, "LUTImage")
If(x <> "") Then LUTImage = x Else LUTImage = 0
UpdateLUT
End Sub
Sub SaveLUT
SaveValue cGameName, "LUTImage", LUTImage
End Sub
Sub NextLUT:LUTImage = (LUTImage + 1) MOD 22:UpdateLUT:SaveLUT:SetLUTLine "Color LUT image " & table1.ColorGradeImage:End Sub
Sub UpdateLUT
Select Case LutImage
Case 0:table1.ColorGradeImage = "LUT0"
Case 1:table1.ColorGradeImage = "LUT1"
Case 2:table1.ColorGradeImage = "LUT2"
Case 3:table1.ColorGradeImage = "LUT3"
Case 4:table1.ColorGradeImage = "LUT4"
Case 5:table1.ColorGradeImage = "LUT5"
Case 6:table1.ColorGradeImage = "LUT6"
Case 7:table1.ColorGradeImage = "LUT7"
Case 8:table1.ColorGradeImage = "LUT8"
Case 9:table1.ColorGradeImage = "LUT9"
Case 10:table1.ColorGradeImage = "LUT10"
Case 11:table1.ColorGradeImage = "LUT Warm 0"
Case 12:table1.ColorGradeImage = "LUT Warm 1"
Case 13:table1.ColorGradeImage = "LUT Warm 2"
Case 14:table1.ColorGradeImage = "LUT Warm 3"
Case 15:table1.ColorGradeImage = "LUT Warm 4"
Case 16:table1.ColorGradeImage = "LUT Warm 5"
Case 17:table1.ColorGradeImage = "LUT Warm 6"
Case 18:table1.ColorGradeImage = "LUT Warm 7"
Case 19:table1.ColorGradeImage = "LUT Warm 8"
Case 20:table1.ColorGradeImage = "LUT Warm 9"
Case 21:table1.ColorGradeImage = "LUT Warm 10"
End Select
End Sub
' New LUT postit
Sub SetLUTLine(String)
Dim Index
Dim xFor
Index = 1
LUBack.imagea = "PostItNote"
String = CL2(String)
For xFor = 1 to 40
Eval("LU" &xFor).imageA = GetHSChar(String, Index)
Index = Index + 1
Next
End Sub
Sub HideLUT
SetLUTLine ""
LUBack.imagea = "PostitBL"
End Sub
Function CL2(NumString) 'center line
Dim Temp, TempStr
If Len(NumString)> 40 Then NumString = Left(NumString, 40)
Temp = (40 - Len(NumString) ) \ 2
TempStr = Space(Temp) & NumString & Space(Temp)
CL2 = TempStr
End Function
'**********************************************
' Flipper adjustments - enable tricks
' by JLouLouLou
'**********************************************
Dim FlipperPower
Dim FlipperElasticity
Dim SOSTorque, SOSAngle
Dim FullStrokeEOS_Torque, LiveStrokeEOS_Torque
Dim LeftFlipperOn
Dim RightFlipperOn
Dim LLiveCatchTimer
Dim RLiveCatchTimer
Dim LiveCatchSensivity
FlipperPower = 5000
FlipperElasticity = 0.85
FullStrokeEOS_Torque = 0.3 ' EOS Torque when flipper hold up ( EOS Coil is fully charged. Ampere increase due to flipper can't move or when it pushed back when "On". EOS Coil have more power )
LiveStrokeEOS_Torque = 0.2 ' EOS Torque when flipper rotate to end ( When flipper move, EOS coil have less Ampere due to flipper can freely move. EOS Coil have less power )
LeftFlipper.EOSTorqueAngle = 10
RightFlipper.EOSTorqueAngle = 10
SOSTorque = 0.1
SOSAngle = 6
LiveCatchSensivity = 10
LLiveCatchTimer = 0
RLiveCatchTimer = 0
LeftFlipper.TimerInterval = 1
LeftFlipper.TimerEnabled = 1
Sub LeftFlipper_Timer 'flipper's tricks timer
'Start Of Stroke Flipper Stroke Routine : Start of Stroke for Tap pass and Tap shoot
If LeftFlipper.CurrentAngle >= LeftFlipper.StartAngle - SOSAngle Then LeftFlipper.Strength = FlipperPower * SOSTorque else LeftFlipper.Strength = FlipperPower : End If
'End Of Stroke Routine : Livecatch and Emply/Full-Charged EOS
If LeftFlipperOn = 1 Then
If LeftFlipper.CurrentAngle = LeftFlipper.EndAngle then
LeftFlipper.EOSTorque = FullStrokeEOS_Torque
LLiveCatchTimer = LLiveCatchTimer + 1
If LLiveCatchTimer < LiveCatchSensivity Then
LeftFlipper.Elasticity = 0
Else
LeftFlipper.Elasticity = FlipperElasticity
LLiveCatchTimer = LiveCatchSensivity
End If
End If
Else
LeftFlipper.Elasticity = FlipperElasticity
LeftFlipper.EOSTorque = LiveStrokeEOS_Torque
LLiveCatchTimer = 0
End If
'Start Of Stroke Flipper Stroke Routine : Start of Stroke for Tap pass and Tap shoot
If RightFlipper.CurrentAngle <= RightFlipper.StartAngle + SOSAngle Then RightFlipper.Strength = FlipperPower * SOSTorque else RightFlipper.Strength = FlipperPower : End If
'End Of Stroke Routine : Livecatch and Emply/Full-Charged EOS
If RightFlipperOn = 1 Then
If RightFlipper.CurrentAngle = RightFlipper.EndAngle Then
RightFlipper.EOSTorque = FullStrokeEOS_Torque
RLiveCatchTimer = RLiveCatchTimer + 1
If RLiveCatchTimer < LiveCatchSensivity Then
RightFlipper.Elasticity = 0
Else
RightFlipper.Elasticity = FlipperElasticity
RLiveCatchTimer = LiveCatchSensivity
End If
End If
Else
RightFlipper.Elasticity = FlipperElasticity
RightFlipper.EOSTorque = LiveStrokeEOS_Torque
RLiveCatchTimer = 0
End If
End Sub
'*******************
' Flipper Subs
'*******************
Sub SolLFlipper(Enabled)
If Enabled Then
PlaySoundAt SoundFXDOF ("LeftflipperupH-2dB", 101, DOFOn, DOFFlippers), LeftFlipper
LeftFlipper.RotateToEnd
LeftFlipperOn = 1
Else
PlaySoundAt SoundFXDOF ("LeftflipperdownH", 101, DOFOff, DOFFlippers), LeftFlipper
LeftFlipper.RotateToStart
LeftFlipperOn = 0
End If
End Sub
Sub SolRFlipper(Enabled)
If Enabled Then
PlaySoundAt SoundFXDOF ("RightflipperupH-2dB", 102, DOFOn, DOFFlippers), RightFlipper
RightFlipper.RotateToEnd
RightFlipperOn = 1
Else
PlaySoundAt SoundFXDOF ("RightflipperdownH", 102, DOFOff, DOFFlippers), RightFlipper
RightFlipper.RotateToStart
RightFlipperOn = 0
End If
End Sub
Sub LeftFlipper_Collide(parm)
PlaySound "fx_rubber_flipper", 0, parm / 60, pan(ActiveBall), 0.2, 0, 0, 0, AudioFade(ActiveBall)
End Sub
Sub RightFlipper_Collide(parm)
PlaySound "fx_rubber_flipper", 0, parm / 60, pan(ActiveBall), 0.2, 0, 0, 0, AudioFade(ActiveBall)
End Sub
'*******************
' GI lights
'*******************
Sub GiOn 'GI lights on
Dim bulb
PlaySound "fx_gion"
For each bulb in aGiLights
bulb.State = 1
Next
End Sub
Sub GiOff 'GI lights off
Dim bulb
PlaySound "fx_gioff"
For each bulb in aGiLights
bulb.State = 0
Next
End Sub
'**************
' TILT
'**************
Sub CheckTilt
Tilt = Tilt + TiltSensitivity
TiltDecreaseTimer.Enabled = True
If Tilt> 15 Then
Tilted = True
TiltReel.SetValue 1
If B2SOn then
Controller.B2SSetTilt 1
end if
DisableTable True
'BallsRemaining(CurrentPlayer) = 0 'player looses the game
TiltRecoveryTimer.Enabled = True 'wait for all the balls to drain
End If
End Sub
Sub TiltDecreaseTimer_Timer
' DecreaseTilt
If Tilt> 0 Then
Tilt = Tilt - 0.1
Else
TiltDecreaseTimer.Enabled = False
End If
End Sub
Sub DisableTable(Enabled)
If Enabled Then
GiOff
'Disable slings, bumpers etc
LeftFlipper.RotateToStart
RightFlipper.RotateToStart
Bumper001.Threshold = 100
Bumper002.Threshold = 100
LeftSlingshot.Disabled = 1
RightSlingshot.Disabled = 1
Else
GiOn
Bumper001.Threshold = 1
Bumper002.Threshold = 1
LeftSlingshot.Disabled = 0
RightSlingshot.Disabled = 0
End If
End Sub
Sub TiltRecoveryTimer_Timer()
' all the balls have drained ..
If(BallsOnPlayfield = 0) Then
EndOfBall
TiltRecoveryTimer.Enabled = False
End If
' otherwise repeat
End Sub
'***************************************************************
' Supporting Ball & Sound Functions v4.0
' includes random pitch in PlaySoundAt and PlaySoundAtBall
'***************************************************************
Dim TableWidth, TableHeight
TableWidth = Table1.width
TableHeight = Table1.height
Function Vol(ball) ' Calculates the Volume of the sound based on the ball speed
Vol = Csng(BallVel(ball) ^2 / 2000)
End Function
Function Pan(ball) ' Calculates the pan for a ball based on the X position on the table. "table1" is the name of the table
Dim tmp
tmp = ball.x * 2 / TableWidth-1
If tmp > 0 Then
Pan = Csng(tmp ^10)
Else
Pan = Csng(-((- tmp) ^10))
End If
End Function
Function Pitch(ball) ' Calculates the pitch of the sound based on the ball speed
Pitch = BallVel(ball) * 20
End Function
Function BallVel(ball) 'Calculates the ball speed
BallVel = (SQR((ball.VelX ^2) + (ball.VelY ^2)))
End Function
Function AudioFade(ball) 'only on VPX 10.4 and newer
Dim tmp
tmp = ball.y * 2 / TableHeight-1
If tmp > 0 Then
AudioFade = Csng(tmp ^10)
Else
AudioFade = Csng(-((- tmp) ^10))
End If
End Function
Sub PlaySoundAt(soundname, tableobj) 'play sound at X and Y position of an object, mostly bumpers, flippers and other fast objects
PlaySound soundname, 0, 1, Pan(tableobj), 0.2, 0, 0, 0, AudioFade(tableobj)
End Sub
Sub PlaySoundAtBall(soundname) ' play a sound at the ball position, like rubbers, targets, metals, plastics
PlaySound soundname, 0, Vol(ActiveBall), pan(ActiveBall), 0.2, Pitch(ActiveBall) * 10, 0, 0, AudioFade(ActiveBall)
End Sub
Function RndNbr(n) 'returns a random number between 1 and n
Randomize timer
RndNbr = Int((n * Rnd) + 1)
End Function
'***********************************
' JP's VP10 Rolling Sounds v4.0
' JP's Ball Shadows
' JP's Ball Speed Control
' Rothbauer's dropping sounds
'***********************************
Const tnob = 19 'total number of balls
Const lob = 0 'number of locked balls
Const maxvel = 28 'max ball velocity
ReDim rolling(tnob)
InitRolling
Sub InitRolling
Dim i
For i = 0 to tnob
rolling(i) = False
Next
End Sub
Sub RollingUpdate() 'call this routine from any realtime timer you may have, running at an interval of 10 is good.
Dim BOT, b, ballpitch, ballvol, speedfactorx, speedfactory
BOT = GetBalls
' stop the sound of deleted balls and hide the shadow
For b = UBound(BOT) + 1 to tnob
rolling(b) = False
StopSound("fx_ballrolling" & b)
aBallShadow(b).Y = 2100 'under the apron 'may differ from table to table
Next
' exit the sub if no balls on the table
If UBound(BOT) = lob - 1 Then Exit Sub 'there no extra balls on this table
' draw the ball shadow
For b = lob to UBound(BOT)
aBallShadow(b).X = BOT(b).X
aBallShadow(b).Y = BOT(b).Y
aBallShadow(b).Height = BOT(b).Z - Ballsize / 2 + 1
'play the rolling sound for each ball
If BallVel(BOT(b)) > 1 Then
If BOT(b).z < 30 Then
ballpitch = Pitch(BOT(b))
ballvol = Vol(BOT(b))
Else
ballpitch = Pitch(BOT(b)) + 50000 'increase the pitch on a ramp
ballvol = Vol(BOT(b)) * 5
End If
rolling(b) = True
PlaySound("fx_ballrolling" & b), -1, ballvol, Pan(BOT(b)), 0, ballpitch, 1, 0, AudioFade(BOT(b))
Else
If rolling(b) = True Then
StopSound("fx_ballrolling" & b)
rolling(b) = False
End If
End If
' rothbauerw's Dropping Sounds
If BOT(b).VelZ < -1 and BOT(b).z < 55 and BOT(b).z > 27 Then 'height adjust for ball drop sounds
PlaySound "fx_balldrop", 0, ABS(BOT(b).velz) / 17, Pan(BOT(b)), 0, Pitch(BOT(b)), 1, 0, AudioFade(BOT(b))
End If
' jps ball speed control
If BOT(b).VelX AND BOT(b).VelY <> 0 Then
speedfactorx = ABS(maxvel / BOT(b).VelX)
speedfactory = ABS(maxvel / BOT(b).VelY)
If speedfactorx < 1 Then
BOT(b).VelX = BOT(b).VelX * speedfactorx
BOT(b).VelY = BOT(b).VelY * speedfactorx
End If
If speedfactory < 1 Then
BOT(b).VelX = BOT(b).VelX * speedfactory
BOT(b).VelY = BOT(b).VelY * speedfactory
End If
End If
Next
End Sub
'**********************
' Ball Collision Sound
'**********************
Sub OnBallBallCollision(ball1, ball2, velocity)
PlaySound("fx_collide"), 0, Csng(velocity) ^2 / 2000, Pan(ball1), 0, Pitch(ball1), 0, 0, AudioFade(ball1)
End Sub
'***************************************
' Collection collision sounds
'***************************************
Sub aMetals_Hit(idx):PlaySoundAtBall "fx_MetalHit":End Sub
Sub aMetalWires_Hit(idx):PlaySoundAtBall "fx_MetalWire":End Sub
Sub aRubber_Bands_Hit(idx):PlaySoundAtBall "fx_rubber_band":End Sub
Sub aRubber_Posts_Hit(idx):PlaySoundAtBall "fx_rubber_post":End Sub
Sub aRubber_Pins_Hit(idx):PlaySoundAtBall "fx_rubber_pin":End Sub
Sub aPlastics_Hit(idx):PlaySoundAtBall "fx_PlasticHit":End Sub
Sub aGates_Hit(idx):PlaySoundAtBall "fx_Gate":End Sub
Sub aWoods_Hit(idx):PlaySoundAtBall "fx_Woodhit":End Sub
'***************************************************************************************************
' Only for VPX 10.2 and higher.
' FlashForMs will blink light or a flasher for TotalPeriod(ms) at rate of BlinkPeriod(ms)
' When TotalPeriod done, light or flasher will be set to FinalState value where
' Final State values are: 0=Off, 1=On, 2=Return to previous State
'***************************************************************************************************
Sub FlashForMs(MyLight, TotalPeriod, BlinkPeriod, FinalState)
If TypeName(MyLight) = "Light" Then
If FinalState = 2 Then
FinalState = MyLight.State
End If
MyLight.BlinkInterval = BlinkPeriod
MyLight.Duration 2, TotalPeriod, FinalState
ElseIf TypeName(MyLight) = "Flasher" Then
Dim steps
' Store all blink information
steps = Int(TotalPeriod / BlinkPeriod + .5)
If FinalState = 2 Then
FinalState = ABS(MyLight.Visible)
End If
MyLight.UserValue = steps * 10 + FinalState
MyLight.TimerInterval = BlinkPeriod
MyLight.TimerEnabled = 0
MyLight.TimerEnabled = 1
ExecuteGlobal "Sub " & MyLight.Name & "_Timer:" & "Dim tmp, steps, fstate:tmp=me.UserValue:fstate = tmp MOD 10:steps= tmp\10 -1:Me.Visible = steps MOD 2:me.UserValue = steps *10 + fstate:If Steps = 0 then Me.Visible = fstate:Me.TimerEnabled=0:End if:End Sub"
End If
End Sub
'****************************************
' Init table for a new game
'****************************************
Sub ResetForNewGame()
'debug.print "ResetForNewGame"
Dim i
bGameInPLay = True
bBallSaverActive = False
StopAttractMode
GiOn
CurrentPlayer = 1
PlayersPlayingGame = 1
bOnTheFirstBall = True
For i = 1 To MaxPlayers
Score(i) = 0
ExtraBallsAwards(i) = 0
Special1Awarded(i) = False
Special2Awarded(i) = False
Special3Awarded(i) = False
Special4Awarded(i) = False
BallsRemaining(i) = BallsPerGame
Next
BonusMultiplier = 1
Bonus = 0
UpdateBallsToPlay
UpdatePlayers
Clear_Match
' init other variables
Tilt = 0
' init game variables
Game_Init()
' start a music?
' first ball
vpmtimer.addtimer 2000, "FirstBall '"
End Sub
Sub FirstBall
'debug.print "FirstBall"
' reset table for a new ball, rise droptargets, etc
ResetForNewPlayerBall()
CreateNewBall()
End Sub
' (Re-)init table for a new ball or player
Sub ResetForNewPlayerBall()
'debug.print "ResetForNewPlayerBall"
UpdatePlayers
AddScore 0
' reset multiplier to 1x
BonusMultiplier = 1
' turn on lights, and variables
bExtraBallWonThisBall = False
ResetNewBallVariables
ResetNewBallLights
End Sub
' Create new ball
Sub CreateNewBall()
BallRelease.CreateSizedBallWithMass BallSize / 2, BallMass
BallsOnPlayfield = BallsOnPlayfield + 1
UpdateBallsToPlay
vpmtimer.addtimer 1000, "PlaySoundAt SoundFXDOF (""fx_Ballrel"", 104, DOFPulse, DOFContactors), Plunger : BallRelease.Kick 90, 4 '"
End Sub
' player lost the ball
Sub EndOfBall
'debug.print "EndOfBall"
' Lost the first ball, now it cannot accept more players
bOnTheFirstBall = False
' Bonus Count
' BonusMultiplier = 2 ' For test
If NOT Tilted Then
Select Case BonusMultiplier
Case 1:BonusCountTimer.Interval = 500
Case 2:BonusCountTimer.Interval = 1000
End Select
CBonus = 0
BonusCountTimer.Enabled = 1
Else
vpmtimer.addtimer 500, "EndOfBall2 '"
Playsound"MotorLeer2"
End If
End Sub
Sub BonusCountTimer_Timer 'The bonus are count when the ball is lost
'debug.print "BonusCount_Timer"
If Bonus> 0 Then
If BonusMultiplier = 1 Then
CBonus = CBonus + 1
If CBonus = 5 Then BonusCountTimer.Interval = BonusCountTimer.Interval + 100
If CBonus = 6 Then BonusCountTimer.Interval = BonusCountTimer.Interval - 100
End If
AddScore 3000 * BonusMultiplier
If BonusMultiplier = 2 Then PlaySoundAt "fx_bonus", Bumper001
Bonus = Bonus -1
UpdateBonusLights
Else
BonusCountTimer.Enabled = 0
vpmtimer.addtimer 1000, "EndOfBall2 '"
Playsound"MotorLeer2"
End If
End Sub
Sub UpdateBonusLights
Select Case Bonus
Case 0:BL3K.State = 0:BL6K.State = 0:BL9K.State = 0:BL12K.State = 0:BL15K.State = 0:BL18K.State = 0:BL21K.State = 0:BL24K.State = 0
Case 1:BL3K.State = 1:BL6K.State = 0:BL9K.State = 0:BL12K.State = 0:BL15K.State = 0:BL18K.State = 0:BL21K.State = 0:BL24K.State = 0
Case 2:BL3K.State = 1:BL6K.State = 1:BL9K.State = 0:BL12K.State = 0:BL15K.State = 0:BL18K.State = 0:BL21K.State = 0:BL24K.State = 0
Case 3:BL3K.State = 1:BL6K.State = 1:BL9K.State = 1:BL12K.State = 0:BL15K.State = 0:BL18K.State = 0:BL21K.State = 0:BL24K.State = 0
Case 4:BL3K.State = 1:BL6K.State = 1:BL9K.State = 1:BL12K.State = 1:BL15K.State = 0:BL18K.State = 0:BL21K.State = 0:BL24K.State = 0
Case 5:BL3K.State = 1:BL6K.State = 1:BL9K.State = 1:BL12K.State = 1:BL15K.State = 1:BL18K.State = 0:BL21K.State = 0:BL24K.State = 0
Case 6:BL3K.State = 1:BL6K.State = 1:BL9K.State = 1:BL12K.State = 1:BL15K.State = 1:BL18K.State = 1:BL21K.State = 0:BL24K.State = 0
Case 7:BL3K.State = 1:BL6K.State = 1:BL9K.State = 1:BL12K.State = 1:BL15K.State = 1:BL18K.State = 1:BL21K.State = 1:BL24K.State = 0
Case 8:BL3K.State = 1:BL6K.State = 1:BL9K.State = 1:BL12K.State = 1:BL15K.State = 1:BL18K.State = 1:BL21K.State = 1:BL24K.State = 1
End Select
If BL24K.State = 1 Then
If LightLaneL.State = 1 Then
LightSpecialR.State = 1
Else
LightSpecialL.State = 1
End If
End If