home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 63 / CDACTUAL63.iso / Aplicaciones / DarkBasic / DemoDarkBasic.exe / help / examples / basic3d / exam06.dba < prev    next >
Encoding:
Text File  |  1999-12-08  |  1.9 KB  |  83 lines

  1. Rem * Title  : Model Collision
  2. Rem * Author : DBS-LB
  3. Rem * Date   : 1st Sept 99
  4. rem ==========================================
  5. rem DARK BASIC EXAMPLE PROGRAM 6
  6. rem ==========================================
  7. rem This program handles object collision
  8. rem ------------------------------------------
  9.  
  10. rem Make a wall to collide against
  11. make object plain 2,100.0,100.0
  12. position object 2,0,50,100
  13.  
  14. rem Load your object
  15. load object "walk.x",1
  16.  
  17. rem Fix the proper angle for the character
  18. yrotate object 1,180
  19. fix object pivot 1
  20.  
  21. rem Switch on collision for the object
  22. set object collision on 1
  23.  
  24. rem Activate manual sync
  25. draw to back
  26. sync on
  27.  
  28. rem Begin main loop
  29. while mouseclick()=0
  30.  
  31. rem Clear screen for ink flash
  32. cls
  33. print screen fps()
  34.  
  35. rem Store old position
  36. oldx#=x#
  37. oldz#=z#
  38.  
  39. rem Control variables with the cursor keys
  40. if upkey()=1 then x#=newxvalue(x#, angle#, 4.0) : z#=newzvalue(z#, angle#, 4.0)
  41. if downkey()=1 then x#=newxvalue(x#, angle#, -4.0) : z#=newzvalue(z#, angle#, -4.0)
  42. if leftkey()=1 then angle#=wrapvalue(angle#-10)
  43. if rightkey()=1 then angle#=wrapvalue(angle#+10)
  44.  
  45. rem Switch between sphere and box area for collision check
  46. if inkey$()="s"
  47.     set object collision to spheres 1
  48. endif
  49. if inkey$()="b"
  50.     set object collision to boxes 1
  51. endif
  52. if inkey$()="p"
  53.     set object collision to polygons 1
  54. endif
  55. if inkey$()="o" then set global collision on 
  56. if inkey$()="f" then set global collision off
  57.  
  58. rem Update object position and rotation
  59. position object 1,x#,0,z#
  60. rotate object 1,0,angle#,0
  61.  
  62. rem On initial contact, flash screen color
  63. if object hit(1,0)>0
  64.     ink 0,rgb(255,255,255)
  65. else
  66.     ink rgb(255,255,255),0
  67. endif
  68.  
  69. rem If collision, restore old position
  70. if object collision(1,0)>0
  71.     x#=oldx#
  72.     z#=oldz#
  73. endif
  74.  
  75. rem Update Screen
  76. sync
  77.  
  78. rem End main loop
  79. endwhile
  80.  
  81. rem Switch off collision for the object
  82. set object collision off 1
  83.