コード例 #1
0
    List <Frame> MakeFrames(int entry, int width, int height, List <Edge> entries,
                            List <Edge> addedRotationsRightTo, System.Random random)
    {
        List <Frame> frames = new List <Frame>();

        FrameWall leftWall = entries.Contains(Edge.Left) ? RandomEntryFrameWall(entry, height, random)
          : new FrameWall(height);
        FrameWall rightWall = entries.Contains(Edge.Right) ? RandomEntryFrameWall(entry, height, random)
          : new FrameWall(height);
        FrameWall topWall = entries.Contains(Edge.Top) ? RandomEntryFrameWall(entry, width, random)
          : new FrameWall(width);
        FrameWall bottomWall = entries.Contains(Edge.Bottom) ? RandomEntryFrameWall(entry, width, random)
          : new FrameWall(width);

        Frame frame = new Frame(new Dictionary <Edge, FrameWall>()
        {
            { Edge.Left, leftWall }, { Edge.Right, rightWall }, { Edge.Top, topWall }, { Edge.Bottom, bottomWall }
        });

        frames.Add(frame);

        foreach (Edge rotEdge in addedRotationsRightTo)
        {
            frames.Add(frame.RotatedRightTo(rotEdge));
        }

        return(frames);
    }
コード例 #2
0
    //my edge
    public FrameRange FrameRangeOff(Edge edge)
    {
        FrameWall wall = FrameWalls[edge];

        if (!wall.HasEntry)
        {
            return(FrameRange.Empty);
        }

        Dictionary <Edge, FrameWallRange> frameWallRanges = new Dictionary <Edge, FrameWallRange>();

        frameWallRanges[edge.Opposite()] = new FrameWallRange(
            new FrameWall(0, wall.Entry, 0),
            new FrameWall(int.MaxValue, wall.Entry, int.MaxValue)
            );
        foreach (Edge missingEdge in EdgeExtensions.AllEdges())
        {
            if (!frameWallRanges.ContainsKey(missingEdge))
            {
                frameWallRanges[missingEdge] = FrameWallRange.All;
            }
        }

        return(new FrameRange(frameWallRanges));
    }
コード例 #3
0
    public FrameWallRange Intersection(FrameWallRange otherWallRange)
    {
        FrameWall newFrameWallMin = FrameWall.Max(FrameWallMin, otherWallRange.FrameWallMin);
        FrameWall newFrameWallMax = FrameWall.Min(FrameWallMax, otherWallRange.FrameWallMax);

        return(new FrameWallRange(newFrameWallMin, newFrameWallMax));
    }
コード例 #4
0
    public Vector2 CenterToEntry(Edge edge)
    {
        //TODO: make sure frame wall is nice and encapsulated, for easy change
        FrameWall frameWall   = FrameWalls[edge];
        Vector2   entryOffset = EdgeDelta(edge) * (frameWall.PreWall + frameWall.Entry / 2.0f - frameWall.Length / 2.0f);

        return(entryOffset + CenterToEdge(edge));
    }
コード例 #5
0
 public bool LessThanOrEqualTo(FrameWall frameWall)
 {
     return(Length <= frameWall.Length &&
            (!HasEntry || frameWall.HasEntry) &&
            PreWall <= frameWall.PreWall &&
            Entry <= frameWall.Entry &&
            PostWall <= frameWall.PostWall);
 }
コード例 #6
0
 public bool Contains(FrameWall frameWall)
 {
     if (IsEmpty)
     {
         return(false);
     }
     return(FrameWallMin.LessThanOrEqualTo(frameWall) &&
            frameWall.LessThanOrEqualTo(FrameWallMax));
 }
コード例 #7
0
    public static FrameWall Max(FrameWall wall1, FrameWall wall2)
    {
        // TODO Might need to remove entry from length
        int entry    = Mathf.Max(wall1.Entry, wall2.Entry);
        int preWall  = Mathf.Max(wall1.PreWall, wall2.PreWall);
        int postWall = Mathf.Max(wall1.PostWall, wall2.PostWall);

        return(new FrameWall(preWall, entry, postWall));
    }
