Arngrim

Hercules

Nov 17th, 2019
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.35 KB | None | 0 0
  1. ' ---------------------------------------------
  2. ' HERCULES
  3. ' ---------------------------------------------
  4.  
  5. Option Explicit
  6. Randomize
  7. 'StartShake
  8.  
  9. On Error Resume Next
  10. ExecuteGlobal GetTextFile("Controller.vbs")
  11. If Err Then MsgBox "Unable to open Controller.vbs. Ensure that it is in the Scripts folder of Visual Pinball."
  12. On Error Goto 0
  13.  
  14.  
  15. Const BallSize = 100 'Its huge!
  16.  
  17. Dim VarHidden, UseVPMDMD
  18. If Hercules.ShowDT = true then
  19. UseVPMDMD = True
  20. VarHidden = 0
  21. lockdown.visible = true
  22. Primitive8.visible = true
  23. leftrail.visible = true
  24. rightrail.visible = true
  25. else
  26. UseVPMDMD = False
  27. VarHidden = 1
  28. lockdown.visible = false
  29. leftrail.visible = false
  30. rightrail.visible = false
  31. Primitive8.visible = false
  32.  
  33. end if
  34.  
  35. LoadVPM "01120000", "ATARI2.VBS", 3.0
  36.  
  37. '==================================================================
  38. ' Game Specific code starts here
  39. '==================================================================
  40. Const cGameName = "hercules" ' PinMAME short name
  41. Const cCredits = "Hercules Total rebuild in vp10 by randr"
  42. Const UseSolenoids = 2
  43. Const UseLamps = True
  44. Const UseGI = False
  45.  
  46. ' Standard Sounds
  47. Const SSolenoidOn = ""
  48. Const SSolenoidOff = ""
  49. Const SFlipperOn = "flipup"
  50. Const SFlipperOff = "flipdown"
  51. Const SCoin = "coin3"
  52.  
  53. ' Solenoids
  54. Const sKnocker = 3
  55. Const sRJet = 4
  56. Const sLJet = 5
  57. Const sRSling = 8
  58. Const sLSling = 9
  59. Const sKnocker2 = 10
  60. Const sKnocker3 = 11
  61. Const sKnocker4 = 12
  62. Const sKnocker5 = 13
  63. Const sBallRelease = 15
  64. Const sEnable = 16
  65. Const sCLo = 17
  66.  
  67. '----------------------------------------------------
  68. ' Bind events to solenoids
  69. ' Last argument will always be "enabled" (True, False)
  70. '----------------------------------------------------
  71. SolCallback(sBallRelease) = "bsTrough.SolOut"
  72. SolCallback(sKnocker) = "vpmSolSound SoundFX(""knock"",DOFKnocker),"
  73. 'SolCallback(sLSling) = "vpmSolSound SoundFX(""hercsling"",DOFContactors),"
  74. 'SolCallback(sRSling) = "vpmSolSound SoundFX(""hercsling"",DOFContactors),"
  75. SolCallback(sLJet) = "Bumper 1,"
  76. SolCallback(sRJet) = "Bumper 2,"
  77. SolCallback(sEnable) = "vpmNudge.SolGameOn"
  78. SolCallback(sLLFlipper) = "SolLFlipper"
  79. SolCallback(sLRFlipper) = "SolRFlipper"
  80. 'SolCallback(sLLFlipper) = "vpmSolFlipper LeftFlipper, Nothing,"
  81. 'SolCallback(sLRFlipper) = "vpmSolFlipper RightFlipper, Nothing,"
  82.  
  83. Sub Bumper(number, enabled)
  84. vpmSolSound SoundFX("hercjet",DOFContactors), enabled
  85. if enabled then BumperState(number) = 3
  86. End Sub
  87.  
  88. Sub SolLFlipper(Enabled)
  89. If Enabled Then
  90. PlaySound SoundFX("flipup",DOFFlippers):LeftFlipper.RotateToEnd
  91. Else
  92. PlaySound SoundFX("flipdown",DOFFlippers):LeftFlipper.RotateToStart
  93. End If
  94. End Sub
  95.  
  96. Sub SolRFlipper(Enabled)
  97. If Enabled Then
  98. PlaySound SoundFX("flipup",DOFFlippers):RightFlipper.RotateToEnd
  99. Else
  100. PlaySound SoundFX("flipdown",DOFFlippers):RightFlipper.RotateToStart
  101. End If
  102. End Sub
  103.  
  104. '--------------------------------
  105. ' Init the table, Start VPinMAME
  106. '--------------------------------
  107.  
  108. Dim AttractCount
  109. Dim Cue
  110. Dim BallActive
  111. 'Dim BallVel(4)
  112. Dim BumperState(2)
  113. Dim bsTrough
  114. dim bump1
  115. dim bump2
  116.  
  117. Sub Hercules_Init
  118. vpmInit Me
  119. On Error Resume Next
  120. With Controller
  121. .GameName = cGameName
  122. .SplashInfoLine = cCredits
  123. .HandleKeyboard = 0
  124. .ShowTitle = 0
  125. .ShowDMDOnly = 1
  126. .ShowFrame = 0
  127. '.HandleMechanics = 1
  128. .Hidden = VarHidden
  129. On Error Resume Next
  130. .Run
  131. If Err Then MsgBox Err.Description
  132. On Error Goto 0
  133. End With
  134. ' Main Timer init
  135. PinMAMETimer.Interval = PinMAMEInterval
  136. PinMAMETimer.Enabled = True
  137. ' Nudging
  138. vpmNudge.TiltSwitch = 48
  139. vpmNudge.Sensitivity = 3
  140. vpmNudge.TiltObj = Array(Bumper1,Bumper2,LeftSlingshot,RightSlingshot)
  141.  
  142. Set bsTrough = New cvpmBallStack ' Trough handler
  143. bsTrough.InitSw 0,1,0,0,0,0,0,0
  144. bsTrough.InitKick Kicker1, 90, 4
  145. bsTrough.InitExitSnd SoundFX("BallOut",DOFContactors), SoundFX("BallOut",DOFContactors)
  146. bsTrough.BallImage = "Cue"
  147. bsTrough.Balls = 1
  148.  
  149. Dim f
  150. For f=1 to 6
  151.  
  152. Next
  153. End Sub
  154.  
  155. '-------------------
  156. ' keyboard handlers
  157. '-------------------
  158. Sub Hercules_KeyUp(ByVal keycode)
  159. If vpmKeyUp(keycode) Then Exit Sub
  160. If keycode = PlungerKey Then PlaySound "Plunger" : Plunger.Fire
  161. End Sub
  162.  
  163. Sub Hercules_KeyDown(ByVal keycode)
  164. If vpmKeyDown(keycode) Then Exit Sub
  165. If keycode = PlungerKey Then Plunger.Pullback
  166. End Sub
  167.  
  168.  
  169. Sub FlipperDecals_Timer
  170. LFD.RotAndTra2=LeftFlipper.CurrentAngle
  171. RFD.RotAndTra2=RightFlipper.CurrentAngle
  172.  
  173. End Sub
  174.  
  175. Sub timergate_Timer
  176. prightgate.rotz=gate3.CurrentAngle
  177. pleftgate.rotz=gate1.CurrentAngle
  178.  
  179. End Sub
  180.  
  181. Sub Bumper1_Hit:bump1 = 1:Me.TimerEnabled = 1:vpmTimer.PulseSw 53::End Sub
  182.  
  183. Sub Bumper1_Timer()
  184. Select Case bump1
  185. Case 1:Pring1.z = 3:bump1 = 2
  186. Case 2:Pring1.z = -3:bump1 = 3
  187. Case 3:Pring1.z = -13:bump1 = 4
  188. Case 4:Pring1.z = -13:bump1 = 5
  189. Case 5:Pring1.z = -3:bump1 = 6
  190. Case 6:Pring1.z = 3:bump1 = 7
  191. case 7:Me.TimerEnabled = 0
  192. End Select
  193. End Sub
  194.  
  195. Sub Bumper2_Hit:vpmTimer.PulseSw 52:bump2 = 1:Me.TimerEnabled = 1:End Sub
  196.  
  197. Sub Bumper2_Timer()
  198. Select Case bump2
  199. Case 1:Pring2.z = 3:bump2 = 2
  200. Case 2:Pring2.z = -3:bump2 = 3
  201. Case 3:Pring2.z = -13:bump2 = 4
  202. Case 4:Pring2.z = -13:bump2 = 5
  203. Case 5:Pring2.z = -3:bump2 = 6
  204. Case 6:Pring2.z = 3:bump2 = 7
  205. case 7:Me.TimerEnabled = 0
  206. End Select
  207. End Sub
  208.  
  209. '---------------------------------------------------------------
  210. ' SWITCH HANDLING
  211. '---------------------------------------------------------------
  212. Sub Drain_Hit : PlaySound "Drain" : bsTrough.AddBall Me : BallActive = 0 : End Sub
  213. Sub Roll3_Hit : Controller.Switch(12) = True : End Sub
  214. Sub Roll3_Unhit : Controller.Switch(12) = False : End Sub
  215.  
  216. Sub Rubber7_Slingshot : vpmTimer.pulseSw 13 : End Sub
  217. Sub Rubber12_Slingshot : vpmTimer.pulseSw 13 : End Sub
  218. Sub Roll1_Hit : Controller.Switch(13) = True : End Sub
  219. Sub Roll1_Unhit : Controller.Switch(13) = False : End Sub
  220. Sub Roll4_Hit : Controller.Switch(13) = True : End Sub
  221. Sub Roll4_Unhit : Controller.Switch(13) = False : End Sub
  222. Sub Roll5_Hit : Controller.Switch(13) = True : End Sub
  223. Sub Roll5_Unhit : Controller.Switch(13) = False : End Sub
  224.  
  225. Sub Roll6_Hit : Controller.Switch(18) = True : End Sub
  226. Sub Roll6_Unhit : Controller.Switch(18) = False : End Sub
  227. Sub Roll7_Hit : Controller.Switch(19) = True : End Sub
  228. Sub Roll7_Unhit : Controller.Switch(19) = False : End Sub
  229. Sub Roll8_Hit : Controller.Switch(20) = True : End Sub
  230. Sub Roll8_Unhit : Controller.Switch(20) = False : End Sub
  231. Sub Lane1_Hit : Controller.Switch(21) = True : End Sub
  232. Sub Lane1_Unhit : Controller.Switch(21) = False : End Sub
  233. Sub Lane2_Hit : Controller.Switch(24) = True : End Sub
  234. Sub Lane2_Unhit : Controller.Switch(24) = False : End Sub
  235. Sub Lane3_Hit : Controller.Switch(25) = True : End Sub
  236. Sub Lane3_Unhit : Controller.Switch(25) = False : End Sub
  237.  
  238. Sub Roll2_Hit : Controller.Switch(26) = True : End Sub
  239. Sub Roll2_Unhit : Controller.Switch(26) = False : End Sub
  240. Sub Roll9_Hit : Controller.Switch(26) = True : End Sub
  241. Sub Roll9_Unhit : Controller.Switch(26) = False : End Sub
  242.  
  243. Sub LeftOutLane_Hit : Controller.Switch(28) = True : End Sub
  244. Sub LeftOutLane_Unhit : Controller.Switch(28) = False : End Sub
  245. Sub LeftInLane_Hit : Controller.Switch(29) = True : End Sub
  246. Sub LeftInLane_Unhit : Controller.Switch(29) = False : End Sub
  247. Sub RightInLane_Hit : Controller.Switch(32) = True : End Sub
  248. Sub RightInLane_Unhit : Controller.Switch(32) = False : End Sub
  249. Sub RightOutLane_Hit : Controller.Switch(33) = True : End Sub
  250. Sub RightOutLane_Unhit : Controller.Switch(33) = False : End Sub
  251. Sub Spinner1_Spin : vpmTimer.pulseSw 40 : End Sub
  252. 'Sub Bumper2_Hit : vpmTimer.PulseSw 52 : End Sub
  253. 'Sub Bumper1_Hit : vpmTimer.PulseSw 53 : End Sub
  254. Sub RightSlingShot_Slingshot : vpmTimer.PulseSw 56 : End Sub
  255. Sub LeftSlingShot_Slingshot : vpmTimer.PulseSw 57 : End Sub
  256.  
  257. Sub Gate1_Hit : PlaySound "Gate" : End Sub
  258. Sub Gate2_Hit : PlaySound "Gate" : End Sub
  259. Sub Gate3_Hit : PlaySound "Gate" : End Sub
  260. Sub WoodHit1_Hit : PlaySound "Bump3" : End Sub
  261. Sub WoodHit2_Hit : PlaySound "Bump3" : End Sub
  262. Sub WoodHit3_Hit : PlaySound "Bump3" : End Sub
  263. Sub WoodHit4_Hit : PlaySound "metalhit_thin" : End Sub
  264.  
  265. Sub ActiveOn_Hit()
  266. Set Cue = ActiveBall
  267. BallActive = 1
  268. End Sub
  269.  
  270. '-------------------------------------
  271. ' Map lights into array
  272. '-------------------------------------
  273. Set Lights( 1) = Bonus1K
  274. Set Lights( 2) = Bonus2K
  275. Set Lights( 3) = Bonus3K
  276. Set Lights( 4) = Bonus4K
  277. Set Lights( 5) = Bonus5K
  278. Set Lights( 6) = Bonus6K
  279. Set Lights( 7) = Bonus7K
  280. Set Lights( 8) = Bonus8K
  281. Set Lights( 9) = Bonus9K
  282. Set Lights(10) = Bonus10K
  283. Set Lights(11) = Bonus20K
  284. Set Lights(12) = Bonus30K
  285. Set Lights(13) = Bonus40K
  286. Set Lights(14) = Yellow1
  287. Set Lights(15) = Yellow2
  288. Set Lights(16) = Yellow3
  289. Set Lights(17) = Yellow4
  290. Set Lights(18) = TopYellow
  291. Set Lights(19) = Orange1
  292. Set Lights(20) = Orange2
  293. Set Lights(21) = Orange3
  294. Set Lights(22) = Orange4
  295. Set Lights(23) = Orange5
  296. Set Lights(24) = TopOrange
  297. Set Lights(25) = Red1
  298. Set Lights(26) = Red2
  299. Set Lights(27) = Red3
  300. Set Lights(28) = Red4
  301. Set Lights(29) = Red5
  302. Set Lights(30) = Red6
  303. Set Lights(31) = TopRed
  304. Set Lights(32) = LeftSP
  305. Set Lights(33) = LeftXB
  306. Set Lights(34) = RightXB
  307. Set Lights(35) = RightSP
  308. Set Lights(36) = TargetLight1
  309. Set Lights(37) = TargetLight2
  310. Set Lights(38) = TargetLight3
  311. Set Lights(39) = TargetLight4
  312. Set Lights(42) = SpinRed
  313. Set Lights(44) = ShootAgainLight
  314. Set Lights(45) = SideYellow
  315. Set Lights(46) = SideOrange
  316. Set Lights(47) = SideRed
  317. Set Lights(49) = SpinYellow
  318. Set Lights(50) = SpinOrange
  319.  
  320. Sub editDips
  321. With vpmDips
  322. .AddForm 334,215,"Hercules DIP switches"
  323. .AddChk 194,146,150,Array("Match feature",&H00000080)
  324. .AddChk 194,162,150,Array("High Score Million Limit",&H00400000)
  325. .AddChk 194,178,150,Array("High Score Display",&H00800000)
  326. .AddChk 194,194,150,Array("Feature ladder memory",&H20000000)
  327. .AddFrame 2, 2, 90,"High score award",&HC0000000,Array("3 replays",&H40000000,"2 replays",&HC0000000,"1 replay",0,"Nothing",&H80000000)
  328. .AddFrame 2, 77, 90,"Maximum credits",&H00000007,Array("5 credits",7,"10 credits",6,"15 credits",5,"20 credits",4,"25 credits",3,"30 credits",2,"35 credits",1,"40 credits",0)
  329. .AddFrame 107, 2, 90,"Special award",&H00000050,Array("Replay",&H50,"Add a ball",&H40,"50,000 points",&H10,"60,000 points",0)
  330. .AddFrame 107, 82, 90,"Extra award",&H00006000,Array("Extra ball",&H6000,"20,000 points",&H4000,"30,000 points",0)
  331. .AddFrame 107,147, 72,"Return lanes",&H00208000,Array("Always off",0,"Alternating",&H200000,"Both on",&H00208000)
  332. .AddFrame 212, 2,100,"Upper lanes",&H00001000,Array("Start + advance",&H1000,"Start only",0)
  333. .AddFrame 212, 49,100,"Game mode",&H00000020,Array("Coin-op",&H20,"Free play",0)
  334. .AddFrame 212, 96,100,"Balls in play",&H1F1F0008,Array("3 balls",&H1D150008,"5 balls",&H1D150000)
  335. .ViewDips
  336. End With
  337. End Sub
  338. Set vpmDips = New cvpmDips
  339. Set vpmShowDips = GetRef("editDips")
  340.  
  341. Sub GameTimer_Timer()
  342.  
  343. End Sub
  344.  
  345. ''''''''''''''''''''''''''''''''''''''''''''
  346. '''''''''Targets''''''''''''''''''''''''''''
  347. ''''''''''''''''''''''''''''''''''''''''''''
  348.  
  349. Dim TargetTR, TargetTL, TargetML, TargetMR
  350.  
  351. Sub S_Top_P_Hit:TargetTL = 1:Me.TimerEnabled = 1:vpmTimer.PulseSw(35):Playsound SoundFX("Bump3",DOFTargets):End Sub
  352.  
  353. Sub S_Top_P_Timer()
  354. Select Case TargetTL
  355. Case 1:Target2.Transy = -5:TargetTL = 2
  356. Case 2:TargetTL = 3
  357. Case 3:Target2.Transy = 0:TargetTL = 4
  358. Case 4:Me.TimerEnabled = 0
  359. End Select
  360. End Sub
  361.  
  362. Sub S_L_Target_Hit:TargetML = 1:Me.TimerEnabled = 1:vpmTimer.PulseSw(34):Playsound SoundFX("Bump3",DOFTargets):End Sub
  363.  
  364. Sub S_L_Target_Timer()
  365. Select Case TargetML
  366. Case 1:Target1.Transy = -5:TargetML = 2
  367. Case 2:TargetML = 3
  368. Case 3:Target1.Transy = 0:TargetML = 4
  369. Case 4:Me.TimerEnabled = 0
  370. End Select
  371. End Sub
  372.  
  373. Sub S_R_Target_Hit:TargetMR = 1:Me.TimerEnabled = 1:vpmTimer.PulseSw(36):Playsound SoundFX("Bump3",DOFTargets):End Sub
  374.  
  375. Sub S_R_Target_Timer()
  376. Select Case TargetMR
  377. Case 1:Target3.Transy = -5:TargetMR = 2
  378. Case 2:TargetMR = 3
  379. Case 3:Target3.Transy = 0:TargetMR = 4
  380. Case 4:Me.TimerEnabled = 0
  381. End Select
  382. End Sub
  383.  
  384. Sub S_Top_Y_Hit:TargetTR = 1:Me.TimerEnabled = 1:vpmTimer.PulseSw(37):Playsound SoundFX("Bump3",DOFTargets):End Sub
  385.  
  386. Sub S_Top_Y_Timer()
  387. Select Case TargetTR
  388. Case 1:Target4.Transy = -5:TargetTR = 2
  389. Case 2:TargetTR = 3
  390. Case 3:Target4.Transy = 0:TargetTR = 4
  391. Case 4:Me.TimerEnabled = 0
  392. End Select
  393. End Sub
  394.  
  395. '**********Sling Shot Animations
  396. ' Rstep and Lstep are the variables that increment the animation
  397. '****************
  398. Dim RStep, Lstep
  399.  
  400. Sub RightSlingShot_Slingshot
  401. vpmTimer.PulseSw 56
  402. PlaySound SoundFX("hercsling",DOFContactors), 0, 1, 0.05, 0.05
  403. RSling.Visible = 0
  404. RSling1.Visible = 1
  405. sling1.TransZ = -20
  406. RStep = 0
  407. RightSlingShot.TimerEnabled = 1
  408. End Sub
  409.  
  410. Sub RightSlingShot_Timer
  411.  
  412. Select Case RStep
  413. Case 3:RSLing1.Visible = 0:RSLing2.Visible = 1:sling1.TransZ = -10
  414. Case 4:RSLing2.Visible = 0:RSLing.Visible = 1:sling1.TransZ = 0':RightSlingShot.TimerEnabled' = 0:gi1.State = 1:Gi2.State = 1
  415. End Select
  416. RStep = RStep + 1
  417. End Sub
  418.  
  419. Sub LeftSlingShot_Slingshot
  420. vpmTimer.PulseSw 57
  421. PlaySound SoundFX("hercsling",DOFContactors),0,1,-0.05,0.05
  422. LSling.Visible = 0
  423. LSling1.Visible = 1
  424. sling2.TransZ = -20
  425. LStep = 0
  426. LeftSlingShot.TimerEnabled = 1
  427. End Sub
  428.  
  429. Sub LeftSlingShot_Timer
  430.  
  431. Select Case LStep
  432. Case 3:LSLing1.Visible = 0:LSLing2.Visible = 1:sling2.TransZ = -10
  433. Case 4:LSLing2.Visible = 0:LSLing.Visible = 1:sling2.TransZ = 0':LeftSlingShot.TimerEnabled' = 0:gi3.State = 1:Gi4.State = 1
  434. End Select
  435. LStep = LStep + 1
  436. End Sub
  437.  
  438.  
  439. ' *********************************************************************
  440. ' Supporting Ball & Sound Functions
  441. ' *********************************************************************
  442.  
  443. Function Vol(ball) ' Calculates the Volume of the sound based on the ball speed
  444. Vol = Csng(BallVel(ball) ^2 / 50)
  445. End Function
  446.  
  447. Function Vol2(ball1, ball2) ' Calculates the Volume of the sound based on the speed of two balls
  448. Vol2 = (Vol(ball1) + Vol(ball2) ) / 2
  449. End Function
  450.  
  451. Function Pan(ball) ' Calculates the pan for a ball based on the X position on the table. "table1" is the name of the table
  452. Dim tmp
  453. tmp = ball.x * 2 / Hercules.width-1
  454. If tmp> 0 Then
  455. Pan = Csng(tmp ^10)
  456. Else
  457. Pan = Csng(-((- tmp) ^10) )
  458. End If
  459. End Function
  460.  
  461. Function Pitch(ball) ' Calculates the pitch of the sound based on the ball speed
  462. Pitch = BallVel(ball) * 20
  463. End Function
  464.  
  465. Function BallVel(ball) 'Calculates the ball speed
  466. BallVel = INT(SQR((ball.VelX ^2) + (ball.VelY ^2) ) )
  467. End Function
  468.  
  469. '*****************************************
  470. ' JP's VP10 Collision & Rolling Sounds
  471. '*****************************************
  472.  
  473. Const tnob = 8 ' total number of balls
  474. ReDim rolling(tnob)
  475. ReDim collision(tnob)
  476. Initcollision
  477.  
  478. Sub Initcollision
  479. Dim i
  480. For i = 0 to tnob
  481. collision(i) = -1
  482. rolling(i) = False
  483. Next
  484. End Sub
  485.  
  486. Sub CollisionTimer_Timer()
  487. Dim BOT, B, B1, B2, dx, dy, dz, distance, radii
  488. BOT = GetBalls
  489.  
  490. ' rolling
  491.  
  492. For B = UBound(BOT) +1 to tnob
  493. rolling(b) = False
  494. StopSound("fx_ballrolling" & b)
  495. Next
  496.  
  497. If UBound(BOT) = -1 Then Exit Sub
  498.  
  499. For B = 0 to UBound(BOT)
  500. If BallVel(BOT(b) ) > 1 AND BOT(b).z < 100 Then
  501. rolling(b) = True
  502. PlaySound("fx_ballrolling" & b), -1, Vol(BOT(b) ), Pan(BOT(b) ), 0, Pitch(BOT(b) ), 1, 0
  503. Else
  504. If rolling(b) = True Then
  505. StopSound("fx_ballrolling" & b)
  506. rolling(b) = False
  507. End If
  508. End If
  509. Next
  510.  
  511. 'collision
  512.  
  513. If UBound(BOT) < 1 Then Exit Sub
  514.  
  515. For B1 = 0 to UBound(BOT)
  516. For B2 = B1 + 1 to UBound(BOT)
  517. dz = INT(ABS((BOT(b1).z - BOT(b2).z) ) )
  518. radii = BOT(b1).radius + BOT(b2).radius
  519. If dz <= radii Then
  520.  
  521. dx = INT(ABS((BOT(b1).x - BOT(b2).x) ) )
  522. dy = INT(ABS((BOT(b1).y - BOT(b2).y) ) )
  523. distance = INT(SQR(dx ^2 + dy ^2) )
  524.  
  525. If distance <= radii AND (collision(b1) = -1 OR collision(b2) = -1) Then
  526. collision(b1) = b2
  527. collision(b2) = b1
  528. PlaySound("fx_collide"), 0, Vol2(BOT(b1), BOT(b2)), Pan(BOT(b1)), 0, Pitch(BOT(b1)), 0, 0
  529. Else
  530. If distance > (radii + 10) Then
  531. If collision(b1) = b2 Then collision(b1) = -1
  532. If collision(b2) = b1 Then collision(b2) = -1
  533. End If
  534. End If
  535. End If
  536. Next
  537. Next
  538. End Sub
  539.  
  540.  
  541. '************************************
  542. ' What you need to add to your table
  543. '************************************
  544.  
  545. ' a timer called CollisionTimer. With a fast interval, like from 1 to 10
  546. ' one collision sound, in this script is called fx_collide
  547. ' as many sound files as max number of balls, with names ending with 0, 1, 2, 3, etc
  548. ' for ex. as used in this script: fx_ballrolling0, fx_ballrolling1, fx_ballrolling2, fx_ballrolling3, etc
  549.  
  550.  
  551. '******************************************
  552. ' Explanation of the rolling sound routine
  553. '******************************************
  554.  
  555. ' sounds are played based on the ball speed and position
  556.  
  557. ' the routine checks first for deleted balls and stops the rolling sound.
  558.  
  559. ' The For loop goes through all the balls on the table and checks for the ball speed and
  560. ' if the ball is on the table (height lower than 30) then then it plays the sound
  561. ' otherwise the sound is stopped, like when the ball has stopped or is on a ramp or flying.
  562.  
  563. ' The sound is played using the VOL, PAN and PITCH functions, so the volume and pitch of the sound
  564. ' will change according to the ball speed, and the PAN function will change the stereo position according
  565. ' to the position of the ball on the table.
  566.  
  567.  
  568. '**************************************
  569. ' Explanation of the collision routine
  570. '**************************************
  571.  
  572. ' The Double For loop: This is a double cycle used to check the collision between a ball and the other ones.
  573. ' If you look at the parameters of both cycles, you’ll notice they are designed to avoid checking
  574. ' collision twice. For example, I will never check collision between ball 2 and ball 1,
  575. ' because I already checked collision between ball 1 and 2. So, if we have 4 balls,
  576. ' the collision checks will be: ball 1 with 2, 1 with 3, 1 with 4, 2 with 3, 2 with 4 and 3 with 4.
  577.  
  578. ' Sum first the radius of both balls, and if the height between them is higher then do not calculate anything more,
  579. ' since the balls are on different heights so they can't collide.
  580.  
  581. ' The next 3 lines calculates distance between xth and yth balls with the Pytagorean theorem,
  582.  
  583. ' The first "If": Checking if the distance between the two balls is less than the sum of the radius of both balls,
  584. ' and both balls are not already colliding.
  585.  
  586. ' Why are we checking if balls are already in collision?
  587. ' Because we do not want the sound repeting when two balls are resting closed to each other.
  588.  
  589. ' Set the collision property of both balls to True, and we assign the number of the ball colliding
  590.  
  591. ' Play the collide sound of your choice using the VOL, PAN and PITCH functions
  592.  
  593. ' Last lines: If the distance between 2 balls is more than the radius of a ball,
  594. ' then there is no collision and then set the collision property of the ball to False (-1).
  595.  
  596.  
  597. Sub Pins_Hit (idx)
  598. PlaySound "pinhit_low", 0, Vol(ActiveBall), Pan(ActiveBall), 0, Pitch(ActiveBall), 0, 0
  599. End Sub
  600.  
  601. Sub Targets_Hit (idx)
  602. PlaySound "target", 0, Vol(ActiveBall), Pan(ActiveBall), 0, Pitch(ActiveBall), 0, 0
  603. End Sub
  604.  
  605. Sub Metals_Thin_Hit (idx)
  606. PlaySound "metalhit_thin", 0, Vol(ActiveBall), Pan(ActiveBall), 0, Pitch(ActiveBall), 1, 0
  607. End Sub
  608.  
  609. Sub Metals_Medium_Hit (idx)
  610. PlaySound "metalhit_medium", 0, Vol(ActiveBall), Pan(ActiveBall), 0, Pitch(ActiveBall), 1, 0
  611. End Sub
  612.  
  613. Sub Metals2_Hit (idx)
  614. PlaySound "metalhit2", 0, Vol(ActiveBall), Pan(ActiveBall), 0, Pitch(ActiveBall), 1, 0
  615. End Sub
  616.  
  617. Sub Gates_Hit (idx)
  618. PlaySound "gate4", 0, Vol(ActiveBall), Pan(ActiveBall), 0, Pitch(ActiveBall), 1, 0
  619. End Sub
  620.  
  621. Sub Spinner_Spin
  622. vpmTimer.pulseSw 40
  623. End Sub
  624.  
  625. Sub Rubbers_Hit(idx)
  626. dim finalspeed
  627. finalspeed=SQR(activeball.velx * activeball.velx + activeball.vely * activeball.vely)
  628. If finalspeed > 1 then
  629. PlaySound "fx_rubber2", 0, Vol(ActiveBall), Pan(ActiveBall), 0, Pitch(ActiveBall), 1, 0
  630. End if
  631. If finalspeed >= 2 AND finalspeed <= 1 then
  632. RandomSoundRubber()
  633. End If
  634. End Sub
  635.  
  636. Sub Posts_Hit(idx)
  637. dim finalspeed
  638. finalspeed=SQR(activeball.velx * activeball.velx + activeball.vely * activeball.vely)
  639. If finalspeed > 16 then
  640. PlaySound "fx_rubber2", 0, Vol(ActiveBall), Pan(ActiveBall), 0, Pitch(ActiveBall), 1, 0
  641. End if
  642. If finalspeed >= 6 AND finalspeed <= 16 then
  643. RandomSoundRubber()
  644. End If
  645. End Sub
  646.  
  647. Sub RandomSoundRubber()
  648. Select Case Int(Rnd*3)+1
  649. Case 1 : PlaySound "rubber_hit_1", 0, Vol(ActiveBall), Pan(ActiveBall), 0, Pitch(ActiveBall), 1, 0
  650. Case 2 : PlaySound "rubber_hit_2", 0, Vol(ActiveBall), Pan(ActiveBall), 0, Pitch(ActiveBall), 1, 0
  651. Case 3 : PlaySound "rubber_hit_3", 0, Vol(ActiveBall), Pan(ActiveBall), 0, Pitch(ActiveBall), 1, 0
  652. End Select
  653. End Sub
  654.  
  655. Sub LeftFlipper_Collide(parm)
  656. RandomSoundFlipper()
  657. End Sub
  658.  
  659. Sub RightFlipper_Collide(parm)
  660. RandomSoundFlipper()
  661. End Sub
  662.  
  663. Sub RandomSoundFlipper()
  664. Select Case Int(Rnd*3)+1
  665. Case 1 : PlaySound "fx_rubber2", 0, Vol(ActiveBall), Pan(ActiveBall), 0, Pitch(ActiveBall), 1, 0
  666. Case 2 : PlaySound "fx_rubber2", 0, Vol(ActiveBall), Pan(ActiveBall), 0, Pitch(ActiveBall), 1, 0
  667. Case 3 : PlaySound "fx_rubber2", 0, Vol(ActiveBall), Pan(ActiveBall), 0, Pitch(ActiveBall), 1, 0
  668. End Select
  669. End Sub
  670.  
  671. Sub AttractTimer_Timer()
  672. AttractCount = AttractCount + 1
  673. End Sub
Advertisement
Add Comment
Please, Sign In to add comment