Media.monkey2 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #Import "PoolMod"
  2. #Import "data/poolAtlasb.png"
  3. #Import "data/hit03.ogg"
  4. #Import "data/hit04.ogg"
  5. #Import "data/hit05.ogg"
  6. #Import "data/hit06.ogg"
  7. #Import "data/shoot.ogg"
  8. #Import "data/bank01.ogg"
  9. #Import "data/bank02.ogg"
  10. #Import "data/rackup.ogg"
  11. #Import "data/applaused.ogg"
  12. #Import "data/pocket1.ogg"
  13. #Import "data/fail.ogg"
  14. #Import "data/completion.ogg"
  15. #Import "data/beep.ogg"
  16. #Import "data/beep2.ogg"
  17. Global media:Media
  18. Class Media
  19. Field titleImg:Image
  20. Field tableImg:Image
  21. Field railImg:Image
  22. Field ballImg:Image
  23. Field stickImg:Image[]
  24. Field ghostImg:Image[]
  25. Field arrowsImg:Image
  26. Field rotatorImg:Image
  27. Field buttonImg:Image[]
  28. Field smallBtnImg:Image[]
  29. Field stripImg:Image
  30. Field getNameImg:Image
  31. Field logoImg:Image
  32. Field frameTopImg:Image[]
  33. Field frameBotImg:Image[]
  34. Field topImg:Image
  35. Field botImg:Image
  36. Field lrImg:Image[]
  37. Field rectImg:Image
  38. Field meterImg:Image
  39. Field stretchImg:Image
  40. Field sliderImg:Image
  41. Field ballCol:Sound[] = New Sound[4]
  42. Field shootCol:Sound
  43. Field railCol:Sound[] = New Sound[2]
  44. Field rackUp:Sound
  45. Field applause:Sound
  46. Field pocketCol:Sound
  47. Field pocketChannel:Channel = New Channel
  48. Field scratchSnd:Sound
  49. Field completionSnd:Sound
  50. Field beepSnd:Sound
  51. Field beepBSnd:Sound
  52. Field arcImg:Image = Null
  53. Field lineImg:Image = Null
  54. Field channeltime:Int[] = New Int[8]
  55. Field colChannel:Channel[] = New Channel[4]
  56. Field colChanIndex:Int = 0
  57. Field colLastChanIndex:Int = 3
  58. Field colFirstChanIndex:Int = 0
  59. Field scoreChannel:Channel[] = New Channel[5]
  60. Field scoreChanIndex:Int = 0
  61. Field scoreLastChan:Int = 5
  62. Method New()
  63. End Method
  64. Method New(atlasImg:Image)
  65. If(atlasImg = Null) RuntimeError("unable to load GameAtlas.png")
  66. titleImg = New Image(atlasImg,0,544,640,480)
  67. tableImg = New Image(atlasImg,0,0,640,360)
  68. railImg = New Image(atlasImg,640,0,384,41)
  69. ballImg = New Image(atlasImg,996,104,23,23)
  70. ballImg.Handle= New Vec2f(.4,.4)
  71. stickImg = LoadFrames(atlasImg,1,501,392,9,1)
  72. stickImg[0].Handle = New Vec2f(1.0,.5)
  73. ghostImg = LoadFrames(atlasImg,640,140,22,22,3)
  74. ghostImg[0].Handle = New Vec2f(.5,.5)
  75. ghostImg[1].Handle = New Vec2f(.5,.5)
  76. ghostImg[2].Handle = New Vec2f(.5,.5)
  77. arrowsImg = New Image(atlasImg,890,141,47,47)
  78. arrowsImg.Handle = New Vec2f(23.0/47.0,23.0/47.0)
  79. rotatorImg = New Image(atlasImg,788,140,101,64)
  80. rotatorImg.Handle = New Vec2f(51.0/101.0,43.0/64.0)
  81. buttonImg = LoadFrames (atlasImg,640,41,190,62,2)
  82. smallBtnImg = LoadFrames(atlasImg,643,289,130,50,2)
  83. stripImg = New Image(atlasImg,1015,130,1,3)
  84. stripImg.Handle = New Vec2f(0.0,.5)
  85. getNameImg = New Image(atlasImg,641,848,383,176)
  86. logoImg = New Image(atlasImg,640,545,255,275)
  87. frameTopImg = LoadFrames(atlasImg,997,128,4,4,2)
  88. frameBotImg = LoadFrames(atlasImg,997,132,4,4,2)
  89. topImg = New Image(atlasImg,1000,128,1,4)
  90. botImg = New Image(atlasImg,1000,132,1,4)
  91. lrImg = LoadFrames(atlasImg,997,131,4,1,2)
  92. rectImg = New Image(atlasImg,1011,131,1,1)
  93. meterImg = New Image(atlasImg,640,103,346,36)
  94. stretchImg = New Image(atlasImg,988,103,1,36)
  95. sliderImg = New Image(atlasImg,990,103,4,36)
  96. ballCol[0] = Sound.Load("asset::hit03.ogg")
  97. If ballCol[0] = Null RuntimeError("unable to load hit03.ogg")
  98. ballCol[1] = Sound.Load("asset::hit04.ogg")
  99. If ballCol[1] = Null RuntimeError("unable to load hti04.ogg")
  100. ballCol[2] = Sound.Load("asset::hit05.ogg")
  101. If ballCol[2] = Null RuntimeError("unable to lead hit05.ogg")
  102. ballCol[3] = Sound.Load("asset::hit06.ogg")
  103. If ballCol[3] = Null RuntimeError("unable to load hit06.ogg")
  104. shootCol = Sound.Load("asset::shoot.ogg")
  105. If shootCol = Null RuntimeError("unable to load shoot.ogg")
  106. railCol[0] = Sound.Load("asset::bank01.ogg")
  107. If railCol[0] = Null RuntimeError("unable to load bank01.ogg")
  108. railCol[1] = Sound.Load("asset::bank02.ogg")
  109. If railCol[1] = Null RuntimeError("unable to load bank02.ogg")
  110. rackUp = Sound.Load("asset::rackup.ogg")
  111. If rackUp = Null RuntimeError("unable To load rackUp.ogg")
  112. applause = Sound.Load("asset::applaused.ogg")
  113. If applause = Null RuntimeError("unable to load applaused.ogg")
  114. pocketCol = Sound.Load("asset::pocket1.ogg")
  115. If pocketCol = Null RuntimeError("unable to load pocket1.ogg")
  116. scratchSnd = Sound.Load("asset::fail.ogg")
  117. If scratchSnd = Null RuntimeError("unable to load fail.ogg")
  118. completionSnd = Sound.Load("asset::completion.ogg")
  119. If completionSnd = Null RuntimeError("unable to load completionSnd.ogg")
  120. beepSnd = Sound.Load("asset::beep.ogg")
  121. If beepSnd = Null Print("unable to load beep.ogg")
  122. beepBSnd = Sound.Load("asset::beep2.ogg")
  123. If beepBSnd = Null RuntimeError("unable to load beep2.ogg")
  124. For Local i:Int = 0 Until 4
  125. colChannel[i] = New Channel()
  126. Next
  127. For Local i:Int = 0 Until scoreLastChan
  128. scoreChannel[i] = New Channel
  129. Next
  130. End Method
  131. Method UpdateChannel:Void()
  132. colChanIndex += 1
  133. If colChanIndex >= colLastChanIndex colChanIndex = colFirstChanIndex
  134. End Method
  135. Method PlayPocketCol:Void()
  136. Local t:Int = Millisecs()-channeltime[colChanIndex]
  137. If(t>200)
  138. channeltime[colChanIndex] = Millisecs()
  139. pocketCol.Play()
  140. UpdateChannel()
  141. Endif
  142. End Method
  143. Method PlayScratch:Void()
  144. scratchSnd.Play()
  145. End Method
  146. Method PlayBallCol:Void(n:Int)
  147. If(n>3) n = 3
  148. If(n<0) n = 0
  149. Local t:Int = Millisecs()-channeltime[colChanIndex]
  150. If(t>200)
  151. channeltime[colChanIndex] = Millisecs()
  152. colChannel[colChanIndex].Play(ballCol[n])
  153. UpdateChannel()
  154. Endif
  155. End Method
  156. Method PlayRailCol:Void(n:Int)
  157. Local t:Int = Millisecs()-channeltime[colChanIndex]
  158. If(t>200)
  159. channeltime[colChanIndex] = Millisecs()
  160. colChannel[colChanIndex].Play(railCol[n],0)
  161. UpdateChannel()
  162. Endif
  163. End Method
  164. Method updateScoreChan:Void()
  165. scoreChanIndex =(scoreChanIndex + 1) Mod scoreLastChan
  166. End Method
  167. Method PlayBeep:Void()
  168. Local t:Int = Millisecs()-channeltime[scoreChanIndex]
  169. channeltime[scoreChanIndex] = Millisecs()
  170. scoreChannel[scoreChanIndex].Play(beepSnd)
  171. updateScoreChan()
  172. End Method
  173. Method PlayBeepB:Void()
  174. Local t:Int = Millisecs()-channeltime[scoreChanIndex]
  175. channeltime[scoreChanIndex] = Millisecs()
  176. scoreChannel[scoreChanIndex].Play(beepBSnd)
  177. updateScoreChan()
  178. End Method
  179. Method PlayShootCol:Void()
  180. Local t:Int = Millisecs()-channeltime[colChanIndex]
  181. If(t>200)
  182. channeltime[colChanIndex] = Millisecs()
  183. colChannel[colChanIndex].Play(shootCol)
  184. UpdateChannel()
  185. End If
  186. End Method
  187. End Class