dzień dobry, czy poniższy kod jest optymalny? Da się to zrobić lepiej, szybciej? :)
Pragnę mieć w tablicy id trzech najblizszych instancji w promieniu global.zasi[4,lvl] od punktu x+16,y+16, oto mój kod:
GML
for(i=0;i<=2;i+=1){
obj[i,0]=-1//id obiektu
obj[i,1]=-1//dystans
}
with(o_wrog){
var odl;
odl=point_distance(other.x+16,other.y+16,x,y)
if odl<global.zasi[4,other.lvl]{//zasieg
if odl<other.obj[2,1] or other.obj[2,1]=-1{
if odl<other.obj[0,1] or other.obj[0,1]=-1{
var pomocnik;
pomocnik[0]=other.obj[1,0]
pomocnik[1]=other.obj[1,1]
other.obj[1,0]=other.obj[0,0]
other.obj[1,1]=other.obj[0,1]
other.obj[0,1]=odl
other.obj[0,0]=id
other.obj[2,0]=pomocnik[0]
other.obj[2,1]=pomocnik[1]
}else{
if odl<other.obj[1,1] or other.obj[1,1]=-1{
other.obj[2,0]=other.obj[1,0]
other.obj[2,1]=other.obj[1,1]
other.obj[1,1]=odl
other.obj[1,0]=id
}else{
if odl<other.obj[2,1] or other.obj[2,1]=-1{
other.obj[2,1]=odl
other.obj[2,0]=id
}
}
}
}
}
}