コード例 #1
0
ファイル: GameModelAStar.cs プロジェクト: Brauny74/Lab
 public point[] findPath(Vector3 tC)
 {
     /*float dist = Vector3.Distance(this.getCoord(),target);
     int disp = System.Convert.ToInt32(dist) / levelSettings.lengthOt;
     if(disp == 0) disp++;
     point[] result = new point[disp];
     result[0] = new point(this.getCoord().x,this.getCoord().y);
     float tmpX = this.getCoord().x;
     float difX = tmpX - tC.x;
     float tmpY = this.getCoord().y;
     float difY = tmpY - tC.y;
     for(int i = 1; i<disp; i++){
         result[i] = new point(tmpX+(difX/disp),tmpY+(difY/disp));
     }
     result[disp-1] = new point(tC.x,tC.y);
     return result;*/
     cell conv = new cell();
     ArrayList t = levelSettings.aStar.algAStar(conv.toGrid(this.getCoord()),conv.toGrid(tC));
     point[] result = new point[t.Count];
     for(int i = 0; i<t.Count; i++){
         conv = (cell)t[i];
         result[i] = conv.toPoint(conv);
     }
     return result;
 }
コード例 #2
0
ファイル: FindPathClass.cs プロジェクト: Brauny74/Lab
 //ýòîò ìåòîä íàõîäèò âñå òî÷êè, ðàñïîëîæåííûå ðÿäîì ñ öåëåâîé òî÷êîé
 ArrayList allcellsNearX(ArrayList openset, ArrayList closedset, cell a)
 {
     ArrayList result = new ArrayList();
         cell b = new cell(0,0);
         /*foreach(cell b in allset)
         {
             if((b.x == a.x - 1)&&(b.y == a.y + 1)){result.Add(b);}
             if((b.x == a.x)&&(b.y == a.y + 1)){result.Add(b);}
             if((b.x == a.x + 1)&&(b.y == a.y + 1)){result.Add(b);}
             if((b.x == a.x - 1)&&(b.y == a.y)){result.Add(b);}
             if((b.x == a.x + 1)&&(b.y == a.y)){result.Add(b);}
             if((b.x == a.x - 1)&&(b.y == a.y - 1)){result.Add(b);}
             if((b.x == a.x)&&(b.y == a.y - 1)){result.Add(b);}
             if((b.x == a.x - 1)&&(b.y == a.y - 1)){result.Add(b);}
         }*/
         point p = a.toPoint(a);
         Vector3 vect = p.getCoord();
         int ob = levelSettings.objectSize;
         cell t;
         t = b.toGrid(vect.x+ob,vect.y);
         if(!(isInSet(t,openset)) && !(isInSet(t,closedset))){
             result.Add(t);
         }else{
             if(isInSet(t,openset)){result.Add(openset[indexOfCell(t,openset)]);}
         }
         t = b.toGrid(vect.x+ob,vect.y+ob);
         if(!(isInSet(t,openset)) && !(isInSet(t,closedset))){
             result.Add(t);
         }else{
             if(isInSet(t,openset)){result.Add(openset[indexOfCell(t,openset)]);}
         }
         t = b.toGrid(vect.x,vect.y+ob);
         if(!(isInSet(t,openset)) && !(isInSet(t,closedset))){
             result.Add(t);
         }else{
             if(isInSet(t,openset)){result.Add(openset[indexOfCell(t,openset)]);}
         }
         t = b.toGrid(vect.x-ob,vect.y);
         if(!(isInSet(t,openset)) && !(isInSet(t,closedset))){
             result.Add(t);
         }else{
             if(isInSet(t,openset)){result.Add(openset[indexOfCell(t,openset)]);}
         }
         t = b.toGrid(vect.x-ob,vect.y-ob);
         if(!(isInSet(t,openset)) && !(isInSet(t,closedset))){
             result.Add(t);
         }else{
             if(isInSet(t,openset)){result.Add(openset[indexOfCell(t,openset)]);}
         }
         t = b.toGrid(vect.x,vect.y-ob);
         if(!(isInSet(t,openset)) && !(isInSet(t,closedset))){
             result.Add(t);
         }else{
             if(isInSet(t,openset)){result.Add(openset[indexOfCell(t,openset)]);}
         }
         t = b.toGrid(vect.x+ob,vect.y-ob);
         if(!(isInSet(t,openset)) && !(isInSet(t,closedset))){
             result.Add(t);
         }else{
             if(isInSet(t,openset)){result.Add(openset[indexOfCell(t,openset)]);}
         }
         t = b.toGrid(vect.x-ob,vect.y+ob);
         if(!(isInSet(t,openset)) && !(isInSet(t,closedset))){
             result.Add(t);
         }else{
             if(isInSet(t,openset)){result.Add(openset[indexOfCell(t,openset)]);}
         }
         return result;
 }