collide.bb 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. Repeat
  2. n_dudes=Input$( "Number of dudes (1-50):" )
  3. Until n_dudes>=1 And n_dudes<=100
  4. Global info1$="Collision demo"
  5. Global info2$="Arrow keys/A/Z To drive, Tab To repel"
  6. Include "../start.bb"
  7. Type Dude
  8. Field entity,speed#
  9. End Type
  10. Const T_DUDE=1,T_WALLS=2
  11. Collisions T_DUDE,T_DUDE,1,2 ;sphere-to-sphere, sliding collisions
  12. Collisions T_DUDE,T_WALLS,2,2 ;sphere-to-polygon, sliding collisions
  13. walls=CreateCube()
  14. EntityColor walls,0,32,192
  15. FitMesh walls,-40,0,-40,80,80,80
  16. FlipMesh walls
  17. EntityType walls,T_WALLS
  18. col=CreateCube()
  19. FitMesh col,-1,0,-1,2,40,2
  20. EntityColor col,255,0,0
  21. EntityAlpha col,.75
  22. EntityType col,T_WALLS
  23. For k=30 To 359+30 Step 60
  24. t=CopyEntity( col )
  25. RotateEntity t,0,k,0
  26. MoveEntity t,0,0,34
  27. Next
  28. FreeEntity col
  29. camera=CreateCamera()
  30. PositionEntity camera,0,50,-46
  31. TurnEntity camera,45,0,0
  32. light=CreateLight()
  33. TurnEntity light,45,45,0
  34. player=CreateCube()
  35. EntityColor player,0,255,0
  36. PositionEntity player,0,3,0
  37. EntityRadius player,2
  38. EntityType player,T_DUDE
  39. nose=CreateCube( player )
  40. EntityColor nose,0,255,0
  41. ScaleEntity nose,.5,.5,.5
  42. PositionEntity nose,0,0,1.5
  43. sphere=CreateSphere()
  44. EntityShininess sphere,.5
  45. EntityType sphere,T_DUDE
  46. an#=0
  47. an_step#=360.0/n_dudes
  48. For k=1 To n_dudes
  49. d.Dude=New Dude
  50. d\entity=CopyEntity( sphere )
  51. EntityColor d\entity,Rnd(255),Rnd(255),Rnd(255)
  52. TurnEntity d\entity,0,an,0
  53. MoveEntity d\entity,0,2,37
  54. ResetEntity d\entity
  55. d\speed=Rnd( .4,.49 )
  56. an=an+an_step
  57. Next
  58. FreeEntity sphere
  59. ok=True
  60. While Not KeyHit(1)
  61. If KeyDown(203) TurnEntity player,0,5,0
  62. If KeyDown(205) TurnEntity player,0,-5,0
  63. If KeyDown(200) MoveEntity player,0,0,.5
  64. If KeyDown(208) MoveEntity player,0,0,-.5
  65. If KeyDown(30) TranslateEntity player,0,.2,0
  66. If KeyDown(44) TranslateEntity player,0,-.2,0
  67. For d.Dude=Each Dude
  68. If EntityDistance( player,d\entity )>2
  69. PointEntity d\entity,player
  70. If KeyDown(15) TurnEntity d\entity,0,180,0
  71. EndIf
  72. MoveEntity d\entity,0,0,d\speed
  73. Next
  74. UpdateWorld
  75. RenderWorld
  76. Goto skip
  77. If ok
  78. ;
  79. ;sanity check!
  80. ;make sure nothings gone through anything else...
  81. ;
  82. For d=Each Dude
  83. If EntityY( d\entity )<.9
  84. ok=False
  85. bad$="Bad Dude Y: "+EntityY( d\entity )
  86. EndIf
  87. For d2.Dude=Each Dude
  88. If d=d2 Then Exit
  89. If EntityDistance( d\entity,d2\entity )<.9
  90. ok=False
  91. bad$="Dude overlap!"
  92. EndIf
  93. Next
  94. Next
  95. EndIf
  96. If ok
  97. Text 0,0,"Dudes OK"
  98. Else
  99. CameraClsColor camera,255,0,0
  100. Text 0,0,bad$
  101. EndIf
  102. .skip
  103. Flip
  104. Wend