Пример #1
0
    public FilledRegion Apply(FillData data)
    {
        float OuterCircle = data.BeingFilled.Width * 0.5f;

        if (OuterCircle <= InnerCircle)
        {
            throw new ArgumentOutOfRangeException("The outer radius has to be larger than the inner radius!");
        }

        Location center = data.BeingFilled.Center;

        //Make the circles.
        data.FillCircle(true, center, OuterCircle);
        data.FillCircle(false, center, InnerCircle);

        //Make the lines to get to the inner circle.
        data.FillLine(false, center, data.BeingFilled.BottomMid);
        data.FillLine(false, center, data.BeingFilled.TopMid);
        data.FillLine(false, center, data.BeingFilled.LeftMid);
        data.FillLine(false, center, data.BeingFilled.RightMid);

        //For spawn points, give the two points just to the left/right of the inner circle.
        return(new CircleRegion(data.BeingFilled, InnerCircle));
    }
    public FilledRegion Apply(FillData data)
    {
        //Keep track of the spawn areas above the steps, indexed by y coordinate.
        Dictionary <int, Region> platformSpaces = new Dictionary <int, Region>();

        //Get step data.
        int  stepWidth  = (int)Math.Round(StepSizeScale * (data.BeingFilled.Width + 1), 0);
        int  spaceWidth = data.BeingFilled.Width + 1 - stepWidth - stepWidth;
        bool left       = true;

        Location line1, line2;

        for (int y = data.BeingFilled.Bottom - 1; y > data.BeingFilled.Top; y -= Space)
        {
            //Fill the line.
            if (left)
            {
                line1 = new Location(data.BeingFilled.Left, y);
                line2 = new Location(data.BeingFilled.Left + stepWidth - 1, y);

                data.FillLine(true, line1, line2);
                platformSpaces.Add(y, new Region(line1, line2, true));
            }
            else
            {
                line1 = new Location(data.BeingFilled.Left + stepWidth + spaceWidth, y);
                line2 = new Location(data.BeingFilled.Right, y);

                data.FillLine(true, line1, line2);
                platformSpaces.Add(y, new Region(line1, line2, true));
            }

            //Change sides.
            left = !left;
        }

        //Free any holes.
        foreach (Location l in data.HolesAlongPerimeter())
        {
            //If the hole is on the left side and there's a platform in the way:
            if (data.BeingFilled.Touches(l.Right, true, true, false) &&
                data.GetMapAt(l.Right))
            {
                //Remove the left edge of the platform.

                data.SetMapAt(l.Right, false);

                Region r = platformSpaces[l.Y];
                ++r.X;
                --r.Width;
                platformSpaces[l.Y] = r;
            }
            //Otherwise, if the hole is on the right side and there's a platform in the way:
            else if (data.BeingFilled.Touches(l.Left, true, true, false) &&
                     data.GetMapAt(l.Left))
            {
                //Remove the right edge of the platform.

                data.SetMapAt(l.Left, false);

                Region r = platformSpaces[l.Y];
                --r.Width;
                platformSpaces[l.Y] = r;
            }
        }

        return(new AlternatingStepsRegion(data.BeingFilled, platformSpaces.Values));
    }