home *** CD-ROM | disk | FTP | other *** search
/ DarkBasic Professional / DarkBasicPro.iso / data1.cab / Lang_Files_(English) / Help / examples / basic3d / basic3d6-example.dba < prev    next >
Encoding:
Text File  |  2004-09-22  |  4.3 KB  |  151 lines

  1. rem Collision Functionality
  2.  
  3. sync on : sync rate 0 : hide mouse : color backdrop rgb(100,100,255)
  4. set text transparent : set text font "Arial" : set text size 20
  5.  
  6. rem load sounds
  7. load sound "impact.wav",1
  8. for s=2 to 10 : clone sound s,1 : next s
  9.  
  10. rem load images
  11. load image "marble.bmp",1
  12. load image "moss.bmp",2
  13. load image "fur.bmp",3
  14.  
  15. rem create floor
  16. make object box 1,400,10,400 : position object 1,0,-5,0
  17. texture object 1,2 : scale object texture 1,2,2
  18.  
  19. rem create walls
  20. make object box 2,400,100,10 : position object 2,0,50,-200
  21. make object box 3,400,100,10 : position object 3,0,50, 200
  22. make object box 4,10,100,400 : position object 4,-200,50,0
  23. make object box 5,10,100,400 : position object 5, 200,50,0
  24. for t=2 to 5
  25.  texture object t,2 : scale object texture t,4,1
  26. next t
  27.  
  28. rem Set floor and walls to box collision for rectangle roamer
  29. make object collision box 1,-200,-5,-200,200,5,200,0
  30. make object collision box 2,-200,-50,-5,200,50,5,0
  31. make object collision box 3,-200,-50,-5,200,50,5,0
  32. make object collision box 4,-5,-50,-200,5,50,200,0
  33. make object collision box 5,-5,-50,-200,5,50,200,0
  34.  
  35. rem create collision platform
  36. make object box 6,100,12,100
  37. position object 6,0,5,0
  38. texture object 6,1
  39.  
  40. rem create bouncey ball and set bounce-vars
  41. make object sphere 11,25
  42. set object collision to spheres 11
  43. set object radius 11,15
  44. texture object 11,1
  45. y#=75 : iy#=2
  46.  
  47. rem rectangle roamer for box collision
  48. make object box 41,40,20,40 : position object 41,95,31,50
  49. make object collision box 41,-20,-10,-20,20,10,20,0
  50. texture object 41,1
  51. set shadow shading on 41
  52.  
  53. rem load a model in center of world
  54. load object "alien.x",51
  55. set object collision to polygons 51
  56. scale object 51,1500,1500,1500
  57. position object 51,0,40,0
  58. xrotate object 51,180
  59. texture object 51,3
  60. scale object texture 51,5,5
  61. set object speed 51,100
  62. loop object 51
  63.  
  64. rem create a crate for automatic collision
  65. make object cube 61,15
  66. automatic object collision 61,8.0,0
  67. set object collision to spheres 61
  68. position object 61,-75,30,75
  69. texture object 61,1
  70. set shadow shading on 61
  71.  
  72. rem setup camera and lights
  73. set point light 0,0,0,0
  74. make light 1 : set point light 1,0,0,0 : color light 1,255,-100,-100
  75. position camera 0,30,-100
  76.  
  77. rem set automatic collision for camera
  78. automatic camera collision 0,30,0
  79. set global collision on
  80.  
  81. rem loop
  82. do
  83.  
  84. rem delete all collision data
  85. if spacekey()=1
  86.  gosub _delete_collision
  87. endif
  88.  
  89. rem move crate to test automatic object collision
  90. yrotate object 61,wrapvalue(object angle y(61)-0.2)
  91. move object down 61,0.5
  92. move object 61,0.5
  93.  
  94. rem control camera
  95. control camera using arrowkeys 0,1,2
  96.  
  97. rem control bouncey ball
  98. y#=y#+(iy#/20.0) : iy#=iy#-0.2
  99. position object 11,object position x(11),y#,object position z(11)
  100. if object collision(11,0)>0 then iy#=iy#*-1.0 : play sound 1+rnd(9)
  101.  
  102. rem display types of collision
  103. if object in screen(11)=1 then center text object screen x(11),object screen y(11)-25,"Polygon Collision"
  104. if object in screen(41)=1 then center text object screen x(41),object screen y(41)-25,"Sliding Box Collision"
  105. if object in screen(61)=1 then center text object screen x(61),object screen y(61)-25,"Automated Collision"
  106.  
  107. rem Add gravity to camera to test automatic collision
  108. position camera camera position x(),camera position y()-0.01,camera position z()
  109.  
  110. rem rectangle roamer
  111. move object 41,0.3
  112. ballhit=object collision(41,0)
  113. `if ballhit>=21 and ballhit<=30
  114. ` yrotate object ballhit,wrapvalue(object angle y(41))
  115. ` move object up ballhit,5.0
  116. ` move object ballhit,0.6
  117. `endif
  118. set cursor 0,0
  119. print ballhit
  120. if ballhit>0
  121.  spin#=rnd(45)
  122.  ax#=object position x(41)-get object collision x()
  123.  ay#=object position y(41)-get object collision y()
  124.  az#=object position z(41)-get object collision z()
  125.  position object 41,ax#,ay#,az#
  126. endif
  127. if spin#>0
  128.  spin#=spin#-1.0
  129.  yrotate object 41,wrapvalue(object angle y(41)+1)
  130. endif
  131.  
  132. rem move default light with ball
  133. position light 0,object position x(11),object position y(11),object position z(11)
  134.  
  135. rem move coloured light with roamer
  136. position light 1,object position x(41),object position y(41)+25,object position z(41)
  137.  
  138. rem update screen
  139. sync
  140.  
  141. rem end loop
  142. loop
  143.  
  144. _delete_collision:
  145.  for o=1 to 5
  146.   delete object collision box o
  147.  next o
  148.  set global collision off
  149. return
  150.  
  151.