コード例 #8
0
    public static FrameWall Min(FrameWall wall1, FrameWall wall2)
    {
        //WARNING LIKELY WONT WORK
        int entry    = Mathf.Min(wall1.Entry, wall2.Entry);
        int preWall  = Mathf.Min(wall1.PreWall, wall2.PreWall);
        int postWall = Mathf.Min(wall1.PostWall, wall2.PostWall);

        return(new FrameWall(preWall, entry, postWall));
    }
コード例 #9
0
    public void MakeEntry(Edge edge, FrameWall frameWall)
    {
        Vector2Int delta = groundArray.EdgeDelta(edge);
        Vector2Int start = groundArray.EdgeStart(edge);

        for (int i = frameWall.PreWall; i < frameWall.PreWall + frameWall.Entry; i++)
        {
            groundArray[start.x + delta.x * i, start.y + delta.y * i] = true;
        }
    }
コード例 #10
0
    public void MakeHallway(Edge edge, Frame frame)
    {
        FrameWall  frameWall = frame.FrameWalls[edge];
        Vector2Int delta     = groundArray.EdgeDelta(edge);
        Vector2Int perpDelta = groundArray.PerpEdgeDelta(edge);
        Vector2Int start     = groundArray.EdgeStart(edge);
        FrameWall  counterClockwiseFrameWall = frame.FrameWalls[edge.RotatedRightTo(Edge.Top)];
        FrameWall  clockwiseFrameWall        = frame.FrameWalls[edge.RotatedRightTo(Edge.Bottom)];
        int        end;
        bool       hasAdjacentEdge = true;

        if (counterClockwiseFrameWall.HasEntry)
        {
            end = counterClockwiseFrameWall.GetWallBySign(edge.GetSign()) + counterClockwiseFrameWall.Entry;
        }
        else if (clockwiseFrameWall.HasEntry)
        {
            end = clockwiseFrameWall.GetWallBySign(edge.GetSign()) + clockwiseFrameWall.Entry;
        }
        else
        {
            hasAdjacentEdge = false;
            end             = (frame.GetDimension(edge.Opposite().GetOrientation())) / 2;
        }

        //Debug.Log("End:" + end);

        for (int i = frameWall.PreWall; i < frameWall.PreWall + frameWall.Entry; i++)
        {
            for (int j = 0; j < end; j++)
            {
                groundArray[start.x + delta.x * i + perpDelta.x * j, start.y + delta.y * i + perpDelta.y * j] = true;
            }
        }

        if (hasAdjacentEdge == false)
        {
            //Vector2Int centerHallStart = start + delta * (frameWall.PreWall+frameWall.Entry) + perpDelta * end;
            //Vector2Int centerHallDelta = delta;
            //Vector2Int centerHallEnd = frameWall.PreWall+frameWall.Entry -

            int centerRoomRadius = frameWall.PreWall + frameWall.Entry / 2 - frame.GetDimension(edge.Opposite().GetOrientation()) / 2;

            groundArray.FillRect(true, frame.Width / 2 - centerRoomRadius, frame.Width / 2 + centerRoomRadius,
                                 frame.Height / 2 - centerRoomRadius, frame.Height / 2 + centerRoomRadius);
            //for (int i = frameWall.PreWall; i < frameWall.PreWall + frameWall.Entry; i++)
            //{
            //    for (int j = 0; j < end; j++)
            //    {
            //        groundArray[start.x + delta.x * i + perpDelta.x * j, start.y + delta.y * i + perpDelta.y * j] = true;
            //    }
            //}
        }
    }
コード例 #11
0
 public FrameWallRange(FrameWall frameWallMin, FrameWall frameWallMax, bool isEmpty = false)
 {
     FrameWallMin = frameWallMin;
     FrameWallMax = frameWallMax;
     IsEmpty      = isEmpty;
     if (!IsValid())
     {
         //Debug.Log("Framewall min is not less than or equal to framewall max, setting empty");
         IsEmpty = true;
     }
     //throw new ArgumentException("Framewall min is not less than or equal to framewall max");
 }