コード例 #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);
                        }
                    }
                }
            }
        }
コード例 #2
0
        public static FlxTilemap createCave()
        {
            FlxCaveGenerator cav = new FlxCaveGenerator((int)Registry.levelSize.X, (int)Registry.levelSize.Y, 0.55f, 30);
            
            int[,] matr = cav.generateCaveLevel(null, null, null, null, null, null, null, null);

            matr = cav.editRectangle(matr, 0, (int)Registry.levelSize.Y / 2, (int)Registry.levelSize.X, 4, 1);
            matr = cav.editRectangle(matr, (int)Registry.levelSize.X / 2, 0, 4, (int)Registry.levelSize.Y, 1);

            matr = cav.grow(matr);

            matr = cav.editRectangle(matr, 0, 0, (int)Registry.levelSize.X, 1, 0);
            matr = cav.editRectangle(matr, 0, 0, 1, (int)Registry.levelSize.Y, 0);

            matr = cav.editRectangle(matr, 0, (int)Registry.levelSize.Y-1, (int)Registry.levelSize.X, 1, 0);
            matr = cav.editRectangle(matr, (int)Registry.levelSize.X-1, 0, 1, (int)Registry.levelSize.Y, 0);

            string newMap = cav.convertMultiArrayToString(matr);

            FlxTilemap tiles = new FlxTilemap();
            // Remap guide before loading map
            tiles.remapGuide = Registry.createAltTileRemap();
            tiles.auto = FlxTilemap.REMAPALT;
            tiles.loadMap(newMap, FlxG.Content.Load<Texture2D>("tiles/oryx_16bit_fantasy_world_trans"), Registry.tileSize, Registry.tileSize);

            tiles.setScrollFactors(1, 1);

            Registry.levelAsTilemap = tiles;

            return tiles;

        }
コード例 #3
0
ファイル: FlxPathState.cs プロジェクト: akadjoker/XNAFlixel
        public void makeCave(float Scroll, Color Col)
        {
            // make a new cave of tiles 50x40;
            FlxCaveGenerator cav = new FlxCaveGenerator(100, 100, 0.48f, 1);

            //Create a matrix based on these parameters.
            int[,] matr = cav.generateCaveLevel(3, 0, 2, 0, 1, 1, 1, 1);

            //convert the array to a comma separated string
            string newMap = cav.convertMultiArrayToString(matr);

            //Create a tilemap and assign the cave map.
            tiles      = new FlxTilemap();
            tiles.auto = FlxTilemap.AUTO;
            tiles.loadMap(newMap, FlxG.Content.Load <Texture2D>("flixel/autotiles_16x16"), 16, 16);
            tiles.setScrollFactors(Scroll, Scroll);
            tiles.color = Col;

            add(tiles);
        }
コード例 #4
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);
                    }
                }
            }
        }
コード例 #5
0
        private void buildCave()
        {
            // make a new cave of tiles 50x40;
            cav = new FlxCaveGenerator(50, 50, 0.55f, 30);

            //Create a matrix based on these parameters.
            matr = cav.generateCaveLevel(null, null, null, null, null, null, new int[] { 0, 49 }, new int[] { 0, 49 });
            matr = cav.grow(matr);

            foreach (Dictionary<string, string> item in Registry.boxes)
            {
                Console.WriteLine("{0} {1} {2} {3} {4} ", item["Name"], item["x"], item["y"], item["width"], item["height"]);

                if (item["Name"] == "TileCrate")
                {

                    createTileblock(item);

                    matr = cav.editRectangle(matr, Convert.ToInt32(item["x"]) / 16, Convert.ToInt32(item["y"]) / 16, Convert.ToInt32(item["width"]) / 16, Convert.ToInt32(item["height"]) / 16, 0);
                }
            }
            //foreach (Dictionary<string, string> item in p)
            //{
            //    if (item["Name"]=="Crate")
            //        matr = cav.editRectangle(matr, Convert.ToInt32(item["x"]) / 16, Convert.ToInt32(item["y"]) / 16 , 4, 4, 0);
            //}

            string newMap = cav.convertMultiArrayToString(matr);

            //Create a tilemap and assign the cave map.
            tiles = new FlxTilemap();
            tiles.auto = FlxTilemap.REMAPALT;
            tiles.loadMap(newMap, FlxG.Content.Load<Texture2D>("tiles/oryx_16bit_fantasy_world_trans"), 24, 24);
            tiles.setScrollFactors(1, 1);
            add(tiles);

            Registry.levelAsTilemap = tiles;

            for (int i = 0; i < 55; i++)
            {
                int rx = FlxU.randomInt(1, 35);
                int ry = FlxU.randomInt(1, 35);

                int rz = tiles.getTile(rx, ry);

                if (rz == 292)
                {
                    Dictionary<string, string> x = new Dictionary<string, string>();
                    x.Add("Name", "PickUp");
                    x.Add("x", (rx * 24).ToString());
                    x.Add("y", (ry * 24).ToString());

                    createSprite(x);
                }

            }

            for (int i = 0; i < 1; i++)
            {
                int rx = FlxU.randomInt(1, 35);
                int ry = FlxU.randomInt(1, 35);

                int rz = tiles.getTile(rx, ry);

                if (rz == 292)
                {
                    Dictionary<string, string> x = new Dictionary<string, string>();
                    x.Add("Name", "Character");
                    x.Add("x", (rx * 24).ToString());
                    x.Add("y", ((ry * 24) - 2).ToString());

                    createSprite(x);
                }
            }
        }
コード例 #6
0
ファイル: TileAutoTool.cs プロジェクト: initials/OgmoEditor2
        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++;
                }
            }
        }
コード例 #7
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++;
                }
            }
        }