Ejemplo n.º 1
0
        public override void OnMouseRightDown(System.Drawing.Point location)
        {
            if (!drawing)
            {
                drawing  = true;
                drawMode = true;

                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 i = 0; i < sizeX; i++)
                {
                    for (int j = 0; j < sizeY; j++)
                    {
                        System.Drawing.Point p = new System.Drawing.Point(i * LayerEditor.Layer.Definition.Grid.Width, j * LayerEditor.Layer.Definition.Grid.Height);

                        setCell(p, true);

                        if (level[j, i] == 1)
                        {
                            setCell(p, false);
                        }
                        else
                        {
                            setCell(p, true);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
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);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void cave(int custom = 0)
        {
            int sizeX = LayerEditor.Layer.TileCellsX;
            int sizeY = LayerEditor.Layer.TileCellsY;

            Console.WriteLine("Size X {0} Size Y {1} - crashes? ", sizeX, sizeY);


            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 if (LayerEditor.Layer.Tiles[x, y] <= LayerEditor.Layer.Tileset.TilesAcross - 1)
                    {
                        level[y, x] = 1;
                    }
                    // HACK : Setting this decoration tile to a negative number so doesn't affect auto-tiling
                    // HACK : Revert to original before setting tile.
                    else
                    {
                        level[y, x] = (LayerEditor.Layer.Tiles[x, y] + 1) * -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;

                // TODO:
                // This causes a crash in some situations. //

                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)
            {
                if (custom == 1)
                {
                    customAutoTile(ii++);
                }
                else if (custom == 2)
                {
                    squareAutoTile(ii++);
                }
                else
                {
                    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 if (_data[total] == 0)
                    {
                        SetCaveTile(p, -1);
                    }
                    // HACK : Since this is a negative number, it's a decoration tile.
                    // HACK : Reverse the tile number to revert back to decoration.
                    else if (_data[total] < 0)
                    {
                        SetCaveTile(p, (_data[total] + 1) * -1);
                    }
                    total++;
                }
            }
        }
Ejemplo n.º 4
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++;
                }
            }
        }