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

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

#### 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 SAGITARIOGraphics3D 800,600,16,2cam=CreateCamera()RotateEntity cam,90,0,0PositionEntity cam,0,50,0Type enemy Field x,y,z,mesh Field distancias[99] Field lowest Field loindexEnd TypeType bot Field x,y,z,mesh Field distancias[99] Field numberEnd Typee.enemy=New enemyex=5 : ey=0 : ez=5emesh=CreateCube()elowest=65536eloindex=-1EntityColor emesh,255,0,0e.enemy=New enemyex=10 : ey=0 : ez=0emesh=CreateCube()elowest=65536eloindex=-1EntityColor emesh,0,0,255b.bot=New botbx=-5 : by=0 : bz=-5bmesh=CreateSphere()bumber=1EntityColor bmesh,255,255,0b.bot=New botbx=5 : by=0 : bz=15bmesh=CreateSphere()bumber=2EntityColor bmesh,255,0,255b.bot=New botbx=15 : by=0 : bz=5bmesh=CreateSphere()bumber=3EntityColor bmesh,0,255,255For e.enemy=Each enemy PositionEntity emesh,ex,ey,ezNextFor b.bot=Each bot PositionEntity bmesh,bx,by,bzNextRepeatFor 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,-.2NextFor e.enemy = Each enemy elowest=65536 eloindex=-1 i=0 For b.bot = Each bot i=i+1 If bumber=i edistancias[i]=EntityDistance(bmesh,emesh) If edistancias[i]<elowest Then elowest = edistancias[i] : eloindex=i EndIf NextNextRenderWorld()Color 255,255,255Text 0,550,"Use cursor keys to move spheres"e.enemy = First enemyColor 255,0,0Text 0,10,"Red enemy"Color 255,255,255Text 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,0If eloindex=2 Then Color 255,0,255If eloindex=3 Then Color 0,255,255Text 0,50,"nearest: "+eloindexe = After eColor 0,0,255Text 200,10,"Blue enemy"Color 255,255,255Text 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,0If eloindex=2 Then Color 255,0,255If eloindex=3 Then Color 0,255,255Text 200,50,"nearest: "+eloindexFlipUntil KeyDown(1)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