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

  1. ;demo10-04.bb - Demonstrates movement with KeyHit()
  2.  
  3. Graphics 800,600
  4.  
  5. ;Set up page flipping
  6. SetBuffer BackBuffer()
  7.  
  8. ;Create the background image that will be scrolled
  9. backgroundimage = LoadImage ("stars.bmp")
  10. playerimage = LoadImage("ship.bmp")
  11.  
  12. ;Create variable that determines how much background has scrolled
  13. scrolly = 0
  14.  
  15. ;CONSTANTS
  16. ;The following constants are used for testing key presses
  17. Const ESCKEY = 1, UPKEY = 200, LEFTKEY = 203, RIGHTKEY = 205, DOWNKEY = 208
  18.  
  19. ;Create player's x any y coordinates - center him
  20. x = 400
  21. y = 300
  22.  
  23.  
  24. ;MAIN LOOP
  25. While Not KeyDown(ESCKEY)
  26.  
  27. ;Scroll background a bit by incrementing scrolly
  28. scrolly = scrolly + 1
  29.  
  30. ;Tile the background
  31. TileBlock backgroundimage,0,scrolly
  32.  
  33. ;Reset scrolly if the number grows too large
  34. If scrolly > ImageHeight(backgroundimage)
  35.     scrolly = 0
  36. EndIf
  37.  
  38.  
  39. ;If the player hits up, move player up
  40. If KeyHit(UPKEY)
  41.     y = y - 5   ;move player 5 pixels up
  42. EndIf
  43.  
  44. ;If the player hits left, move player left
  45. If KeyHit(LEFTKEY)
  46.     x = x - 5   ;move player 5 pixels left
  47. EndIf
  48.  
  49. ;If player hits right, move player right
  50. If KeyHit(RIGHTKEY) 
  51.     x = x + 5   ;move player 5 pixels right
  52. EndIf
  53.  
  54. ;If player hits down, move player down
  55. If KeyHit(DOWNKEY)
  56.     y = y + 5   ;move player 5 pixels down
  57. EndIf 
  58.  
  59. ;draw the player at his proper coordinates on the screen
  60. DrawImage playerimage, x,y
  61.  
  62. ;Wait a bit
  63. Delay 50
  64.  
  65. ;Flip the front and back buffers
  66. Flip
  67.  
  68. Wend ;END OF MAIN LOOP