home *** CD-ROM | disk | FTP | other *** search
/ Game Programming for Teens / GameProgrammingForTeens.iso / Source / chapter12 / demo12-01.bb next >
Encoding:
Text File  |  2003-04-06  |  926 b   |  52 lines

  1. ;demo12-01.bb - Demonstrates random variables
  2. Graphics 800,600
  3.  
  4. ;Set up automidhandle and backbuffer
  5. AutoMidHandle True
  6. SetBuffer BackBuffer()
  7.  
  8. ;Make sure we seed the random genereator
  9. SeedRnd MilliSecs()
  10.  
  11. ;Now we load the image that we will use.
  12. flyimage = LoadAnimImage ("fly.bmp",64,64,0,4)
  13. ;create a starting frame value
  14. frame = 0
  15.  
  16. ;create the x and y values for the fly
  17. flyx = 400
  18. flyy = 300
  19.  
  20. ;MAIN LOOP
  21. While Not KeyDown (1)
  22.  
  23. ;Clear the screen
  24. Cls
  25.  
  26. Text 0,0,"Fly X: " + flyx
  27. Text 0,20,"Fly Y: " + flyy
  28.  
  29. ;move the fly a random amount
  30. flyx = flyx + Rand(-15,15)
  31. flyy = flyy + Rand(-15,15)
  32.  
  33. ;Draw the fly on screen
  34. DrawImage flyimage,flyx,flyy,frame
  35.  
  36. ;increment the frame
  37. frame = frame + 1
  38.  
  39. ;If frame gets too large or small, reset it
  40. If frame > 3
  41.     frame = 0
  42. ElseIf frame < 0
  43.     frame = 3 
  44. EndIf
  45.  
  46. ;Flip the buffers
  47. Flip
  48.  
  49. ;Wait a little bit
  50. Delay 25
  51.  
  52. Wend   ;END OF MAIN LOOP