forked from LegendsUnchained/vpx-standalone-alp4k
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gorgar.vbs
3095 lines (2586 loc) · 110 KB
/
Gorgar.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
Option Explicit
On Error Resume Next
ExecuteGlobal GetTextFile("controller.vbs")
If Err Then MsgBox "You need the controller.vbs in order to run this table, available in the vp10 package"
On Error Goto 0
'//////////////////////////////////////////////////////////////////////
'// OPTIONS
'//////////////////////////////////////////////////////////////////////
'VR STUFF//////////////////////////////////////////////////////////////////
dim vrstuff,objects,pincabs
objects = 1 '(0 = not visible, 1 = visible) Visible objects in vr room
pincabs = 1 '(0 = not visible, 1 = visible) Visible pinball cabinets in vr room
'//////////////////////////////////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////
Const BallBright = 1 '0 - Normal, 1 - Bright
Const VolumeDial = 0.8
Const BallRollVolume = 0.5 'Level of ball rolling volume. Value between 0 and 1
Const RampRollVolume = 0.5 'Level of ramp rolling volume. Value between 0 and 1
'//////////////////////////////////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////
Const BallSize = 50
Const BallMass = 1
'UseVPMColoredDMD = DesktopMode
Dim DesktopMode:DesktopMode = gorgar.ShowDT
Dim UseVPMColoredDMD
Dim VarHidden, UseVPMDMD
UseVPMDMD=true
VarHidden=1
LoadVPM "01300000","S6.VBS",3.1
'********************************************
'** Game Specific Code Starts Here **
'********************************************
Const UseSolenoids=2,UseLamps=1,UseSync=1
Const SSolenoidOn="solon",SSolenoidOff="soloff",SFlipperOn="FlipperUp",SFlipperOff="FlipperDown",SCoin="quarter"
Const tnob = 5
Const lob = 0
Const AmbientBallShadowOn = 1
Const DynamicBallShadowsOn = 1
Const RubberizerEnabled = 1
Const TargetBouncerEnabled = 1 '0 = normal standup targets, 1 = bouncy targets
Const TargetBouncerFactor = 0.7 'Level of bounces. Recommmended value of 0.7
Dim tablewidth: tablewidth = gorgar.width
Dim tableheight: tableheight = gorgar.height
'**************************************
'** Bind Events To Solenoids **
'**************************************
SolCallback(1) = "bsTrough.SolOut"
SolCallBack(2) = "bsLKicker.SolOut"
SolCallback(3) = "SolDTDropUp"
SolCallback(4) = "SolDTDropUp2"
SolCallback(5) = "mMagnet.MagnetOn="
SolCallback(6) = "MagnetFlash"
SolCallback(14) = "vpmSolSound SoundFX(""knocker"",DOFKnocker),"
'SolCallback(17) = "vpmSolSound SoundFX(""bumper1"",DOFContactors),"
'SolCallback(18) = "vpmSolSound SoundFX(""bumper2"",DOFContactors),"
'SolCallback(19) = "vpmSolSound SoundFX(""bumper3"",DOFContactors),"
'SolCallback(20) = "vpmSolSound SoundFX(""sling"",DOFContactors),"
'SolCallback(21) = "vpmSolSound SoundFX(""sling"",DOFContactors),"
SolCallback(23) = "vpmNudge.SolGameOn"
SolCallback(sLRFlipper) = "SolRFlipper"
SolCallback(sLLFlipper) = "SolLFlipper"
Sub Drain_Hit : RandomSoundDrain Drain : bsTrough.AddBall Me : End Sub
'********************************************
' Drop Target Controls
'********************************************
Sub SolDTDropUp2(Enabled)
If Enabled Then
debug.print "SolDTDropUp2"
DTRaise 20
DTRaise 19
DTRaise 18
RandomSoundDropTargetReset sw19p
End If
End Sub
Sub SolDTDropUp(Enabled)
If Enabled Then
debug.print "SolDTDropUp"
DTRaise 41
DTRaise 42
DTRaise 43
RandomSoundDropTargetReset sw42p
End If
End Sub
Sub sw41_hit
DTHit 41
End Sub
Sub sw42_hit
DTHit 42
End Sub
Sub sw43_hit
DTHit 43
End Sub
Sub sw20_hit
DTHit 20
End Sub
Sub sw19_hit
DTHit 19
End Sub
Sub sw18_hit
DTHit 18
End Sub
Sub CheckDTs
If controller.switch(41) AND controller.switch(42) AND controller.switch(43) then
controller.switch(44)=true
Else
controller.switch(44)=false
End if
If controller.switch(18) AND controller.switch(19) AND controller.switch(20) then
controller.switch(21)=true
Else
controller.switch(21)=false
End if
end sub
'//////////////////////////////////////////////////////////////////////
'// Ball
'//////////////////////////////////////////////////////////////////////
If BallBright Then
gorgar.BallImage = "ball_HDR_brighter"
Else
gorgar.BallImage = "MRBallDark2b"
End If
'//////////////////////////////////////////////////////////////////////
'// Dynamic Ball Shadows
'//////////////////////////////////////////////////////////////////////
dim gilvl:gilvl = 1
Const fovY = 0 'Offset y position under ball to account for layback or inclination (more pronounced need further back)
Const DynamicBSFactor = 0.95 '0 to 1, higher is darker
Const AmbientBSFactor = 0.7 '0 to 1, higher is darker
Const AmbientMovement = 2 '1 to 4, higher means more movement as the ball moves left and right
Const Wideness = 20 'Sets how wide the dynamic ball shadows can get (20 +5 thinness should be most realistic for a 50 unit ball)
Const Thinness = 5 'Sets minimum as ball moves away from source
' *** This segment goes within the RollingUpdate sub, so that if Ambient...=0 and Dynamic...=0 the entire DynamicBSUpdate sub can be skipped for max performance
' ' stop the sound of deleted balls
' For b = UBound(BOT) + 1 to tnob
' If AmbientBallShadowOn = 0 Then BallShadowA(b).visible = 0
' ...rolling(b) = False
' ...StopSound("BallRoll_" & b)
' Next
'
'...rolling and drop sounds...
' If DropCount(b) < 5 Then
' DropCount(b) = DropCount(b) + 1
' End If
'
' ' "Static" Ball Shadows
' If AmbientBallShadowOn = 0 Then
' If BOT(b).Z > 30 Then
' BallShadowA(b).height=BOT(b).z - BallSize/4 'This is technically 1/4 of the ball "above" the ramp, but it keeps it from clipping
' Else
' BallShadowA(b).height=BOT(b).z - BallSize/2 + 5
' End If
' BallShadowA(b).Y = BOT(b).Y + Ballsize/5 + fovY
' BallShadowA(b).X = BOT(b).X
' BallShadowA(b).visible = 1
' End If
' *** Required Functions, enable these if they are not already present elswhere in your table
Function DistanceFast(x, y)
dim ratio, ax, ay
ax = abs(x) 'Get absolute value of each vector
ay = abs(y)
ratio = 1 / max(ax, ay) 'Create a ratio
ratio = ratio * (1.29289 - (ax + ay) * ratio * 0.29289)
if ratio > 0 then 'Quickly determine if it's worth using
DistanceFast = 1/ratio
Else
DistanceFast = 0
End if
end Function
Function max(a,b)
if a > b then
max = a
Else
max = b
end if
end Function
'Dim PI: PI = 4*Atn(1)
'Function Atn2(dy, dx)
' If dx > 0 Then
' Atn2 = Atn(dy / dx)
' ElseIf dx < 0 Then
' If dy = 0 Then
' Atn2 = pi
' Else
' Atn2 = Sgn(dy) * (pi - Atn(Abs(dy / dx)))
' end if
' ElseIf dx = 0 Then
' if dy = 0 Then
' Atn2 = 0
' else
' Atn2 = Sgn(dy) * pi / 2
' end if
' End If
'End Function
'
'Function AnglePP(ax,ay,bx,by)
' AnglePP = Atn2((by - ay),(bx - ax))*180/PI
'End Function
'****** End Part B: Code and Functions ******
'****** Part C: The Magic ******
Dim sourcenames, currentShadowCount, DSSources(43), numberofsources, numberofsources_hold
sourcenames = Array ("","","","","","","","","","","","")
currentShadowCount = Array (0,0,0,0,0,0,0,0,0,0,0,0)
' *** Trim or extend these to match the number of balls/primitives/flashers on the table!
dim objrtx1(12), objrtx2(12)
dim objBallShadow(12)
Dim BallShadowA
BallShadowA = Array (BallShadowA0,BallShadowA1,BallShadowA2,BallShadowA3,BallShadowA4,BallShadowA5,BallShadowA6,BallShadowA7,BallShadowA8,BallShadowA9,BallShadowA10,BallShadowA11)
DynamicBSInit
sub DynamicBSInit()
Dim iii, source
for iii = 0 to tnob 'Prepares the shadow objects before play begins
Set objrtx1(iii) = Eval("RtxBallShadow" & iii)
objrtx1(iii).material = "RtxBallShadow" & iii
objrtx1(iii).z = iii/1000 + 0.01
objrtx1(iii).visible = 0
Set objrtx2(iii) = Eval("RtxBall2Shadow" & iii)
objrtx2(iii).material = "RtxBallShadow2_" & iii
objrtx2(iii).z = (iii)/1000 + 0.02
objrtx2(iii).visible = 0
currentShadowCount(iii) = 0
Set objBallShadow(iii) = Eval("BallShadow" & iii)
objBallShadow(iii).material = "BallShadow" & iii
UpdateMaterial objBallShadow(iii).material,1,0,0,0,0,0,AmbientBSFactor,RGB(0,0,0),0,0,False,True,0,0,0,0
objBallShadow(iii).Z = iii/1000 + 0.04
objBallShadow(iii).visible = 0
BallShadowA(iii).Opacity = 100*AmbientBSFactor
BallShadowA(iii).visible = 0
Next
iii = 0
For Each Source in DynamicSources
DSSources(iii) = Array(Source.x, Source.y)
iii = iii + 1
Next
numberofsources = iii
numberofsources_hold = iii
end sub
Sub DynamicBSUpdate
Dim falloff: falloff = 150 'Max distance to light sources, can be changed if you have a reason
Dim ShadowOpacity, ShadowOpacity2
Dim s, Source, LSd, currentMat, AnotherSource, BOT, iii
BOT = GetBalls
'Hide shadow of deleted balls
For s = UBound(BOT) + 1 to tnob
objrtx1(s).visible = 0
objrtx2(s).visible = 0
objBallShadow(s).visible = 0
BallShadowA(s).visible = 0
Next
If UBound(BOT) < lob Then Exit Sub 'No balls in play, exit
'The Magic happens now
For s = lob to UBound(BOT)
' *** Normal "ambient light" ball shadow
'Layered from top to bottom. If you had an upper pf at for example 80 and ramps even above that, your segments would be z>110; z<=110 And z>100; z<=100 And z>30; z<=30 And z>20; Else invisible
If AmbientBallShadowOn = 1 Then 'Primitive shadow on playfield, flasher shadow in ramps
If BOT(s).Z > 30 Then 'The flasher follows the ball up ramps while the primitive is on the pf
If BOT(s).X < tablewidth/2 Then
objBallShadow(s).X = ((BOT(s).X) - (Ballsize/10) + ((BOT(s).X - (tablewidth/2))/(Ballsize/AmbientMovement))) + 5
Else
objBallShadow(s).X = ((BOT(s).X) + (Ballsize/10) + ((BOT(s).X - (tablewidth/2))/(Ballsize/AmbientMovement))) - 5
End If
objBallShadow(s).Y = BOT(s).Y + BallSize/10 + fovY
objBallShadow(s).visible = 1
BallShadowA(s).X = BOT(s).X
BallShadowA(s).Y = BOT(s).Y + BallSize/5 + fovY
BallShadowA(s).height=BOT(s).z - BallSize/4 'This is technically 1/4 of the ball "above" the ramp, but it keeps it from clipping
BallShadowA(s).visible = 1
Elseif BOT(s).Z <= 30 And BOT(s).Z > 20 Then 'On pf, primitive only
objBallShadow(s).visible = 1
If BOT(s).X < tablewidth/2 Then
objBallShadow(s).X = ((BOT(s).X) - (Ballsize/10) + ((BOT(s).X - (tablewidth/2))/(Ballsize/AmbientMovement))) + 5
Else
objBallShadow(s).X = ((BOT(s).X) + (Ballsize/10) + ((BOT(s).X - (tablewidth/2))/(Ballsize/AmbientMovement))) - 5
End If
objBallShadow(s).Y = BOT(s).Y + fovY
BallShadowA(s).visible = 0
Else 'Under pf, no shadows
objBallShadow(s).visible = 0
BallShadowA(s).visible = 0
end if
Elseif AmbientBallShadowOn = 2 Then 'Flasher shadow everywhere
If BOT(s).Z > 30 Then 'In a ramp
BallShadowA(s).X = BOT(s).X
BallShadowA(s).Y = BOT(s).Y + BallSize/5 + fovY
BallShadowA(s).height=BOT(s).z - BallSize/4 'This is technically 1/4 of the ball "above" the ramp, but it keeps it from clipping
BallShadowA(s).visible = 1
Elseif BOT(s).Z <= 30 And BOT(s).Z > 20 Then 'On pf
BallShadowA(s).visible = 1
If BOT(s).X < tablewidth/2 Then
BallShadowA(s).X = ((BOT(s).X) - (Ballsize/10) + ((BOT(s).X - (tablewidth/2))/(Ballsize/AmbientMovement))) + 5
Else
BallShadowA(s).X = ((BOT(s).X) + (Ballsize/10) + ((BOT(s).X - (tablewidth/2))/(Ballsize/AmbientMovement))) - 5
End If
BallShadowA(s).Y = BOT(s).Y + Ballsize/10 + fovY
BallShadowA(s).height=BOT(s).z - BallSize/2 + 5
Else 'Under pf
BallShadowA(s).visible = 0
End If
End If
' *** Dynamic shadows
If DynamicBallShadowsOn Then
If BOT(s).Z < 30 Then 'And BOT(s).Y < (TableHeight - 200) Then 'Or BOT(s).Z > 105 Then 'Defining when and where (on the table) you can have dynamic shadows
For iii = 0 to numberofsources - 1
LSd=DistanceFast((BOT(s).x-DSSources(iii)(0)),(BOT(s).y-DSSources(iii)(1))) 'Calculating the Linear distance to the Source
If LSd < falloff And gilvl > 0 Then 'If the ball is within the falloff range of a light and light is on (we will set numberofsources to 0 when GI is off)
currentShadowCount(s) = currentShadowCount(s) + 1 'Within range of 1 or 2
if currentShadowCount(s) = 1 Then '1 dynamic shadow source
sourcenames(s) = iii
currentMat = objrtx1(s).material
objrtx2(s).visible = 0 : objrtx1(s).visible = 1 : objrtx1(s).X = BOT(s).X : objrtx1(s).Y = BOT(s).Y + fovY
' objrtx1(s).Z = BOT(s).Z - 25 + s/1000 + 0.01 'Uncomment if you want to add shadows to an upper/lower pf
objrtx1(s).rotz = AnglePP(DSSources(iii)(0), DSSources(iii)(1), BOT(s).X, BOT(s).Y) + 90
ShadowOpacity = (falloff-LSd)/falloff 'Sets opacity/darkness of shadow by distance to light
objrtx1(s).size_y = Wideness*ShadowOpacity+Thinness 'Scales shape of shadow with distance/opacity
UpdateMaterial currentMat,1,0,0,0,0,0,ShadowOpacity*DynamicBSFactor^2,RGB(0,0,0),0,0,False,True,0,0,0,0
If AmbientBallShadowOn = 1 Then
currentMat = objBallShadow(s).material 'Brightens the ambient primitive when it's close to a light
UpdateMaterial currentMat,1,0,0,0,0,0,AmbientBSFactor*(1-ShadowOpacity),RGB(0,0,0),0,0,False,True,0,0,0,0
Else
BallShadowA(s).Opacity = 100*AmbientBSFactor*(1-ShadowOpacity)
End If
Elseif currentShadowCount(s) = 2 Then
'Same logic as 1 shadow, but twice
currentMat = objrtx1(s).material
AnotherSource = sourcenames(s)
objrtx1(s).visible = 1 : objrtx1(s).X = BOT(s).X : objrtx1(s).Y = BOT(s).Y + fovY
' objrtx1(s).Z = BOT(s).Z - 25 + s/1000 + 0.01 'Uncomment if you want to add shadows to an upper/lower pf
objrtx1(s).rotz = AnglePP(DSSources(AnotherSource)(0),DSSources(AnotherSource)(1), BOT(s).X, BOT(s).Y) + 90
ShadowOpacity = (falloff-DistanceFast((BOT(s).x-DSSources(AnotherSource)(0)),(BOT(s).y-DSSources(AnotherSource)(1))))/falloff
objrtx1(s).size_y = Wideness*ShadowOpacity+Thinness
UpdateMaterial currentMat,1,0,0,0,0,0,ShadowOpacity*DynamicBSFactor^3,RGB(0,0,0),0,0,False,True,0,0,0,0
currentMat = objrtx2(s).material
objrtx2(s).visible = 1 : objrtx2(s).X = BOT(s).X : objrtx2(s).Y = BOT(s).Y + fovY
' objrtx2(s).Z = BOT(s).Z - 25 + s/1000 + 0.02 'Uncomment if you want to add shadows to an upper/lower pf
objrtx2(s).rotz = AnglePP(DSSources(iii)(0), DSSources(iii)(1), BOT(s).X, BOT(s).Y) + 90
ShadowOpacity2 = (falloff-LSd)/falloff
objrtx2(s).size_y = Wideness*ShadowOpacity2+Thinness
UpdateMaterial currentMat,1,0,0,0,0,0,ShadowOpacity2*DynamicBSFactor^3,RGB(0,0,0),0,0,False,True,0,0,0,0
If AmbientBallShadowOn = 1 Then
currentMat = objBallShadow(s).material 'Brightens the ambient primitive when it's close to a light
UpdateMaterial currentMat,1,0,0,0,0,0,AmbientBSFactor*(1-max(ShadowOpacity,ShadowOpacity2)),RGB(0,0,0),0,0,False,True,0,0,0,0
Else
BallShadowA(s).Opacity = 100*AmbientBSFactor*(1-max(ShadowOpacity,ShadowOpacity2))
End If
end if
Else
currentShadowCount(s) = 0
BallShadowA(s).Opacity = 100*AmbientBSFactor
End If
Next
Else 'Hide dynamic shadows everywhere else
objrtx2(s).visible = 0 : objrtx1(s).visible = 0
End If
End If
Next
End Sub
'//////////////////////////////////////////////////////////////////////
'// FLIPPERS
'//////////////////////////////////////////////////////////////////////
Const ReflipAngle = 20
' Flipper Solenoid Callbacks (these subs mimics how you would handle flippers in ROM based tables)
Sub SolLFlipper(Enabled)
If Enabled Then
LF.Fire 'leftflipper.rotatetoend
If leftflipper.currentangle < leftflipper.endangle + ReflipAngle Then
RandomSoundReflipUpLeft LeftFlipper
Else
SoundFlipperUpAttackLeft LeftFlipper
RandomSoundFlipperUpLeft LeftFlipper
End If
Else
LeftFlipper.RotateToStart
If LeftFlipper.currentangle < LeftFlipper.startAngle - 5 Then
RandomSoundFlipperDownLeft LeftFlipper
End If
FlipperLeftHitParm = FlipperUpSoundLevel
End If
End Sub
Sub SolRFlipper(Enabled)
If Enabled Then
RF.Fire 'rightflipper.rotatetoend
If rightflipper.currentangle > rightflipper.endangle - ReflipAngle Then
RandomSoundReflipUpRight RightFlipper
Else
SoundFlipperUpAttackRight RightFlipper
RandomSoundFlipperUpRight RightFlipper
End If
Else
RightFlipper.RotateToStart
If RightFlipper.currentangle > RightFlipper.startAngle + 5 Then
RandomSoundFlipperDownRight RightFlipper
End If
FlipperRightHitParm = FlipperUpSoundLevel
End If
End Sub
' Flipper collide subs
Sub LeftFlipper_Collide(parm)
CheckLiveCatch Activeball, LeftFlipper, LFCount, parm
LeftFlipperCollide parm
End Sub
Sub RightFlipper_Collide(parm)
CheckLiveCatch Activeball, RightFlipper, RFCount, parm
RightFlipperCollide parm
End Sub
' This subroutine updates the flipper shadows and visual primitives
Sub FlipperVisualUpdate
FlipperLSh.RotZ = LeftFlipper.CurrentAngle
FlipperRSh.RotZ = RightFlipper.CurrentAngle
End Sub
dim LF : Set LF = New FlipperPolarity
dim RF : Set RF = New FlipperPolarity
InitPolarity
'
''*******************************************
'' Late 70's to early 80's
'
Sub InitPolarity()
dim x, a : a = Array(LF, RF)
for each x in a
x.AddPoint "Ycoef", 0, RightFlipper.Y-65, 1 'disabled
x.AddPoint "Ycoef", 1, RightFlipper.Y-11, 1
x.enabled = True
x.TimeDelay = 80
Next
AddPt "Polarity", 0, 0, 0
AddPt "Polarity", 1, 0.05, -2.7
AddPt "Polarity", 2, 0.33, -2.7
AddPt "Polarity", 3, 0.37, -2.7
AddPt "Polarity", 4, 0.41, -2.7
AddPt "Polarity", 5, 0.45, -2.7
AddPt "Polarity", 6, 0.576,-2.7
AddPt "Polarity", 7, 0.66, -1.8
AddPt "Polarity", 8, 0.743, -0.5
AddPt "Polarity", 9, 0.81, -0.5
AddPt "Polarity", 10, 0.88, 0
addpt "Velocity", 0, 0, 1
addpt "Velocity", 1, 0.16, 1.06
addpt "Velocity", 2, 0.41, 1.05
addpt "Velocity", 3, 0.53, 1'0.982
addpt "Velocity", 4, 0.702, 0.968
addpt "Velocity", 5, 0.95, 0.968
addpt "Velocity", 6, 1.03, 0.945
LF.Object = LeftFlipper
LF.EndPoint = EndPointLp
RF.Object = RightFlipper
RF.EndPoint = EndPointRp
End Sub
'
'
'
''*******************************************
'' Mid 80's
'
'Sub InitPolarity()
' dim x, a : a = Array(LF, RF)
' for each x in a
' x.AddPoint "Ycoef", 0, RightFlipper.Y-65, 1 'disabled
' x.AddPoint "Ycoef", 1, RightFlipper.Y-11, 1
' x.enabled = True
' x.TimeDelay = 80
' Next
'
' AddPt "Polarity", 0, 0, 0
' AddPt "Polarity", 1, 0.05, -3.7
' AddPt "Polarity", 2, 0.33, -3.7
' AddPt "Polarity", 3, 0.37, -3.7
' AddPt "Polarity", 4, 0.41, -3.7
' AddPt "Polarity", 5, 0.45, -3.7
' AddPt "Polarity", 6, 0.576,-3.7
' AddPt "Polarity", 7, 0.66, -2.3
' AddPt "Polarity", 8, 0.743, -1.5
' AddPt "Polarity", 9, 0.81, -1
' AddPt "Polarity", 10, 0.88, 0
'
' addpt "Velocity", 0, 0, 1
' addpt "Velocity", 1, 0.16, 1.06
' addpt "Velocity", 2, 0.41, 1.05
' addpt "Velocity", 3, 0.53, 1'0.982
' addpt "Velocity", 4, 0.702, 0.968
' addpt "Velocity", 5, 0.95, 0.968
' addpt "Velocity", 6, 1.03, 0.945
'
' LF.Object = LeftFlipper
' LF.EndPoint = EndPointLp
' RF.Object = RightFlipper
' RF.EndPoint = EndPointRp
'End Sub
'
'
'*******************************************
' Late 80's early 90's
'Sub InitPolarity()
' dim x, a : a = Array(LF, RF)
' for each x in a
' x.AddPoint "Ycoef", 0, RightFlipper.Y-65, 1 'disabled
' x.AddPoint "Ycoef", 1, RightFlipper.Y-11, 1
' x.enabled = True
' x.TimeDelay = 60
' Next
'
' AddPt "Polarity", 0, 0, 0
' AddPt "Polarity", 1, 0.05, -5
' AddPt "Polarity", 2, 0.4, -5
' AddPt "Polarity", 3, 0.6, -4.5
' AddPt "Polarity", 4, 0.65, -4.0
' AddPt "Polarity", 5, 0.7, -3.5
' AddPt "Polarity", 6, 0.75, -3.0
' AddPt "Polarity", 7, 0.8, -2.5
' AddPt "Polarity", 8, 0.85, -2.0
' AddPt "Polarity", 9, 0.9,-1.5
' AddPt "Polarity", 10, 0.95, -1.0
' AddPt "Polarity", 11, 1, -0.5
' AddPt "Polarity", 12, 1.1, 0
' AddPt "Polarity", 13, 1.3, 0
'
' addpt "Velocity", 0, 0, 1
' addpt "Velocity", 1, 0.16, 1.06
' addpt "Velocity", 2, 0.41, 1.05
' addpt "Velocity", 3, 0.53, 1'0.982
' addpt "Velocity", 4, 0.702, 0.968
' addpt "Velocity", 5, 0.95, 0.968
' addpt "Velocity", 6, 1.03, 0.945
'
' LF.Object = LeftFlipper
' LF.EndPoint = EndPointLp
' RF.Object = RightFlipper
' RF.EndPoint = EndPointRp
'End Sub
'
''*******************************************
'' Early 90's and after
'
'Sub InitPolarity()
' dim x, a : a = Array(LF, RF)
' for each x in a
' x.AddPoint "Ycoef", 0, RightFlipper.Y-65, 1 'disabled
' x.AddPoint "Ycoef", 1, RightFlipper.Y-11, 1
' x.enabled = True
' x.TimeDelay = 60
' Next
'
' AddPt "Polarity", 0, 0, 0
' AddPt "Polarity", 1, 0.05, -5.5
' AddPt "Polarity", 2, 0.4, -5.5
' AddPt "Polarity", 3, 0.6, -5.0
' AddPt "Polarity", 4, 0.65, -4.5
' AddPt "Polarity", 5, 0.7, -4.0
' AddPt "Polarity", 6, 0.75, -3.5
' AddPt "Polarity", 7, 0.8, -3.0
' AddPt "Polarity", 8, 0.85, -2.5
' AddPt "Polarity", 9, 0.9,-2.0
' AddPt "Polarity", 10, 0.95, -1.5
' AddPt "Polarity", 11, 1, -1.0
' AddPt "Polarity", 12, 1.05, -0.5
' AddPt "Polarity", 13, 1.1, 0
' AddPt "Polarity", 14, 1.3, 0
'
' addpt "Velocity", 0, 0, 1
' addpt "Velocity", 1, 0.16, 1.06
' addpt "Velocity", 2, 0.41, 1.05
' addpt "Velocity", 3, 0.53, 1'0.982
' addpt "Velocity", 4, 0.702, 0.968
' addpt "Velocity", 5, 0.95, 0.968
' addpt "Velocity", 6, 1.03, 0.945
'
' LF.Object = LeftFlipper
' LF.EndPoint = EndPointLp
' RF.Object = RightFlipper
' RF.EndPoint = EndPointRp
'End Sub
' Flipper trigger hit subs
Sub TriggerLF_Hit() : LF.Addball activeball : End Sub
Sub TriggerLF_UnHit() : LF.PolarityCorrect activeball : End Sub
Sub TriggerRF_Hit() : RF.Addball activeball : End Sub
Sub TriggerRF_UnHit() : RF.PolarityCorrect activeball : End Sub
'******************************************************
' FLIPPER CORRECTION FUNCTIONS
'******************************************************
Sub AddPt(aStr, idx, aX, aY) 'debugger wrapper for adjusting flipper script in-game
dim a : a = Array(LF, RF)
dim x : for each x in a
x.addpoint aStr, idx, aX, aY
Next
End Sub
Class FlipperPolarity
Public DebugOn, Enabled
Private FlipAt 'Timer variable (IE 'flip at 723,530ms...)
Public TimeDelay 'delay before trigger turns off and polarity is disabled TODO set time!
private Flipper, FlipperStart,FlipperEnd, FlipperEndY, LR, PartialFlipCoef
Private Balls(20), balldata(20)
dim PolarityIn, PolarityOut
dim VelocityIn, VelocityOut
dim YcoefIn, YcoefOut
Public Sub Class_Initialize
redim PolarityIn(0) : redim PolarityOut(0) : redim VelocityIn(0) : redim VelocityOut(0) : redim YcoefIn(0) : redim YcoefOut(0)
Enabled = True : TimeDelay = 50 : LR = 1: dim x : for x = 0 to uBound(balls) : balls(x) = Empty : set Balldata(x) = new SpoofBall : next
End Sub
Public Property let Object(aInput) : Set Flipper = aInput : StartPoint = Flipper.x : End Property
Public Property Let StartPoint(aInput) : if IsObject(aInput) then FlipperStart = aInput.x else FlipperStart = aInput : end if : End Property
Public Property Get StartPoint : StartPoint = FlipperStart : End Property
Public Property Let EndPoint(aInput) : FlipperEnd = aInput.x: FlipperEndY = aInput.y: End Property
Public Property Get EndPoint : EndPoint = FlipperEnd : End Property
Public Property Get EndPointY: EndPointY = FlipperEndY : End Property
Public Sub AddPoint(aChooseArray, aIDX, aX, aY) 'Index #, X position, (in) y Position (out)
Select Case aChooseArray
case "Polarity" : ShuffleArrays PolarityIn, PolarityOut, 1 : PolarityIn(aIDX) = aX : PolarityOut(aIDX) = aY : ShuffleArrays PolarityIn, PolarityOut, 0
Case "Velocity" : ShuffleArrays VelocityIn, VelocityOut, 1 :VelocityIn(aIDX) = aX : VelocityOut(aIDX) = aY : ShuffleArrays VelocityIn, VelocityOut, 0
Case "Ycoef" : ShuffleArrays YcoefIn, YcoefOut, 1 :YcoefIn(aIDX) = aX : YcoefOut(aIDX) = aY : ShuffleArrays YcoefIn, YcoefOut, 0
End Select
if gametime > 100 then Report aChooseArray
End Sub
Public Sub Report(aChooseArray) 'debug, reports all coords in tbPL.text
if not DebugOn then exit sub
dim a1, a2 : Select Case aChooseArray
case "Polarity" : a1 = PolarityIn : a2 = PolarityOut
Case "Velocity" : a1 = VelocityIn : a2 = VelocityOut
Case "Ycoef" : a1 = YcoefIn : a2 = YcoefOut
case else :tbpl.text = "wrong string" : exit sub
End Select
dim str, x : for x = 0 to uBound(a1) : str = str & aChooseArray & " x: " & round(a1(x),4) & ", " & round(a2(x),4) & vbnewline : next
tbpl.text = str
End Sub
Public Sub AddBall(aBall) : dim x : for x = 0 to uBound(balls) : if IsEmpty(balls(x)) then set balls(x) = aBall : exit sub :end if : Next : End Sub
Private Sub RemoveBall(aBall)
dim x : for x = 0 to uBound(balls)
if TypeName(balls(x) ) = "IBall" then
if aBall.ID = Balls(x).ID Then
balls(x) = Empty
Balldata(x).Reset
End If
End If
Next
End Sub
Public Sub Fire()
Flipper.RotateToEnd
processballs
End Sub
Public Property Get Pos 'returns % position a ball. For debug stuff.
dim x : for x = 0 to uBound(balls)
if not IsEmpty(balls(x) ) then
pos = pSlope(Balls(x).x, FlipperStart, 0, FlipperEnd, 1)
End If
Next
End Property
Public Sub ProcessBalls() 'save data of balls in flipper range
FlipAt = GameTime
dim x : for x = 0 to uBound(balls)
if not IsEmpty(balls(x) ) then
balldata(x).Data = balls(x)
End If
Next
PartialFlipCoef = ((Flipper.StartAngle - Flipper.CurrentAngle) / (Flipper.StartAngle - Flipper.EndAngle))
PartialFlipCoef = abs(PartialFlipCoef-1)
End Sub
Private Function FlipperOn() : if gameTime < FlipAt+TimeDelay then FlipperOn = True : End If : End Function 'Timer shutoff for polaritycorrect
Public Sub PolarityCorrect(aBall)
if FlipperOn() then
dim tmp, BallPos, x, IDX, Ycoef : Ycoef = 1
'y safety Exit
if aBall.VelY > -8 then 'ball going down
RemoveBall aBall
exit Sub
end if
'Find balldata. BallPos = % on Flipper
for x = 0 to uBound(Balls)
if aBall.id = BallData(x).id AND not isempty(BallData(x).id) then
idx = x
BallPos = PSlope(BallData(x).x, FlipperStart, 0, FlipperEnd, 1)
if ballpos > 0.65 then Ycoef = LinearEnvelope(BallData(x).Y, YcoefIn, YcoefOut) 'find safety coefficient 'ycoef' data
end if
Next
If BallPos = 0 Then 'no ball data meaning the ball is entering and exiting pretty close to the same position, use current values.
BallPos = PSlope(aBall.x, FlipperStart, 0, FlipperEnd, 1)
if ballpos > 0.65 then Ycoef = LinearEnvelope(aBall.Y, YcoefIn, YcoefOut) 'find safety coefficient 'ycoef' data
End If
'Velocity correction
if not IsEmpty(VelocityIn(0) ) then
Dim VelCoef
VelCoef = LinearEnvelope(BallPos, VelocityIn, VelocityOut)
if partialflipcoef < 1 then VelCoef = PSlope(partialflipcoef, 0, 1, 1, VelCoef)
if Enabled then aBall.Velx = aBall.Velx*VelCoef
if Enabled then aBall.Vely = aBall.Vely*VelCoef
End If
'Polarity Correction (optional now)
if not IsEmpty(PolarityIn(0) ) then
If StartPoint > EndPoint then LR = -1 'Reverse polarity if left flipper
dim AddX : AddX = LinearEnvelope(BallPos, PolarityIn, PolarityOut) * LR
if Enabled then aBall.VelX = aBall.VelX + 1 * (AddX*ycoef*PartialFlipcoef)
End If
End If
RemoveBall aBall
End Sub
End Class
'******************************************************
' FLIPPER POLARITY AND RUBBER DAMPENER SUPPORTING FUNCTIONS
'******************************************************
' Used for flipper correction and rubber dampeners
Sub ShuffleArray(ByRef aArray, byVal offset) 'shuffle 1d array
dim x, aCount : aCount = 0
redim a(uBound(aArray) )
for x = 0 to uBound(aArray) 'Shuffle objects in a temp array
if not IsEmpty(aArray(x) ) Then
if IsObject(aArray(x)) then
Set a(aCount) = aArray(x)
Else
a(aCount) = aArray(x)
End If
aCount = aCount + 1
End If
Next
if offset < 0 then offset = 0
redim aArray(aCount-1+offset) 'Resize original array
for x = 0 to aCount-1 'set objects back into original array
if IsObject(a(x)) then
Set aArray(x) = a(x)
Else
aArray(x) = a(x)
End If
Next
End Sub
' Used for flipper correction and rubber dampeners
Sub ShuffleArrays(aArray1, aArray2, offset)
ShuffleArray aArray1, offset
ShuffleArray aArray2, offset
End Sub
' Used for flipper correction, rubber dampeners, and drop targets
Function BallSpeed(ball) 'Calculates the ball speed
BallSpeed = SQR(ball.VelX^2 + ball.VelY^2 + ball.VelZ^2)
End Function
' Used for flipper correction and rubber dampeners
Function PSlope(Input, X1, Y1, X2, Y2) 'Set up line via two points, no clamping. Input X, output Y
dim x, y, b, m : x = input : m = (Y2 - Y1) / (X2 - X1) : b = Y2 - m*X2
Y = M*x+b
PSlope = Y
End Function
' Used for flipper correction
Class spoofball
Public X, Y, Z, VelX, VelY, VelZ, ID, Mass, Radius
Public Property Let Data(aBall)
With aBall
x = .x : y = .y : z = .z : velx = .velx : vely = .vely : velz = .velz
id = .ID : mass = .mass : radius = .radius
end with
End Property
Public Sub Reset()
x = Empty : y = Empty : z = Empty : velx = Empty : vely = Empty : velz = Empty
id = Empty : mass = Empty : radius = Empty
End Sub
End Class
' Used for flipper correction and rubber dampeners
Function LinearEnvelope(xInput, xKeyFrame, yLvl)
dim y 'Y output
dim L 'Line
dim ii : for ii = 1 to uBound(xKeyFrame) 'find active line
if xInput <= xKeyFrame(ii) then L = ii : exit for : end if
Next
if xInput > xKeyFrame(uBound(xKeyFrame) ) then L = uBound(xKeyFrame) 'catch line overrun
Y = pSlope(xInput, xKeyFrame(L-1), yLvl(L-1), xKeyFrame(L), yLvl(L) )
if xInput <= xKeyFrame(lBound(xKeyFrame) ) then Y = yLvl(lBound(xKeyFrame) ) 'Clamp lower
if xInput >= xKeyFrame(uBound(xKeyFrame) ) then Y = yLvl(uBound(xKeyFrame) ) 'Clamp upper
LinearEnvelope = Y
End Function
'******************************************************
' FLIPPER TRICKS
'******************************************************
RightFlipper.timerinterval=1
Rightflipper.timerenabled=True
sub RightFlipper_timer()
FlipperTricks LeftFlipper, LFPress, LFCount, LFEndAngle, LFState
FlipperTricks RightFlipper, RFPress, RFCount, RFEndAngle, RFState
FlipperNudge RightFlipper, RFEndAngle, RFEOSNudge, LeftFlipper, LFEndAngle
FlipperNudge LeftFlipper, LFEndAngle, LFEOSNudge, RightFlipper, RFEndAngle
end sub
Dim LFEOSNudge, RFEOSNudge
Sub FlipperNudge(Flipper1, Endangle1, EOSNudge1, Flipper2, EndAngle2)
Dim b, BOT
BOT = GetBalls
If Flipper1.currentangle = Endangle1 and EOSNudge1 <> 1 Then
EOSNudge1 = 1
'debug.print Flipper1.currentangle &" = "& Endangle1 &"--"& Flipper2.currentangle &" = "& EndAngle2
If Flipper2.currentangle = EndAngle2 Then
For b = 0 to Ubound(BOT)
If FlipperTrigger(BOT(b).x, BOT(b).y, Flipper1) Then
'Debug.Print "ball in flip1. exit"
exit Sub
end If
Next
For b = 0 to Ubound(BOT)
If FlipperTrigger(BOT(b).x, BOT(b).y, Flipper2) Then
BOT(b).velx = BOT(b).velx / 1.3
BOT(b).vely = BOT(b).vely - 0.5
end If
Next
End If
Else
If Abs(Flipper1.currentangle) > Abs(EndAngle1) + 30 then EOSNudge1 = 0
End If
End Sub
'*****************
' Maths
'*****************
Dim PI: PI = 4*Atn(1)
Function dSin(degrees)
dsin = sin(degrees * Pi/180)
End Function
Function dCos(degrees)
dcos = cos(degrees * Pi/180)
End Function
Function Atn2(dy, dx)
If dx > 0 Then
Atn2 = Atn(dy / dx)
ElseIf dx < 0 Then
If dy = 0 Then
Atn2 = pi
Else
Atn2 = Sgn(dy) * (pi - Atn(Abs(dy / dx)))
end if
ElseIf dx = 0 Then
if dy = 0 Then
Atn2 = 0
else
Atn2 = Sgn(dy) * pi / 2
end if
End If
End Function
'*************************************************
' Check ball distance from Flipper for Rem
'*************************************************
Function Distance(ax,ay,bx,by)
Distance = SQR((ax - bx)^2 + (ay - by)^2)
End Function
Function DistancePL(px,py,ax,ay,bx,by) ' Distance between a point and a line where point is px,py
DistancePL = ABS((by - ay)*px - (bx - ax) * py + bx*ay - by*ax)/Distance(ax,ay,bx,by)
End Function
Function Radians(Degrees)
Radians = Degrees * PI /180
End Function
Function AnglePP(ax,ay,bx,by)
AnglePP = Atn2((by - ay),(bx - ax))*180/PI
End Function
Function DistanceFromFlipper(ballx, bally, Flipper)
DistanceFromFlipper = DistancePL(ballx, bally, Flipper.x, Flipper.y, Cos(Radians(Flipper.currentangle+90))+Flipper.x, Sin(Radians(Flipper.currentangle+90))+Flipper.y)
End Function
Function FlipperTrigger(ballx, bally, Flipper)
Dim DiffAngle
DiffAngle = ABS(Flipper.currentangle - AnglePP(Flipper.x, Flipper.y, ballx, bally) - 90)
If DiffAngle > 180 Then DiffAngle = DiffAngle - 360
If DistanceFromFlipper(ballx,bally,Flipper) < 48 and DiffAngle <= 90 and Distance(ballx,bally,Flipper.x,Flipper.y) < Flipper.Length Then
FlipperTrigger = True
Else
FlipperTrigger = False
End If
End Function