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

  1. Rem * Title  : Using Sprites
  2. Rem * Author : DBS-MB
  3. Rem * Date   : 1st August 99
  4. rem ===================================================
  5. rem DARK BASIC EXAMPLE PROGRAM 4
  6. rem ===================================================
  7. rem This program will draw a sprite on screen 
  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 Get sprite width and find the middle of it going across
  32. spritewidth=(sprite width(1)/2)
  33.  
  34. rem Get sprite height and find the middle of it going down
  35. spriteheight=(sprite height(1)/2)
  36.  
  37. rem Get other sprite data
  38. spriteexists=sprite exist(1)
  39. spritevert=sprite flipped(1)
  40. spritehori=sprite mirrored(1)
  41.  
  42. rem New offset for sprite 1 
  43. offset sprite 1,spritewidth,spriteheight
  44.  
  45. rem Copy background to screen
  46. copy bitmap 1,0
  47.  
  48. rem The is were on screen sprite will appear
  49. acrossscreen=100
  50. downscreen=100
  51.  
  52. rem This is were sprite will move to
  53. targetacross=100
  54. targetdown=100
  55.  
  56. rem When you make a sprite the sprite is set so that it save the background
  57. rem and restore it when it has moved
  58. rem you can switch of this by using the command SET SPRITE
  59.  
  60. rem The sprite will not save the background
  61. rem please remove the REM command before running
  62. REM set sprite 1,0,1 
  63.  
  64. rem please replace the REM command before using the next set sprite command
  65.  
  66. rem The background color grab with the image will not be transparent
  67. rem please remove the ` before running
  68. `set sprite 1,1,0 
  69.  
  70. print "setting save background and transparent on a sprite"
  71. do
  72.     rem Have we pressed the left mouse button    
  73.     if mouseclick()=1
  74.         rem get were mouse is across the screen
  75.         targetacross=mousex()
  76.         rem get were mouse is down the screen    
  77.         targetdown=mousey()
  78.     endif
  79.  
  80.     rem This next part home the sprite on the target x and target y position
  81.     if acrossscreen<targetacross:acrossscreen=acrossscreen+1:endif
  82.     if acrossscreen>targetacross:acrossscreen=acrossscreen-1:endif
  83.     if downscreen<targetdown:downscreen=downscreen+1:endif
  84.     if downscreen>targetdown:downscreen=downscreen-1:endif
  85.     
  86.     rem Draw the sprite at the new position
  87.     sprite 1,acrossscreen,downscreen,1
  88.  
  89. loop
  90.  
  91. rem Clear the screen
  92. cls 
  93.  
  94. rem Remove the sprite from memory
  95. delete sprite 1
  96.  
  97. rem Remove image 1 from memory
  98. delete image 1
  99.  
  100. rem End the program
  101. end
  102.  
  103.