Пример #1
0
            public void CalculateDirection()
            {
                int random = VGUtils.GetRandomInt(0, 4);

                switch (random)
                {
                case 0:
                    _nextX = 1;
                    _nextY = 0;
                    break;

                case 1:
                    _nextX = -1;
                    _nextY = 0;
                    break;

                case 2:
                    _nextX = 0;
                    _nextY = 1;
                    break;

                case 3:
                    _nextX = 0;
                    _nextY = -1;
                    break;
                }
            }
Пример #2
0
        public override void Generate(VGArea mArea)
        {
            FinalAreas.Add(mArea.Clone());

            for (int i = 0; i < Splits; i++)
            {
                FinalAreas = Split(FinalAreas, i % 2 == 0, i == Splits - 1);
            }

            List <VGArea> toRemove = FinalAreas.Where(t => VGUtils.GetRandomInt(0, 100) <= RemoveChancePercent).ToList();

            foreach (VGArea area in toRemove)
            {
                FinalAreas.Remove(area);
            }

            if (IsBorder)
            {
                foreach (VGArea area in FinalAreas)
                {
                    foreach (VGTile tile in area.GetBorderTiles())
                    {
                        tile.Set(ValueSolid, false);
                    }
                }
            }

            if (IsCarved)
            {
                foreach (VGArea area in FinalAreas)
                {
                    for (int iY = 1 + CarveOffset; iY < area.Height - 1 - CarveOffset; iY++)
                    {
                        for (int iX = 1 + CarveOffset; iX < area.Width - 1 - CarveOffset; iX++)
                        {
                            area[iX, iY].Set(ValueRoom);
                        }
                    }
                }
            }

            if (IsConnected)
            {
                for (int index = 0; index < FinalAreas.Count - 1; index++)
                {
                    Connect(FinalAreas[index], FinalAreas[index + 1]);
                }
            }

            mArea.SetBorder(1);
        }
Пример #3
0
            public void Step()
            {
                if (VGUtils.GetRandomInt(0, 100) <= WalkerDirectionChangeChance)
                {
                    CalculateDirection();
                }
                if ((_steps > WalkerMinimumSteps && VGUtils.GetRandomInt(0, 1000) < WalkerDeathChance) || _steps > WalkerMaximumSteps)
                {
                    Alive = false;
                }
                X += _nextX;
                Y += _nextY;

                _steps++;
            }
Пример #4
0
        public override void Generate(VGArea mArea)
        {
            for (int i = 0; i < WalkersAmount; i++)
            {
                VGTile randomTile = mArea.GetRandomTile();
                WalkerPaths.Add(new VGGWalkerPath(randomTile.X, randomTile.Y, WalkerMinimumSteps, WalkerMaximumSteps, WalkerDeathChance, WalkerDirectionChangeChance));
            }

            bool running = true;

            while (running)
            {
                List <VGGWalkerPath> toRemove = new List <VGGWalkerPath>();
                running = false;

                foreach (VGGWalkerPath path in WalkerPaths)
                {
                    if (mArea.Contains(path.X, path.Y))
                    {
                        for (int iY = -WalkerRadius; iY < WalkerRadius + 1; iY++)
                        {
                            for (int iX = -WalkerRadius; iX < WalkerRadius + 1; iX++)
                            {
                                if (mArea.Contains(path.X + iX, path.Y + iY))
                                {
                                    mArea[path.X + iX, path.Y + iY].Set(ValuePassable);
                                }
                            }
                        }
                    }
                    else if (IsWrapped)
                    {
                        if (path.X >= mArea.Width)
                        {
                            path.X = 0;
                        }
                        else if (path.X < 0)
                        {
                            path.X = mArea.Width - 1;
                        }

                        if (path.Y >= mArea.Height)
                        {
                            path.Y = 0;
                        }
                        else if (path.Y < 0)
                        {
                            path.Y = mArea.Height - 1;
                        }
                    }

                    path.Step();

                    if (path.Alive)
                    {
                        running = true;
                    }
                    else if (IsRoomCreatedOnDeath)
                    {
                        toRemove.Add(path);

                        int roomWidth  = VGUtils.GetRandomInt(RoomMinSize, RoomMaxSize);
                        int roomHeight = VGUtils.GetRandomInt(RoomMinSize, RoomMaxSize);

                        for (int iY = 0; iY < roomHeight; iY++)
                        {
                            for (int iX = 0; iX < roomWidth; iX++)
                            {
                                if (mArea.Contains(path.X - (roomWidth / 2) + iX, path.Y - (roomHeight / 2) + iY))
                                {
                                    mArea[path.X - (roomWidth / 2) + iX, path.Y - (roomHeight / 2) + iY].Set(ValuePassable);
                                }
                            }
                        }
                    }
                }

                foreach (VGGWalkerPath pathToRemove in toRemove)
                {
                    WalkerPaths.Remove(pathToRemove);
                }
            }
        }