Esempio n. 1
0
 private void AddBranches(int total)
 {
     for (int i = 0; i < total; i++)
     {
         BranchLine line    = ChooseRandomMainBranch();
         bool       success = AddChild(line);
     }
 }
Esempio n. 2
0
        private void AddBlobs(int circles, int hollowChance, int minSize, int maxSize, int minVar, int maxVar, int minWobble, int maxWobble)
        {
            for (int i = 0; i < circles; i++)
            {
                BranchLine line = ChooseRandomMainBranch();

                AddBlob(line, hollowChance, minSize, maxSize, minVar, maxVar, minWobble, maxWobble);
            }
        }
Esempio n. 3
0
        private bool CreatePath(BranchLine parent, int depth)
        {
            if (depth >= maxDepth)
            {
                return(false);
            }

            BranchLine branch = null;

            for (int i = 0; i < 50; i++)
            {
                //choose the end of this branch to branch from previous line

                //choose a random length
                int length = rand.Next(minLineSize, maxLineSize);

                double parentAngle = rand.NextDouble() * 2 * Math.PI;
                if (parent.Start != parent.End)
                {
                    parentAngle = Math.Atan2(parent.End.Y - parent.Start.Y, parent.End.X - parent.Start.X);
                }

                //choose a random direction
                double angle = (rand.NextDouble() * 2 - 1) * mainFreedom * Math.PI + parentAngle;

                //create branch with end point
                PointF     end        = new PointF((float)Math.Cos(angle) * length + parent.End.X, (float)Math.Sin(angle) * length + parent.End.Y);
                BranchLine tempBranch = new BranchLine(parent.End, end);

                if (!IsLineForbidden(tempBranch))
                {
                    branch = tempBranch;
                    break;
                }
            }

            if (branch != null)
            {
                //TODO: draw branch with forbidden values
                Loc2D start = new Loc2D((int)Math.Round(branch.Start.X), (int)Math.Round(branch.Start.Y));
                Loc2D end   = new Loc2D((int)Math.Round(branch.End.X), (int)Math.Round(branch.End.Y));
                DrawStraightPassage(start, end);

                //for now, just add the branch
                parent.Children.Add(branch);

                //call recusrively
                CreatePath(branch, depth + 1);
            }
            return(true);
        }
Esempio n. 4
0
        private void AddBlob(BranchLine line, int hollowChance, int minSize, int maxSize, int minVar, int maxVar, int minWobble, int maxWobble)
        {
            bool  hollow   = rand.Next() % 100 < hollowChance ? true : false;
            int   size     = rand.Next(minSize, maxSize + 1);
            int   diff     = rand.Next(minVar, maxVar + 1);
            int   wobble   = rand.Next(minWobble, maxWobble + 1);
            float progress = (float)rand.NextDouble();
            Loc2D center   = new Loc2D((int)(line.End.X * progress + line.Start.X * (1 - progress)), (int)(line.End.Y * progress + line.Start.Y * (1 - progress)));

            //TODO: check for forbiddance

            //TODO: draw blob
            DrawBlob(center, size, diff, wobble, hollow);
        }
Esempio n. 5
0
        private bool AddChild(BranchLine line)
        {
            //choose a random place to branch from previous line, as a dead end
            BranchLine branch = null;

            for (int i = 0; i < 50; i++)
            {
                //choose the end of this branch to branch from previous line

                //choose a random length
                int length = rand.Next(minLineSize, maxLineSize);

                double parentAngle = rand.NextDouble() * 2 * Math.PI;
                if (line.Start != line.End)
                {
                    parentAngle = Math.Atan2(line.End.Y - line.Start.Y, line.End.X - line.Start.X);
                }

                //choose a random direction
                double angle = (rand.NextDouble() * 2 - 1) * mainFreedom * Math.PI + parentAngle;

                //choose a part of the line
                float phase = (float)rand.NextDouble();

                //create branch with end point
                PointF     start      = new PointF(line.Start.X * (1 - phase) + line.End.X * phase, line.Start.Y * (1 - phase) + line.End.Y * phase);
                PointF     end        = new PointF((float)Math.Cos(angle) * length + start.X, (float)Math.Sin(angle) * length + start.Y);
                BranchLine tempBranch = new BranchLine(start, end);

                if (!IsLineForbidden(tempBranch))
                {
                    branch = tempBranch;
                    break;
                }
            }

            if (branch != null)
            {
                //TODO: draw branch with forbidden values
                Loc2D start = new Loc2D((int)Math.Round(branch.Start.X), (int)Math.Round(branch.Start.Y));
                Loc2D end   = new Loc2D((int)Math.Round(branch.End.X), (int)Math.Round(branch.End.Y));
                DrawStraightPassage(start, end);

                //for now, just add the branch
                line.Children.Add(branch);
            }

            return(false);
        }
