Beispiel #1
0
 protected bool CollidesWithMatchingType(BiomeRect buildingBiomeRect)
 {
     foreach (var rect in Rects)
     {
         if (rect.Intersects(buildingBiomeRect) && rect.Colour == buildingBiomeRect.Colour)
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #2
0
        protected void AddRect(BiomeRect n)
        {
            var newRects = new List <BiomeRect>(20)
            {
                n
            };
            var victims = new List <BiomeRect>(20);

            foreach (var rect in Rects)
            {
                if (!n.Intersects(rect))
                {
                    continue;
                }

                victims.Add(rect);

                var clampn = rect.Intersect(n);

                if (clampn.BottomLeft.X > rect.BottomLeft.X)
                {
                    var colour = rect.Colour;
                    newRects.Add(new BiomeRect(rect.BottomLeft, new BiomeVector(clampn.BottomLeft.X, rect.TopRight.Y), colour));
                }

                if (clampn.TopRight.X < rect.TopRight.X)
                {
                    var colour = rect.Colour;
                    newRects.Add(new BiomeRect(new BiomeVector(clampn.TopRight.X, rect.BottomLeft.Y), rect.TopRight, colour));
                }

                if (clampn.BottomLeft.Y > rect.BottomLeft.Y)
                {
                    var colour = rect.Colour;
                    newRects.Add(new BiomeRect(new BiomeVector(clampn.BottomLeft.X, rect.BottomLeft.Y), new BiomeVector(clampn.TopRight.X, clampn.BottomLeft.Y), colour));
                }

                if (clampn.TopRight.Y < rect.TopRight.Y)
                {
                    var colour = rect.Colour;
                    newRects.Add(new BiomeRect(new BiomeVector(clampn.BottomLeft.X, clampn.TopRight.Y), new BiomeVector(clampn.TopRight.X, rect.TopRight.Y), colour));
                }
            }

            foreach (var victim in victims)
            {
                Rects.Remove(victim);
            }

            Rects.AddRange(newRects);
        }
Beispiel #3
0
        private void AddMainRoads()
        {
            // add vertical road.
            var mainRoadColor = Legend.MainRoadColor;
            var vertRoadRect  = new BiomeRect(MainRoadWidth, 0, Width, MainRoadWidth, mainRoadColor);

            AddRect(vertRoadRect);

            // add horizontal road.
            var horizRoadRect = new BiomeRect(0, MainRoadWidth, MainRoadWidth, Height, mainRoadColor);

            AddRect(horizRoadRect);

            // add junction.0
            var junctionRect = new BiomeRect(0, 0, MainRoadWidth, MainRoadWidth, Legend.JunctionColor);

            AddRect(junctionRect);
        }
Beispiel #4
0
        private void AddField()
        {
            var w = Rng.NextFloat(Width / 6, Width / 3);
            var h = Rng.NextFloat(Width / 6, Height / 3);
            var x = Rng.NextFloat(FarmGenerationMargin, Width - w);
            var y = Rng.NextFloat(FarmGenerationMargin, Height - h);

            /*
             * int h;
             * int x;
             * int y;
             * var w = h = x = y = 10;
             */
            var field = new BiomeRect(x, y, x + w, y + h, Legend.FieldColor);

            if (CollidesWithMatchingType(field))
            {
                return;
            }

            AddRect(field);

            // bails

            /*
             * var bailcount = (int)(BailDensity *  (((w * h) / ((float)BailSize * BailSize))));
             *
             * for (var i = 0; i < bailcount; i++)
             * {
             *  var bx = Rng.Next(field.TopLeft.X + BailSize, field.BottomRight.X - BailSize);
             *  var by = Rng.Next(field.TopLeft.Y + BailSize, field.BottomRight.Y - BailSize);
             *
             *  var bail = new Rect(bx, by, bx + BailSize, by + BailSize, BailColor);
             *
             *  if (CollidesWithMatchingType(bail))
             *      continue;
             *
             *  AddRect(bail);
             * }
             */
        }
Beispiel #5
0
        private static void DrawRect(Graphics graphics, BiomeRect biomeRect)
        {
            var clipbounds = graphics.ClipBounds.Height;

            var darkColour = Color.FromArgb(255, biomeRect.Colour.R / 3, biomeRect.Colour.G / 3, biomeRect.Colour.B / 3);

            var darkBrush = new LinearGradientBrush(new Point((int)biomeRect.TopLeft.X, (int)(clipbounds - biomeRect.TopLeft.Y)),
                                                    new Point((int)biomeRect.BottomRight.X, (int)(clipbounds - biomeRect.BottomRight.Y)),
                                                    biomeRect.Colour, darkColour);

            var medColour = Color.FromArgb(92, biomeRect.Colour.R / 2, biomeRect.Colour.G / 2, biomeRect.Colour.B / 2);
            var medPen    = new Pen(medColour)
            {
                Width = 1f
            };

            graphics.FillRectangle(darkBrush, biomeRect.TopLeft.X, clipbounds - biomeRect.TopLeft.Y, biomeRect.Width, biomeRect.Height);
            graphics.DrawRectangle(medPen, biomeRect.TopLeft.X, clipbounds - biomeRect.TopLeft.Y, biomeRect.Width, biomeRect.Height);
            graphics.DrawLine(medPen, biomeRect.TopLeft.X, clipbounds - biomeRect.TopLeft.Y,
                              biomeRect.BottomRight.X, clipbounds - biomeRect.BottomRight.Y);
        }
Beispiel #6
0
        private void AddHouse()
        {
            var w = Rng.Next(64, 80);
            var h = Rng.Next(64, 80);
            var x = Rng.Next(FarmGenerationMargin + 1, (int)(Width - w));
            var y = Rng.Next(FarmGenerationMargin + 1, (int)(Height - h));

            var drivewayColor = Legend.DrivewayColor;
            var parkingspace  = new BiomeRect(x, y, x + w, y + h, drivewayColor);

            AddRect(parkingspace);

            var hh = Rng.Next(h / 2, h - 1);
            var hw = Rng.Next(w / 2, w - 1);

            var hx = Rng.NextFloat(x, x + (w - hw));
            var hy = Rng.NextFloat(y, y + (h - hh));

            var house = new BiomeRect(hx, hy, hx + hw, hy + hh, Legend.HouseColor);

            AddRect(house);

            var drivewayX = Rng.NextFloat(x, x + w - DrivewayWidth);
            var driveway  = new BiomeRect(drivewayX, FarmGenerationMargin, drivewayX + DrivewayWidth, y, drivewayColor);

            AddRect(driveway);

            var stableStartX = x - 120 < 0 ? x + w + 20 : x - 100;
            var stableX      = Rng.NextFloat(stableStartX, stableStartX + 60);
            var stableY      = Rng.NextFloat(y, y + (h / 2.0f));

            var stableWidth  = Rng.Next(35, 45);
            var stableHeight = Rng.Next(40, 50);

            var outhouse = new BiomeRect(stableX, stableY, stableX + stableWidth, stableY + stableHeight, Legend.Stable);

            //AddRect(outhouse);
        }