[bb] Distance between many entities by RGF [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:42

Previous topic - Next topic

BlitzBot

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) Select
;CODE BY WARNER, BOBYSAIT AND SAGITARIO

Graphics3D 800,600,16,2

cam=CreateCamera()
RotateEntity cam,90,0,0
PositionEntity cam,0,50,0

Type enemy
Field x,y,z,mesh
Field distancias[99]
Field lowest
Field loindex
End Type

Type bot
Field x,y,z,mesh
Field distancias[99]
Field number
End Type

e.enemy=New enemy
ex=5 : ey=0 : ez=5
emesh=CreateCube()
elowest=65536
eloindex=-1
EntityColor emesh,255,0,0

e.enemy=New enemy
ex=10 : ey=0 : ez=0
emesh=CreateCube()
elowest=65536
eloindex=-1
EntityColor emesh,0,0,255

b.bot=New bot
bx=-5 : by=0 : bz=-5
bmesh=CreateSphere()
b
umber=1
EntityColor bmesh,255,255,0

b.bot=New bot
bx=5 : by=0 : bz=15
bmesh=CreateSphere()
b
umber=2
EntityColor bmesh,255,0,255

b.bot=New bot
bx=15 : by=0 : bz=5
bmesh=CreateSphere()
b
umber=3
EntityColor bmesh,0,255,255

For e.enemy=Each enemy
PositionEntity emesh,ex,ey,ez
Next

For b.bot=Each bot
PositionEntity bmesh,bx,by,bz
Next

Repeat
For b.bot=Each bot
If KeyDown(203)=True Then MoveEntity bmesh,-.2,0,0

If KeyDown(205)=True Then MoveEntity bmesh,+.2,0,0

If KeyDown(200)=True Then MoveEntity bmesh,0,0,+.2

If KeyDown(208)=True Then MoveEntity bmesh,0,0,-.2
Next

For e.enemy = Each enemy
elowest=65536
eloindex=-1
i=0
For b.bot = Each bot
i=i+1
If b
umber=i
edistancias[i]=EntityDistance(bmesh,emesh)
If edistancias[i]<elowest Then elowest = edistancias[i] : eloindex=i
EndIf
Next
Next

RenderWorld()

Color 255,255,255
Text 0,550,"Use cursor keys to move spheres"

e.enemy = First enemy
Color 255,0,0
Text 0,10,"Red enemy"
Color 255,255,255
Text 0,20,"distance to 1: "+edistancias[1]
Text 0,30,"distance to 2: "+edistancias[2]
Text 0,40,"distance to 3: "+edistancias[3]
If eloindex=1 Then Color 255,255,0
If eloindex=2 Then Color 255,0,255
If eloindex=3 Then Color 0,255,255
Text 0,50,"nearest: "+eloindex

e = After e
Color 0,0,255
Text 200,10,"Blue enemy"
Color 255,255,255
Text 200,20,"distance to 1: "+edistancias[1]
Text 200,30,"distance to 2: "+edistancias[2]
Text 200,40,"distance to 3: "+edistancias[3]
If eloindex=1 Then Color 255,255,0
If eloindex=2 Then Color 255,0,255
If eloindex=3 Then Color 0,255,255
Text 200,50,"nearest: "+eloindex

Flip
Until KeyDown(1)
End


Comments :


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