예제 #1
0
파일: SpawnPoint.cs 프로젝트: phelow/OhDeer
    public bool ZoneCheck(RoadPiece rp)
    {
        Collider2D [] cols = Physics2D.OverlapCircleAll(new Vector2(rp.transform.position.x, rp.transform.position.y + 10.2f), RADAR_CHECK_SIZE);
        rp.AddGizmo(new Vector3(rp.transform.position.x, rp.transform.position.y + 10.2f, 0));

        RoadPiece TopRp = null;

        foreach (Collider2D cd in cols)
        {
            RoadPiece trp = cd.GetComponent <RoadPiece> ();
            if (trp == null && cd.transform.parent != null)
            {
                trp = cd.transform.parent.GetComponentInChildren <RoadPiece> ();
            }
            if (trp == null && cd.transform.parent != null)
            {
                trp = cd.transform.parent.GetComponent <RoadPiece> ();
            }

            if (trp != null)
            {
                TopRp = trp;
            }
        }

        if (TopRp != null)
        {
            if (TopRp.GetSpawnPoint(WaypointOrientation.Bottom) != null && rp.GetSpawnPoint(WaypointOrientation.Top) == null)
            {
                return(false);
            }
            else if (TopRp.GetSpawnPoint(WaypointOrientation.Bottom) == null && rp.GetSpawnPoint(WaypointOrientation.Top) != null)
            {
                return(false);
            }
        }

        cols = Physics2D.OverlapCircleAll(new Vector2(rp.transform.position.x - 10.2f, rp.transform.position.y), RADAR_CHECK_SIZE);
        rp.AddGizmo(new Vector3(rp.transform.position.x - 10.2f, rp.transform.position.y, 0));
        RoadPiece LeftRp = null;

        foreach (Collider2D cd in cols)
        {
            RoadPiece trp = cd.GetComponent <RoadPiece> ();
            if (trp == null && cd.transform.parent != null)
            {
                trp = cd.transform.parent.GetComponentInChildren <RoadPiece> ();
            }
            if (trp == null && cd.transform.parent != null)
            {
                trp = cd.transform.parent.GetComponent <RoadPiece> ();
            }
            if (trp != null)
            {
                LeftRp = trp;
            }
        }

        if (LeftRp != null)
        {
            if (LeftRp.GetSpawnPoint(WaypointOrientation.Right) != null && rp.GetSpawnPoint(WaypointOrientation.Left) == null)
            {
                return(false);
            }
            else if (LeftRp.GetSpawnPoint(WaypointOrientation.Right) == null && rp.GetSpawnPoint(WaypointOrientation.Left) != null)
            {
                return(false);
            }
        }
        cols = Physics2D.OverlapCircleAll(new Vector2(rp.transform.position.x + 10.2f, rp.transform.position.y), RADAR_CHECK_SIZE);
        rp.AddGizmo(new Vector3(rp.transform.position.x + 10.2f, rp.transform.position.y, 0));
        RoadPiece RightRp = null;

        foreach (Collider2D cd in cols)
        {
            RoadPiece trp = cd.GetComponent <RoadPiece> ();
            if (trp == null && cd.transform.parent != null)
            {
                trp = cd.transform.parent.GetComponentInChildren <RoadPiece> ();
            }
            if (trp == null && cd.transform.parent != null)
            {
                trp = cd.transform.parent.GetComponent <RoadPiece> ();
            }
            if (trp != null)
            {
                RightRp = trp;
            }
        }

        if (RightRp != null)
        {
            if (RightRp.GetSpawnPoint(WaypointOrientation.Left) != null && rp.GetSpawnPoint(WaypointOrientation.Right) == null)
            {
                return(false);
            }
            else if (RightRp.GetSpawnPoint(WaypointOrientation.Left) == null && rp.GetSpawnPoint(WaypointOrientation.Right) != null)
            {
                return(false);
            }
        }
        cols = Physics2D.OverlapCircleAll(new Vector2(rp.transform.position.x, rp.transform.position.y - 10.2f), RADAR_CHECK_SIZE);
        rp.AddGizmo(new Vector3(rp.transform.position.x, rp.transform.position.y - 10.2f, 0));
        RoadPiece BottomRp = null;

        foreach (Collider2D cd in cols)
        {
            RoadPiece trp = cd.GetComponent <RoadPiece> ();
            if (trp == null && cd.transform.parent != null)
            {
                trp = cd.transform.parent.GetComponentInChildren <RoadPiece> ();
            }
            if (trp == null && cd.transform.parent != null)
            {
                trp = cd.transform.parent.GetComponent <RoadPiece> ();
            }
            if (trp != null)
            {
                BottomRp = trp;
            }
        }

        if (BottomRp != null)
        {
            if (BottomRp.GetSpawnPoint(WaypointOrientation.Top) != null && rp.GetSpawnPoint(WaypointOrientation.Bottom) == null)
            {
                return(false);
            }
            else if (BottomRp.GetSpawnPoint(WaypointOrientation.Top) == null && rp.GetSpawnPoint(WaypointOrientation.Bottom) != null)
            {
                return(false);
            }
        }


        return(true);
    }
