예제 #1
0
    // this one is still problematic
    private Grid_Portal GetPortalWithLargestDistance(MapGenerator m)
    {
        float       largestDistance = 0f;
        Grid_Portal result          = null;

        foreach (Grid_Portal p in m.GetPortals())
        {
            if (p == this)
            {
                continue;
            }
            if (p.GetPairPortal() != null)
            {
                continue;
            }

            float dist = Mathf.Abs((GetPos().x - p.GetPos().x) + (GetPos().z - p.GetPos().z));
            if (largestDistance < dist)
            {
                result = p;
            }
        }

        if (result != null)
        {
            return(result);
        }
        else
        {
            Debug.Log("Problem with portals");
            return(null);
        }
    }
예제 #2
0
    public override void Initialize()
    {
        // we need to link this portal to another one
        // apply one of the algorithms to pair itself with another one
        MapGenerator m = MapGenerator.mapGenerator;

        if (m.GetPortals().IndexOf(this) % 2 == 0)
        {
            //pairPortal = GetPortalWithNextOneInList(m);
            pairPortal = GetPortalWithNextOneInList(m);

            if (pairPortal != null)
            {
                pairPortal.SetPortal(this);
            }
        }
    }
예제 #3
0
    private Grid_Portal GetPortalWithNextOneInList(MapGenerator m)
    {
        int         currentIndex = m.GetPortals().IndexOf(this);
        Grid_Portal p            = null;

        if (m.GetPortals().Count > currentIndex + 1)
        {
            p = m.GetPortals()[currentIndex + 1];
        }
        if (p != null)
        {
            return(p);
        }
        else
        {
            Debug.Log("Your portals need to be of plural amount");
            return(null);
        }
    }
예제 #4
0
 public void SetPortal(Grid_Portal p)
 {
     pairPortal = p;
 }