I submit for your approval a MOSTLY complete system for finding the nearest 5 bricks from a field of 100.
Hold T to turn off the pasted bricks and hold y to turn them on (default). I say mostly because it still pastes sprites over the closest ones, but it also puts sprites there.
The "ball's" position is the mouse coordinates, for seeing the effect. As you can see, the performance impact of the HUGE number of loops is small, as I am still getting upwards of 200 fps CAPPED when the bricks are turned off and about 100 when on.
With this system, it would be easy to use SPRITE COLLISION to check the 5 sprite bricks with the (currently non existant) sprite ball to see which are hit, without taking the performance hit of 100 sprites.
Circle 320,240,5
get image 65535,315,235,325,245
cls
Box 320,240,350,255
GET IMAGE 1,320,240,350,255
cls
box 320,240,370,245
GET IMAGE 65534,320,240,350,245
cls
XVel#=1
YVel#=-1
DIM BrickX(100)
DIM BrickY(100)
DIM BrickC(100,2)
DIM Close5(6,2)
DIM Distances(100,2)
MaxD#=SQRT((640*640)+(480*480))
FOR I=1 to 6
Close5(I,2)=MaxD#
NEXT I
For y=1 to 5
FOR X=1 to 20
Brick=X+(Y-1)*20
BrickX(Brick)=10+(X-1)*31
BrickY(Brick)=100+(Y-1)*16
BrickC(Brick,1)=BrickX(Brick)+15
BrickC(Brick,2)=BrickY(Brick)+7
NEXT X
NEXT Y
sync on : sync rate 0
DO
oldx=ballx
oldy=bally
BallX=MouseX() : BallY=MouseY()
if oldx<>BallX or oldy<>bally
FOR I=1 to 100
Distances(i,1)=Dist(BallX,BallY,BrickC(i,1),BrickC(i,2))
Distances(i,2)=i
NEXT I
numbersort()
ENDIF
FOR I=1 to 5
sprite i,BrickX(Close5(I,1)),BrickY(Close5(I,1)),1
NEXT I
IF toggle=0
For i=1 to 100
paste image 1,brickx(i),bricky(i)
NEXT I
ENDIF
IF inkey$()="t" then toggle=1
IF inkey$()="y" then toggle=0
print screen fps()
sync
CLS
LOOP
END
FUNCTION Dist(X1,Y1,X2,Y2)
D=((X2-X1)*(X2-X1))+((Y2-Y1)*(Y2-Y1))
ENDFUNCTION D
FUNCTION List5()
For i=1 to 5
Print str$(Close5(i,1))+":"+str$(close5(i,2))
NEXT I
sync
ENDFUNCTION
FUNCTION NumberSort()
chain=1
chainx=1
REPEAT
IF distances(chain,1)>distances(chain+1,1)
distances(0,1)=distances(chain,1)
distances(0,2)=distances(chain,2)
distances(chain,1)=distances(chain+1,1)
distances(chain,2)=distances(chain+1,2)
distances(chain+1,1)=distances(0,1)
distances(chain+1,2)=distances(0,2)
ENDIF
INC Chain
inc chainx
if chain=100
chain=1
endif
UNTIL chainx=10000
return$=""
FOR i=1 to 5
close5(i,1)=distances(i,2)
NEXT I
ENDFUNCTION
Feel free to use any of the functions if they are useful.
Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose