October 28, 2020, 06:46:16 AM

### Author Topic: [bb] Distance between many entities by RGF [ 1+ years ago ]  (Read 1274 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] Distance between many entities by RGF [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : Distance between many entities
Author : RGF
Posted : 1+ years ago

Description : Calculate the distance between several entities, and choose the nearest one

Code :
Code: BlitzBasic
1. ;CODE BY WARNER, BOBYSAIT AND SAGITARIO
2.
3. Graphics3D 800,600,16,2
4.
5. cam=CreateCamera()
6. RotateEntity cam,90,0,0
7. PositionEntity cam,0,50,0
8.
9. Type enemy
10.         Field x,y,z,mesh
11.         Field distancias[99]
12.         Field lowest
13.         Field loindex
14. End Type
15.
16. Type bot
17.         Field x,y,z,mesh
18.         Field distancias[99]
19.         Field number
20. End Type
21.
22. e.enemy=New enemy
23. ex=5 : ey=0 : ez=5
24. emesh=CreateCube()
25. elowest=65536
26. eloindex=-1
27. EntityColor emesh,255,0,0
28.
29. e.enemy=New enemy
30. ex=10 : ey=0 : ez=0
31. emesh=CreateCube()
32. elowest=65536
33. eloindex=-1
34. EntityColor emesh,0,0,255
35.
36. b.bot=New bot
37. bx=-5 : by=0 : bz=-5
38. bmesh=CreateSphere()
39. b
40. umber=1
41. EntityColor bmesh,255,255,0
42.
43. b.bot=New bot
44. bx=5 : by=0 : bz=15
45. bmesh=CreateSphere()
46. b
47. umber=2
48. EntityColor bmesh,255,0,255
49.
50. b.bot=New bot
51. bx=15 : by=0 : bz=5
52. bmesh=CreateSphere()
53. b
54. umber=3
55. EntityColor bmesh,0,255,255
56.
57. For e.enemy=Each enemy
58.         PositionEntity emesh,ex,ey,ez
59. Next
60.
61. For b.bot=Each bot
62.         PositionEntity bmesh,bx,by,bz
63. Next
64.
65. Repeat
66. For b.bot=Each bot
67. If KeyDown(203)=True Then MoveEntity bmesh,-.2,0,0
68.
69. If KeyDown(205)=True Then MoveEntity bmesh,+.2,0,0
70.
71. If KeyDown(200)=True Then MoveEntity bmesh,0,0,+.2
72.
73. If KeyDown(208)=True Then MoveEntity bmesh,0,0,-.2
74. Next
75.
76. For e.enemy = Each enemy
77.         elowest=65536
78.         eloindex=-1
79.         i=0
80.         For b.bot = Each bot
81.                 i=i+1
82.                 If b
83. umber=i
84.                         edistancias[i]=EntityDistance(bmesh,emesh)
85.                         If edistancias[i]<elowest Then elowest = edistancias[i] : eloindex=i
86.                 EndIf
87.         Next
88. Next
89.
90. RenderWorld()
91.
92. Color 255,255,255
93. Text 0,550,"Use cursor keys to move spheres"
94.
95. e.enemy = First enemy
96. Color 255,0,0
97. Text 0,10,"Red enemy"
98. Color 255,255,255
99. Text 0,20,"distance to 1: "+edistancias[1]
100. Text 0,30,"distance to 2: "+edistancias[2]
101. Text 0,40,"distance to 3: "+edistancias[3]
102. If eloindex=1 Then Color 255,255,0
103. If eloindex=2 Then Color 255,0,255
104. If eloindex=3 Then Color 0,255,255
105. Text 0,50,"nearest: "+eloindex
106.
107. e = After e
108. Color 0,0,255
109. Text 200,10,"Blue enemy"
110. Color 255,255,255
111. Text 200,20,"distance to 1: "+edistancias[1]
112. Text 200,30,"distance to 2: "+edistancias[2]
113. Text 200,40,"distance to 3: "+edistancias[3]
114. If eloindex=1 Then Color 255,255,0
115. If eloindex=2 Then Color 255,0,255
116. If eloindex=3 Then Color 0,255,255
117. Text 200,50,"nearest: "+eloindex
118.
119. Flip
120. Until KeyDown(1)
121. End

RGF(Posted 1+ years ago)

Damm I know, I know, should be indented, but I don't know how to post indented code!

Ked(Posted 1+ years ago)

<div class="quote"> Damm I know, I know, should be indented, but I don't know how to post indented code! </div>Just copy and paste it from your IDE (with indents).

RGF(Posted 1+ years ago)

THNKYOU