home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 63 / CDACTUAL63.iso / Aplicaciones / DarkBasic / DemoDarkBasic.exe / help / examples / sprite / exam02.dba < prev    next >
Encoding:
Text File  |  2000-04-09  |  2.5 KB  |  103 lines

  1. Rem * Title  : Making a Sprite
  2. Rem * Author : DBS-MB
  3. Rem * Date   : 1st August 99
  4. rem ===================================================
  5. rem DARK BASIC EXAMPLE PROGRAM 2
  6. rem ===================================================
  7. rem This program will make a sprite
  8. rem ---------------------------------------------------
  9.  
  10. rem Set the ink to white and paper color to black 
  11. ink rgb(244,214,210),1
  12.  
  13. rem Load a bitmap on to the screen
  14. load bitmap "face.bmp"
  15.  
  16. rem Load back ground to bitmap 1
  17. load bitmap "back.bmp",1
  18.  
  19. rem When you load a bitmap that bitmap becomes the current bitmap
  20. rem where all drawing is done 
  21.  
  22. rem Use this command to set drawing to the screen
  23. set current bitmap 0 
  24.  
  25. rem Grab image 1 from bitmap
  26. get image 1,18,17,156,196
  27.  
  28. rem Now we will make a sprite
  29. sprite 1,100,100,1
  30.  
  31. rem Copy background to screen
  32. copy bitmap 1,0
  33.  
  34. rem The is were on screen sprite will apear
  35. acrossscreen=100
  36. downscreen=100
  37.  
  38. rem This is were sprite will move to
  39. targetacross=0
  40. targetdown=0
  41.  
  42. get image 2,0,0,150,150
  43.  
  44. rem Reset current bitmap to visible bitmap zero
  45. set current bitmap 0
  46.  
  47. do    
  48.  
  49.     rem Check for return key being pressed
  50.     if returnkey()=1
  51.  
  52.         rem Set the text printing to top of the screen
  53.         set cursor 0,0
  54.  
  55.         rem Print sprite info
  56.         print "making a sprite"
  57.         print "sprite x pos ",sprite x(1)
  58.         print "sprite y pos ",sprite y(1)
  59.         print "sprite offset x ",sprite offset x(1)
  60.         print "sprite offset y ",sprite offset y(1) 
  61.         print "sprite width is ",sprite width(1)
  62.         print "sprite height is ",sprite height(1)
  63.         print "sprite image number ",sprite image(1)
  64.  
  65.         rem Wait till you relese the return key
  66.         repeat :until returnkey()<>1
  67.  
  68.         rem Clear any text from the screen
  69.         paste image 2,0,0
  70.  
  71.     endif
  72.  
  73.     rem Have we pressed the left mouse button    
  74.     if mouseclick()=1
  75.         rem Get were mouse is across the screen
  76.         targetacross=mousex()
  77.         rem Get were mouse is down the screen    
  78.         targetdown=mousey()
  79.     endif
  80.  
  81.     rem This next part home the sprite on the target x and target y position
  82.     if acrossscreen<targetacross:acrossscreen=acrossscreen+1:endif
  83.     if acrossscreen>targetacross:acrossscreen=acrossscreen-1:endif
  84.     if downscreen<targetdown:downscreen=downscreen+1:endif
  85.     if downscreen>targetdown:downscreen=downscreen-1:endif
  86.     
  87.     rem Draw the sprite at the new position
  88.     sprite 1,acrossscreen,downscreen,1
  89.  
  90. loop
  91.  
  92. rem Clear the screen
  93. cls 
  94.  
  95. rem Remove the sprite from memory
  96. delete sprite 1
  97.  
  98. rem Remove image 1 from memory
  99. delete image 1
  100.  
  101. rem End the program
  102. end
  103.