home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / devtools / files / lb202win.exe / LB202W.EXE / SPRITTIM.BAS < prev    next >
Encoding:
BASIC Source File  |  2000-10-24  |  2.1 KB  |  71 lines

  1.  
  2.     'get the sprite images and background
  3.     loadbmp "smiley1", "sprites\smiley1.bmp"
  4.     loadbmp "smiley2", "sprites\smiley2.bmp"
  5.     loadbmp "smiley3", "sprites\smiley3.bmp"
  6.     loadbmp "smiley4", "sprites\smiley4.bmp"
  7.     loadbmp "landscape", "sprites\bg1.bmp"
  8.  
  9.     'open a window and graphicbox
  10.     WindowHeight = 300
  11.     WindowWidth = 400
  12.     graphicbox #w.g, 0, 0, 400, 300
  13.     open "sprite test" for window_nf as #w
  14.     print #w, "trapclose [quit]"
  15.  
  16.     'add a background and 4 sprites and animation cycling
  17.     print #w.g, "background landscape"
  18.     for x = 1 to 4
  19.         spriteName$ = word$("smiley smiler smiled smiles", x)
  20.         print #w.g, "addsprite "; spriteName$; " smiley1 smiley2 smiley3 smiley4"
  21.         print #w.g, "cyclesprite "; spriteName$; " "; x; " once"
  22.     next x
  23.  
  24.     'set the sprite positions
  25.     print #w.g, "spritexy smiley 0 0"
  26.     print #w.g, "spritexy smiler 100 0"
  27.     print #w.g, "spritexy smiled 0 100"
  28.     print #w.g, "spritexy smiles 100 100"
  29.  
  30.     'set the sprite movement
  31.     print #w.g, "spritemovexy smiley 1 1"
  32.     print #w.g, "spritemovexy smiler -1 1"
  33.     print #w.g, "spritemovexy smiled 1 -1"
  34.     print #w.g, "spritemovexy smiles -1 -1"
  35.  
  36.     start = time$("ms")
  37.  
  38.     'set up a timer every 75 milliseconds
  39.     timer 75, [advanceAnimation]
  40.     wait
  41.  
  42. [advanceAnimation]   'This is where we go at each timer tick
  43.  
  44.     'draw another cycle of animation
  45.     cycles = cycles + 1
  46.     if cycles = 140 then
  47.     'set the sprite movement
  48.         print #w.g, "spritemovexy smiley -1 -1"
  49.         print #w.g, "spritemovexy smiler 1 -1"
  50.         print #w.g, "spritemovexy smiled -1 1"
  51.         print #w.g, "spritemovexy smiles 1 1"
  52.     end if
  53.     if cycles = 180 then timer 0 : goto [finish]
  54.     print #w.g, "backgroundxy "; cycles * 4; " 0"
  55.     print #w.g, "drawsprites ; spritecollides smiley list$"
  56.     if list$ > "" then print #w.g, "cyclesprite smiley 1 once"
  57.     wait
  58.  
  59.  
  60. [finish]
  61.  
  62.     elapsed = (time$("ms") - start) / 1000
  63.     print "Elapsed time: "; elapsed; " seconds"
  64.     print "Frames per seconds: "; cycles / elapsed
  65.     wait
  66.  
  67. [quit]
  68.  
  69.     close #w
  70.     end
  71.