home *** CD-ROM | disk | FTP | other *** search
/ Game Programming for Teens / GameProgrammingForTeens.iso / Source / chapter11 / demo11-05.bb < prev    next >
Encoding:
Text File  |  2003-04-06  |  3.6 KB  |  147 lines

  1. ;demo11-05.bb - Demonstrates channels
  2.  
  3. Graphics 800,600
  4.  
  5. ;Set Up backbuffer and AutoMidHandle
  6. SetBuffer BackBuffer()
  7. AutoMidHandle True
  8.  
  9. ;CONSTANTS
  10. ;These are the key code constants
  11. Const UPKEY = 200, DOWNKEY = 208, AKEY = 30, ZKEY = 44, LEFTKEY = 203, RIGHTKEY = 205, PKEY = 25, RKEY = 19, SKEY = 31, ENTERKEY = 28
  12.  
  13. ;IMAGES
  14. ;The background stars image
  15. backgroundimage = LoadImage("stars.bmp")
  16.  
  17. ;Play the music file and save its channel
  18. backgroundmusic = PlayMusic("Interim Nation - Human Update.mp3")
  19.  
  20. ;Create starting variables for pitch, volume, and pan.
  21. pitch = 22000
  22. volume# = .500
  23. pan# = 0.00
  24.  
  25. ;Initialize the pitch, volume, and panning effect of the music
  26. ChannelPitch backgroundmusic, pitch
  27. ChannelVolume backgroundmusic, volume#
  28. ChannelPan backgroundmusic, pan#
  29.  
  30.  
  31. ;MAIN LOOP
  32. While Not KeyDown(1)
  33.  
  34. ;Tile the background image on the screen
  35. TileBlock backgroundimage, 0, scrolly
  36.  
  37. ;Scroll the background a tiny bit
  38. scrolly = scrolly + 1
  39.  
  40. ;If the scrolly variable is too large, reset the scrolly variable
  41. If scrolly > ImageHeight (backgroundimage)
  42.     scrolly = 0
  43. EndIf
  44.  
  45. ;Make sure text appears in top left corner of screen
  46. Locate 0,0
  47. Print "This program allows you to adjust the background music that is playing right now."
  48. Print "Press Up or Down to increase or decrease the pitch. Pitch = " + pitch
  49. Print "Press A or Z to increase or decrease the volume. Volume = " + volume#
  50. Print "Press the Left or Right Arrow to change the pan amount. Pan = " + pan#
  51. Print "Press 'P' to Pause the song, 'R' to resume the song, or 'S' to stop the song."
  52. Print "Press Enter to begin the song from the beginning if it stops playing."
  53.  
  54. ;If the up key is pressed, increase the pitch by 1000 hz
  55. If KeyDown(UPKEY)
  56.     pitch = pitch + 1000
  57.     
  58.     ;Do not let pitch grow too large
  59.     If pitch >= 44000  ;44000 is the max pitch
  60.         pitch = 44000
  61.     EndIf
  62.     
  63. EndIf
  64.  
  65. ;If down key is pressed, decrease pitch by 1000 hz
  66. If KeyDown(DOWNKEY)
  67.     pitch = pitch - 1000
  68.  
  69.     ;Do not let pitch grow too small
  70.     If pitch <= 0
  71.         pitch = 0
  72.     EndIf
  73.     
  74. EndIf
  75.  
  76. ;If 'A' is pressed, increase volume by .1
  77. If KeyDown(AKEY)
  78.     volume# = volume# + .1
  79.  
  80.     ;Do not let volume get too large
  81.     If volume# >= 1    ;1 is the max volume
  82.         volume# = 1
  83.     EndIf
  84. EndIf
  85.  
  86. ;If 'Z' is pressed, decrease volume by .1
  87. If KeyDown(ZKEY)
  88.     volume# = volume# - .1
  89.  
  90.     ;Do not let volume get too small
  91.     If volume# <= 0    ;1 is the max volume
  92.         volume# = 0
  93.     EndIf
  94. EndIf
  95.  
  96. ;If Left Arrow is pressed, change pan by -.1 (move it left by .1)
  97. If KeyDown(LEFTKEY)
  98.     pan# = pan# - .1
  99.     
  100.     ;Don't let pan go too far left
  101.     If pan# <= -1
  102.         pan# = -1    ;-1 is the lowest pan can be
  103.     EndIf
  104. EndIf
  105.  
  106. ;If Right Arrow is pressed, change pan by .1 (move pan right by .1)
  107. If KeyDown(RIGHTKEY)
  108.     pan# = pan# + .1
  109.     
  110.     ;Don't let pan go too far left
  111.     If pan# >= 1
  112.         pan# = 1    ;1 is the highest pan can be
  113.     EndIf
  114. EndIf
  115.  
  116. ;If 'P' is pressed, pause the channel
  117. If KeyDown(PKEY)
  118.     PauseChannel backgroundmusic
  119. EndIf
  120.  
  121. ;If 'R' is pressed, resume the channel
  122. If KeyDown(RKEY)
  123.     ResumeChannel backgroundmusic
  124. EndIf
  125.  
  126. ;If stop is pressed, stop the channel
  127. If KeyDown(SKEY)
  128.     StopChannel backgroundmusic
  129. EndIf
  130.  
  131. ;If Enter is pressed, test if the channel is playing. If it is, disregard enter, otherwise begin the song from the beginning
  132. If KeyDown(ENTERKEY)
  133.     
  134.     ;If channel is not playing, reset the song from the beginning
  135.     If Not ChannelPlaying(backgroundmusic)
  136.         backgroundmusic = PlayMusic("Interim Nation - Human Update.mp3")
  137.     EndIf
  138. EndIf
  139.  
  140. ;Synchronize the pitch, volume and pan with the music
  141. ChannelPitch backgroundmusic, pitch
  142. ChannelVolume backgroundmusic, volume#
  143. ChannelPan backgroundmusic, pan#
  144.  
  145. Delay 25
  146. Flip
  147. Wend