Esempio n. 6
0
        private BranchLine ChooseRandomMainBranch()
        {
            BranchLine chosenBranch = null;

            if (startLine.Children.Count > 0)
            {
                chosenBranch = startLine.Children[0];
                BranchLine currentBranch = chosenBranch;
                int        total         = 1;
                while (currentBranch.Children.Count > 0)
                {
                    if (rand.Next(0, total + 1) == 0)
                    {
                        chosenBranch = currentBranch.Children[0];
                    }
                    currentBranch = currentBranch.Children[0];
                    total++;
                }
            }
            return(chosenBranch);
        }
Esempio n. 7
0
        //an initial create-map method
        public override void Generate(int seed, RDungeonFloor entry, List <FloorBorder> floorBorders, Dictionary <int, List <int> > borderLinks)
        {
            //TODO: make sure that this algorithm follows floorBorders and borderLinks constraints

            this.seed    = seed;
            this.entry   = entry;
            FloorBorders = floorBorders;
            BorderLinks  = borderLinks;

            BorderPoints = new Loc2D[2];

            AgeArray = new int[20, 20];
            TopLeft  = new Loc2D(-AgeArray.GetLength(0) / 2, -AgeArray.GetLength(1) / 2);

            rand = new Random(seed);

            maxDepth = 8;
            branches = 5;

            startLine = new BranchLine(new PointF(0, 0), new PointF(0, 0));

            CreatePath(startLine, 0);

            AddBranches(branches);

            AddBlobs(3, 500, 3, 6, 1, 2, 0, 3);

            if (rand.Next() % 100 < 30)
            {
                AddBlob(startLine, 100, 3, 6, 1, 4, 0, 3);
            }

            BorderPoints[0] = TopLeft * -1;
            BorderPoints[1] = TopLeft * -1;

            ConvertToMapArray();
        }
Esempio n. 8
0
        //TODO
        private bool IsLineForbidden(BranchLine line)
        {
            //"draw" pixels of the line, checking to see if any part of the line's crossing is "forbidden"

            return false;
        }
Esempio n. 9
0
        private bool CreatePath(BranchLine parent, int depth)
        {
            if (depth >= maxDepth)
                return false;

            BranchLine branch = null;
            for (int i = 0; i < 50; i++)
            {
                //choose the end of this branch to branch from previous line

                //choose a random length
                int length = rand.Next(minLineSize, maxLineSize);

                double parentAngle = rand.NextDouble() * 2 * Math.PI;
                if (parent.Start != parent.End)
                    parentAngle = Math.Atan2(parent.End.Y - parent.Start.Y, parent.End.X - parent.Start.X);

                //choose a random direction
                double angle = (rand.NextDouble() * 2 - 1) * mainFreedom * Math.PI + parentAngle;

                //create branch with end point
                PointF end = new PointF((float)Math.Cos(angle) * length + parent.End.X, (float)Math.Sin(angle) * length + parent.End.Y);
                BranchLine tempBranch = new BranchLine(parent.End, end);

                if (!IsLineForbidden(tempBranch))
                {
                    branch = tempBranch;
                    break;
                }
            }

            if (branch != null)
            {
                //TODO: draw branch with forbidden values
                Loc2D start = new Loc2D((int)Math.Round(branch.Start.X), (int)Math.Round(branch.Start.Y));
                Loc2D end = new Loc2D((int)Math.Round(branch.End.X), (int)Math.Round(branch.End.Y));
                DrawStraightPassage(start, end);

                //for now, just add the branch
                parent.Children.Add(branch);

                //call recusrively
                CreatePath(branch, depth + 1);
            }
            return true;
        }
