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

  1. ;demo08-02.bb - A moving animated image
  2.  
  3. Graphics 800,600
  4.  
  5. ;Set up BackBuffer() and AutoMidHandle
  6. SetBuffer BackBuffer()
  7. AutoMidHandle True
  8.  
  9. ;IMAGES
  10. ;Load the animated image of the boy
  11. playerimage = LoadAnimImage("animatedboy.bmp",95,71,0,8)
  12.  
  13. ;TYPES
  14. ;Load the player type
  15. Type player
  16.     Field x,y    ;The x and y coordinate position
  17.     Field frame  ;The frame that should be drawn
  18. End Type
  19.  
  20. ;Create the player
  21. player.player = New player 
  22.  
  23. ;Give the player its starting values
  24. player\x = 400
  25. player\y = 300
  26. player\frame = 0
  27.  
  28. ;MAIN LOOP
  29. While Not KeyDown(1)
  30.  
  31. ;Clear the screen
  32. Cls
  33.  
  34.  
  35. ;Position text at the top left corner of the screen
  36. Locate 0,0
  37. Print "X Coordinate: " + player\x
  38. Print "Y Coordinate: " + player\y
  39.  
  40.  
  41. ;If player presses left, move him left and decrement the frame number
  42. If KeyDown (203)
  43.     player\x = player\x - 5
  44.     player\frame = player\frame - 1
  45.  
  46. EndIf
  47.  
  48. ;If player presses right, move him right and increment the frame number
  49. If KeyDown(205)
  50.     player\x = player\x + 5
  51.     player\frame = player\frame + 1
  52. EndIf
  53.  
  54. ;If player presses up, move him up and increment the frame number
  55. If KeyDown (200) 
  56.     player\y = player\y -5
  57.     player\frame = player\frame + 1
  58. EndIf
  59.  
  60. ;If player presses down, move him down and decrement the frame number
  61. If KeyDown (208)
  62.     player\y = player\y + 5
  63.     player\frame = player\frame - 1
  64. EndIf
  65.  
  66. ;If the frame gets too high, reset it back to zero.
  67. If player\frame > 7
  68.     player\frame = 0
  69.     
  70. ;If the frame gets too low, reset it to 3
  71. ElseIf player\frame < 0
  72.     player\frame = 7
  73. EndIf
  74.  
  75. ;Draw the player at the correct position and the correct frame
  76. DrawImage playerimage, player\x,player\y, player\frame
  77.  
  78. ;Wait a while
  79. Delay 100
  80. Flip
  81. Wend
  82. ;END OF MAIN LOOP