home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD 60 / supercd60_2.iso / BlitzBasic / Blitz2DPCP / data1.cab / Support / help / samples / move_player.bb < prev    next >
Encoding:
Text File  |  2001-11-21  |  947 b   |  54 lines

  1. ;example of how to move a 'player' with the keyboard
  2. ; verified 1.48 4/18/2001
  3. ;use left and right arrow keys to move the player image
  4. ;
  5. ;hit ESC to exit
  6.  
  7. ;go into graphics mode
  8. Graphics 640,480
  9.  
  10. ;enable double buffering
  11. SetBuffer BackBuffer()
  12.  
  13. ;load a player image
  14. player=LoadImage("graphics\player.bmp")
  15.  
  16. ;initialize player position
  17. player_x=320
  18. player_y=440
  19.  
  20. ;loop until ESC hit...
  21. While Not KeyDown(1)
  22.  
  23.     ;is left key being held?
  24.     If KeyDown(203)
  25.     
  26.         ;move player to the left
  27.         player_x=player_x-4
  28.         
  29.         ;stop the player going 'off screen'
  30.         If player_x<0 Then player_x=0
  31.         
  32.     EndIf
  33.     
  34.     ;is right key being held?
  35.     If KeyDown(205)
  36.     
  37.         ;move player to the right
  38.         player_x=player_x+4
  39.         
  40.         ;stop the player going 'off screen'
  41.         If player_x>604 Then player_x=604
  42.     
  43.     EndIf
  44.     
  45.     ;clear the screen
  46.     Cls
  47.     
  48.     ;draw the player
  49.     DrawImage player,player_x,player_y
  50.     
  51.     ;swap front and back buffers
  52.     Flip
  53.     
  54. Wend