home *** CD-ROM | disk | FTP | other *** search
/ Game Programming for Teens / GameProgrammingForTeens.iso / Source / chapter10 / demo10-01.bb < prev    next >
Encoding:
Text File  |  2003-04-06  |  1.3 KB  |  47 lines

  1. ;demo10-01.bb - Demonstrates usage of KeyDown()
  2.  
  3. ;Initalize Graphics
  4. Graphics 800,600
  5.  
  6. ;Load the background image
  7. backgroundimage = LoadImage("stars.bmp")
  8.  
  9. ;CONSTANTS
  10. ;The following constants are used for testing key presses
  11. Const ESCKEY = 1, UPKEY = 200, LEFTKEY = 203, RIGHTKEY = 205, DOWNKEY = 208
  12.  
  13. ;scrollx and scrolly define how much the image should be moved
  14. scrollx = 0
  15. scrolly = 0
  16.  
  17.  
  18. ;MAIN LOOP
  19. While Not KeyDown(ESCKEY)
  20.  
  21. ;If the player hits up, we will scroll the background up
  22. If KeyDown(UPKEY)
  23.     scrolly = scrolly - 5 ;scroll background 5 pixels up
  24. EndIf ;End of UPKEY test
  25.  
  26. ;If the player hits left, we will scroll the background left
  27. If KeyDown(LEFTKEY)
  28.     scrollx = scrollx - 5 ;scroll background 5 pixels left
  29. EndIf ;End LEFTKEY test
  30.  
  31. ;If player hits right, we will scroll the background right
  32. If KeyDown(RIGHTKEY) 
  33.     scrollx = scrollx + 5 ;scroll background 5 pixels right
  34. EndIf ;End RIGHTKEY test
  35.  
  36. ;If player hits down, we will scroll the background down
  37. If KeyDown(DOWNKEY)
  38.     scrolly = scrolly + 5 ;Scroll background 5 pixels down
  39. EndIf ;End of DOWNKEY test
  40.  
  41. ;Tile the background image on the screen so it looks like actual outer space
  42. TileBlock backgroundimage,scrollx,scrolly
  43.  
  44. ;Wait a fraction of a second.
  45. Delay 35
  46.  
  47. Wend ;END OF MAIN LOOP