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

  1. Rem * Title  : Sprite Collision
  2. Rem * Author : DBS-LB
  3. Rem * Date   : 1st Sept 99
  4. rem ===================================================
  5. rem DARK BASIC EXAMPLE PROGRAM 9
  6. rem ===================================================
  7. rem This program will detect sprite collision
  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 Grab image 1 from bitmap
  17. get image 1,32,52,152,170
  18.  
  19. rem Now we will make two sprites
  20. sprite 1,100,100,1 : mirror sprite 1
  21. sprite 2,300,200,1 : flip sprite 2 : scale sprite 2,200
  22.  
  23. rem Activate manual sync
  24. sync on
  25.  
  26. rem Press left mouse button to quit
  27. repeat
  28.  
  29.     rem Clear screen
  30.     cls
  31.  
  32.     rem Record old position
  33.     oldx=x
  34.     oldy=y
  35.  
  36.     rem Control position with cursors
  37.     if upkey()=1 then y=y-3
  38.     if downkey()=1 then y=y+3
  39.     if leftkey()=1 then x=x-3
  40.     if rightkey()=1 then x=x+3
  41.  
  42.     rem draw the sprite at the new position
  43.     sprite 1,x,y,1
  44.  
  45.     rem Check for initial impact
  46.     if sprite hit(1,0)>0 then ink 0,rgb(255,255,255) else ink rgb(255,255,255),0
  47.  
  48.     rem Check for collision and block new position
  49.     if sprite collision(1,0)>0
  50.         x=oldx
  51.         y=oldy
  52.         sprite 1,x,y,1
  53.     endif
  54.  
  55.     rem Update screen
  56.     sync
  57.  
  58. until mouseclick()=1
  59.  
  60. rem Clear the screen
  61. cls 
  62.  
  63. rem Remove sprites from memory
  64. delete sprite 1
  65. delete sprite 2
  66.  
  67. rem Remove image 1 from memory
  68. delete image 1
  69.  
  70. rem End the program
  71. end
  72.