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

  1. ;demo11-02.bb - Demonstrates SoundPitch
  2.  
  3. Graphics 800,600
  4.  
  5. ;Make sure backbuffer is drawn on and automidhandle is true
  6. SetBuffer BackBuffer()
  7. AutoMidHandle True
  8.  
  9. ;IMAGES
  10. ;load the player's ship image
  11. playerimage = LoadImage ("spaceship.bmp")
  12.  
  13.  
  14. ;SOUNDS
  15. ;Load the bullet sound
  16. explosionsound = LoadSound ("explode.wav")
  17.  
  18. ;CONSTANTS
  19. ;The following constants are used for key codes
  20. Const ESCKEY = 1,SPACEBAR = 57, UPKEY = 200, DOWNKEY = 208
  21.  
  22. ;create hertz variable
  23. hertz = 22000
  24.  
  25. ;Make sure bullet has hertz value of hertz variable to begin with
  26. SoundPitch explosionsound, hertz
  27.  
  28.  
  29.  
  30. ;MAIN LOOP
  31. While Not KeyDown(1)
  32. ;Clear the screen
  33. Cls
  34.  
  35. ;Make sure text is drawn in top left hand corner
  36. Locate 0,0
  37. Print "Current Hertz Value: " + hertz
  38.  
  39. ;Play explosion sound if player hits space bar
  40. If KeyHit(SPACEBAR)
  41.     PlaySound explosionsound
  42. EndIf
  43.  
  44. ;If up is hit, increment hertz variable
  45. If KeyHit (UPKEY)
  46.     hertz = hertz + 1000
  47. EndIf
  48.  
  49. ;If down is hit, decrement hertz variable
  50. If KeyHit(DOWNKEY)
  51.     hertz = hertz - 1000
  52. EndIf
  53.  
  54. ;Make the explosion have the same pitch as the hertz variable
  55. SoundPitch explosionsound, hertz
  56.  
  57. ;Draw the player
  58. DrawImage playerimage, MouseX(), MouseY()
  59.  
  60. Flip
  61. Wend
  62.  
  63.  
  64. ;END OF MAIN LOOP