home *** CD-ROM | disk | FTP | other *** search
/ Game Programming for Teens / GameProgrammingForTeens.iso / Source / chapter07 / demo07-11.bb < prev    next >
Encoding:
Text File  |  2004-08-28  |  1.5 KB  |  71 lines

  1. ;demo07-11.bb - Demonstrates preloading and real-time rotation
  2.  
  3. Graphics 800,600
  4. ;Set up AutoMidHandle and BackBuffer()
  5. AutoMidHandle True
  6. SetBuffer BackBuffer()
  7.  
  8. ;IMAGES
  9. ;Load the spaceship image that will be rotated
  10. shipimage = LoadImage ("spaceship.bmp")
  11.  
  12. ;CONSTANTS
  13. ;How many rotations do you want total?
  14. Const rotations = 16
  15.  
  16. ;Create the rotation array
  17. Dim imagearray(rotations)
  18.  
  19. ;For all of the rotations you want, copy the spaceship image and rotate it the correct amount of degrees
  20. For frame = 0 To rotations - 1
  21.     imagearray(frame) = CopyImage (shipimage)
  22.     RotateImage imagearray(frame), frame*360/rotations
  23. Next 
  24.  
  25.  
  26. Print "Press Left to rotate counter-clockwise and right to rotate clockwise,"
  27. Print "Press Esc to exit."
  28.  
  29. ;Begin at frame 0 (facing upwards)
  30. frame = 0
  31.  
  32. ;MAIN LOOP
  33. While Not KeyDown(1)
  34.  
  35. ;Clear the screen
  36. Cls
  37.  
  38. ;Rotate the ship left if user presses left
  39. If KeyDown (203)
  40.     
  41. ;Decrement frame by 1 (thus rotating it left)
  42.     frame = frame - 1
  43.  
  44. ;If the frame count is less than 0, put it back at the max value of the array
  45.     If frame <= 0
  46.         frame = rotations - 1
  47.     EndIf
  48. ;Rotate the ship right if user presses right
  49. ElseIf KeyDown (205)
  50.  
  51. ;Increment frame by 1 (thus rotating it right)
  52.     frame = frame + 1
  53.  
  54. ;If frame gets too big, set it to the first frame (0)
  55.     If frame >= rotations
  56.         frame = 0
  57.     EndIf 
  58.  
  59. EndIf
  60.  
  61.  
  62.  
  63. ;Draw the current frame
  64. DrawImage imagearray(frame), 400,300
  65.  
  66.  
  67. Flip
  68.  
  69. ;Wait for a while
  70. Delay 50
  71. Wend