Esempio n. 10
0
        private bool AddChild(BranchLine line)
        {
            //choose a random place to branch from previous line, as a dead end
            BranchLine branch = null;
            for (int i = 0; i < 50; i++)
            {
                //choose the end of this branch to branch from previous line

                //choose a random length
                int length = rand.Next(minLineSize, maxLineSize);

                double parentAngle = rand.NextDouble() * 2 * Math.PI;
                if (line.Start != line.End)
                    parentAngle = Math.Atan2(line.End.Y - line.Start.Y, line.End.X - line.Start.X);

                //choose a random direction
                double angle = (rand.NextDouble() * 2 - 1) * mainFreedom * Math.PI + parentAngle;

                //choose a part of the line
                float phase = (float)rand.NextDouble();

                //create branch with end point
                PointF start = new PointF(line.Start.X * (1 - phase) + line.End.X * phase, line.Start.Y * (1 - phase) + line.End.Y * phase);
                PointF end = new PointF((float)Math.Cos(angle) * length + start.X, (float)Math.Sin(angle) * length + start.Y);
                BranchLine tempBranch = new BranchLine(start, end);

                if (!IsLineForbidden(tempBranch))
                {
                    branch = tempBranch;
                    break;
                }
            }

            if (branch != null)
            {
                //TODO: draw branch with forbidden values
                Loc2D start = new Loc2D((int)Math.Round(branch.Start.X), (int)Math.Round(branch.Start.Y));
                Loc2D end = new Loc2D((int)Math.Round(branch.End.X), (int)Math.Round(branch.End.Y));
                DrawStraightPassage(start, end);

                //for now, just add the branch
                line.Children.Add(branch);
            }

            return false;
        }
Esempio n. 11
0
        private void AddBlob(BranchLine line, int hollowChance, int minSize, int maxSize, int minVar, int maxVar, int minWobble, int maxWobble)
        {
            bool hollow = rand.Next() % 100 < hollowChance ? true : false;
            int size = rand.Next(minSize, maxSize + 1);
            int diff = rand.Next(minVar, maxVar + 1);
            int wobble = rand.Next(minWobble, maxWobble + 1);
            float progress = (float)rand.NextDouble();
            Loc2D center = new Loc2D((int)(line.End.X * progress + line.Start.X * (1 - progress)), (int)(line.End.Y * progress + line.Start.Y * (1 - progress)));

            //TODO: check for forbiddance

            //TODO: draw blob
            DrawBlob(center, size, diff, wobble, hollow);
        }
Esempio n. 12
0
        //an initial create-map method
        public override void Generate(int seed, RDungeonFloor entry, List<FloorBorder> floorBorders, Dictionary<int, List<int>> borderLinks)
        {
            //TODO: make sure that this algorithm follows floorBorders and borderLinks constraints

            this.seed = seed;
            this.entry = entry;
            FloorBorders = floorBorders;
            BorderLinks = borderLinks;

            BorderPoints = new Loc2D[2];

            AgeArray = new int[20, 20];
            TopLeft = new Loc2D(-AgeArray.GetLength(0) / 2, -AgeArray.GetLength(1) / 2);

            rand = new Random(seed);

            maxDepth = 8;
            branches = 5;

            startLine = new BranchLine(new PointF(0, 0), new PointF(0, 0));

            CreatePath(startLine, 0);

            AddBranches(branches);

            AddBlobs(3, 500, 3, 6, 1, 2, 0, 3);

            if (rand.Next() % 100 < 30)
                AddBlob(startLine, 100, 3, 6, 1, 4, 0, 3);

            BorderPoints[0] = TopLeft * -1;
            BorderPoints[1] = TopLeft * -1;

            ConvertToMapArray();
        }
Esempio n. 13
0
        //TODO
        private bool IsLineForbidden(BranchLine line)
        {
            //"draw" pixels of the line, checking to see if any part of the line's crossing is "forbidden"

            return(false);
        }