예제 #2
0
파일: SpawnPoint.cs 프로젝트: phelow/OhDeer
    public bool SetConnections()
    {
        Collider2D [] cols = Physics2D.OverlapCircleAll(new Vector2(transform.position.x, transform.position.y), 1.0f);
        RoadPiece     rp   = null;

        foreach (Collider2D cd in cols)
        {
            RoadPiece trp = cd.GetComponent <RoadPiece> ();
            if (trp != null)
            {
                rp = trp;
            }
        }

        if (rp == null)
        {
            return(true);
        }

        WaypointOrientation oppositeOrientation = WaypointOrientation.Bottom;

        switch (m_orientation)
        {
        case WaypointOrientation.Bottom:
            oppositeOrientation = WaypointOrientation.Top;
            break;

        case WaypointOrientation.Left:
            oppositeOrientation = WaypointOrientation.Right;
            break;

        case WaypointOrientation.Right:
            oppositeOrientation = WaypointOrientation.Left;
            break;

        case WaypointOrientation.Top:
            oppositeOrientation = WaypointOrientation.Bottom;
            break;
        }

        //TODO: fix this to accomodate placing pieces with multiple connections

        SpawnPoint sp = rp.GetSpawnPoint(oppositeOrientation);

        if (sp == null)
        {
            return(false);
        }
        if (sp.IsLinked())
        {
            return(true);
        }
        Waypoint[] targetInput;
        targetInput = sp.getInput();
        Waypoint[] targetOutput;
        targetOutput = sp.getOutput();


        foreach (Waypoint wp in m_output)
        {
            wp.SetNext(targetInput);
        }

        foreach (Waypoint wp in targetOutput)
        {
            wp.SetNext(m_input);
        }
        Link(sp);
        sp.Link(this);

        return(true);
    }
예제 #3
0
파일: SpawnPoint.cs 프로젝트: phelow/OhDeer
    public RoadPiece PlacePiece(RoadPiece previous)
    {
        if (m_OriginalViableRoadPieces == null)
        {
            m_OriginalViableRoadPieces = m_viableRoadPieces;
        }

        m_viableRoadPieces = m_OriginalViableRoadPieces;
        List <GameObject> instantiables = AvailablePieceThatFits();

        if (instantiables != null)
        {
            bool pieceNotPlaced = true;
            while (pieceNotPlaced && instantiables.Count > 0)
            {
                //TODO, prevent double selection
                int        choice = Random.Range(0, instantiables.Count);
                GameObject go     = GameObject.Instantiate(instantiables[choice]);
                instantiables.RemoveAt(choice);

                go.transform.position = transform.position;

                WaypointOrientation oppositeOrientation = WaypointOrientation.Bottom;
                switch (m_orientation)
                {
                case WaypointOrientation.Bottom:
                    oppositeOrientation = WaypointOrientation.Top;
                    break;

                case WaypointOrientation.Left:
                    oppositeOrientation = WaypointOrientation.Right;
                    break;

                case WaypointOrientation.Right:
                    oppositeOrientation = WaypointOrientation.Left;
                    break;

                case WaypointOrientation.Top:
                    oppositeOrientation = WaypointOrientation.Bottom;
                    break;
                }

                //TODO: fix this to accomodate placing pieces with multiple connections

                RoadPiece  rp = go.GetComponent <RoadPiece> ();
                SpawnPoint sp = rp.GetSpawnPoint(oppositeOrientation);
                //TODO: link up all of the road pieces

                Waypoint[] targetInput;
                targetInput = sp.getInput();
                Waypoint[] targetOutput;
                targetOutput = sp.getOutput();
                Link(sp);
                sp.Link(this);


                foreach (Waypoint wp in m_output)
                {
                    wp.SetNext(targetInput);
                }

                foreach (Waypoint wp in targetOutput)
                {
                    wp.SetNext(m_input);
                }
                go.GetComponent <RoadPiece> ().Instantiate(previous);

                bool works = true;

                foreach (SpawnPoint targetSpawnPoints in rp.SpawnPoints())
                {
                    if (targetSpawnPoints.IsColliding())
                    {
                        if (targetSpawnPoints.SetConnections() == false)
                        {
                            works = false;
                        }
                    }
                }

                if (ZoneCheck(rp) == false)
                {
                    works = false;
                }

                if (works == false)
                {
                    rp.KillMe();
                }
                else
                {
                    pieceNotPlaced = false;
                    return(rp);
                }
            }
            return(null);
        }
        else
        {
            return(null);
        }
    }