Пример #1
0
 protected AttkVtx InterpVert(AttkVtx vI, AttkVtx vO, Ninja plr)
 {
     //returns an interpolated vertec between vI (vertex inside player hitbox),
     //vO(vertex outside player hitbox), where plr is the player
     AttkVtx retVtx = new AttkVtx();
     float itpWgt = 1.1f;
     if(vO.pos.x > plr.Right()){
         retVtx.pos.x=plr.Right();
         itpWgt = (plr.Right() - vI.pos.x)/(vO.pos.x-vI.pos.x);
         retVtx.pos.y = itpWgt*vI.pos.y + (1-itpWgt)*vO.pos.y;//solve rest
     }else if(vO.pos.x < plr.Left()){
         retVtx.pos.x=plr.Left();
         itpWgt = (plr.Left() - vI.pos.x)/(vO.pos.x-vI.pos.x);
         retVtx.pos.y = itpWgt*vI.pos.y + (1-itpWgt)*vO.pos.y;//solve rest
     }
     if(itpWgt>1){
         if(vO.pos.y > plr.Top()){
             retVtx.pos.y=plr.Top();
             itpWgt = (plr.Top() - vI.pos.y)/(vO.pos.y-vI.pos.y);
             retVtx.pos.x = itpWgt*vI.pos.x + (1-itpWgt)*vO.pos.x;//solve rest
         }
         else if(vO.pos.y > plr.Bottom()){
             retVtx.pos.y=plr.Bottom();
             itpWgt = (plr.Bottom() - vI.pos.y)/(vO.pos.y-vI.pos.y);
             retVtx.pos.x = itpWgt*vI.pos.x + (1-itpWgt)*vO.pos.x;//solve rest
         }
     }
     retVtx.mag = itpWgt*vI.mag + (1-itpWgt)*vO.mag;
     retVtx.dir = itpWgt*vI.dir + (1-itpWgt)*vO.dir;
     retVtx.dmg = itpWgt*vI.dmg + (1-itpWgt)*vO.dmg;
     retVtx.wgt = itpWgt*vI.wgt + (1-itpWgt)*vO.wgt;
     return retVtx;
 }