Exemplo n.º 1
0
        public override void OnMouseLeftDown(System.Drawing.Point location)
        {
            int sizeX = LayerEditor.Layer.GridCellsX;
            int sizeY = LayerEditor.Layer.GridCellsY;

            FlxCaveGenerator cave = new FlxCaveGenerator(LayerEditor.Layer.GridCellsX, LayerEditor.Layer.GridCellsY);

            cave.genInitMatrix(LayerEditor.Layer.GridCellsX, LayerEditor.Layer.GridCellsY);
            int[,] level = cave.generateCaveLevel();

            for (int y = 0; y < sizeY; y++)
            {
                for (int x = 0; x < sizeX; x++)
                {
                    level[y, x] = Convert.ToInt32(LayerEditor.Layer.Grid[x, y]);
                }
            }

            level = cave.smoothLevel(level);

            for (int y = 0; y < sizeY; y++)
            {
                for (int x = 0; x < sizeX; x++)
                {
                    System.Drawing.Point p = new System.Drawing.Point(x * LayerEditor.Layer.Definition.Grid.Width, y * LayerEditor.Layer.Definition.Grid.Height);

                    setCell(p, false);

                    if (level[y, x] == 1)
                    {
                        setCell(p, true);
                    }
                    else
                    {
                        setCell(p, false);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void cave()
        {
            int sizeX = LayerEditor.Layer.TileCellsX;
            int sizeY = LayerEditor.Layer.TileCellsY;

            FlxCaveGenerator cave = new FlxCaveGenerator(sizeX, sizeY);

            cave.genInitMatrix(sizeX, sizeY);
            int[,] level = cave.generateCaveLevel();

            for (int y = 0; y < sizeY; y++)
            {
                for (int x = 0; x < sizeX; x++)
                {
                    if (LayerEditor.Layer.Tiles[x, y] == -1)
                    {
                        level[y, x] = 0;
                    }
                    else
                    {
                        level[y, x] = 1;
                    }
                }
            }

            level = cave.smoothLevel(level);

            string MapData = cave.convertMultiArrayToString(level);

            int heightInTiles = 0;

            //Figure out the map dimensions based on the data string
            string[] cols;
            string[] rows = MapData.Split('\n');
            heightInTiles = rows.Length;
            int r = 0;
            int c;

            cols  = rows[r].Split(',');
            _data = new int[rows.Length * cols.Length];
            while (r < heightInTiles)
            {
                cols = rows[r++].Split(',');
                if (cols.Length <= 1)
                {
                    heightInTiles = heightInTiles - 1;
                    continue;
                }
                if (widthInTiles == 0)
                {
                    widthInTiles = cols.Length;
                }
                c = 0;
                while (c < widthInTiles)
                {
                    _data[((r - 1) * widthInTiles) + c] = int.Parse(cols[c++]);
                }
            }

            int total      = 0;
            int ii         = 0;
            int totalTiles = LayerEditor.Layer.TileCellsX * LayerEditor.Layer.TileCellsY;

            while (ii < totalTiles)
            {
                autoTile(ii++);
            }

            total = 0;

            for (int y = 0; y < sizeY; y++)
            {
                for (int x = 0; x < sizeX; x++)
                {
                    System.Drawing.Point p = new System.Drawing.Point(x * LayerEditor.Layer.Definition.Grid.Width, y * LayerEditor.Layer.Definition.Grid.Height);

                    SetCaveTile(p, -1);

                    if (_data[total] >= 1)
                    {
                        SetCaveTile(p, _data[total] - 1);
                    }
                    else
                    {
                        SetCaveTile(p, -1);
                    }
                    total++;
                }
            }
        }