コード例 #1
0
        public void CreateVaultInRoom(Vault v, Room r)
        {
            uint[,] tileInts  = v.tileInts;
            uint[,] spikeInts = v.spikeInts;



            for (int x = 0; x < tileInts.GetLength(0); x++)
            {
                for (int y = 0; y < tileInts.GetLength(1); y++)
                {
                    uint rawTile = tileInts [x, y];
                    int  tile    = (int)(rawTile & ~(0xE0000000));                 // ignore flipping and rotating
                    // Tiled add's a 1 to the tile so that 0 can be blank
                    tile--;
                    Coordinates newCoords = new Coordinates(x, tileInts.GetLength(0) - 1 - y);
                    newCoords.x += r.pos.x;
                    newCoords.y += r.pos.y;
                    newCoords.x -= r.size.x / 2;
                    //				newCoords.y -= r.size.y;
                    newCoords.y -= r.size.y / 2;

                    if (tile != -1)
                    {
                        map.SetTile(newCoords.x, newCoords.y, wallLayer, tile);
                    }
                }
            }
            for (int x = 0; x < spikeInts.GetLength(0); x++)
            {
                for (int y = 0; y < spikeInts.GetLength(1); y++)
                {
                    uint rawTile = spikeInts [x, y];
                    int  tile    = (int)(rawTile & ~(0xE0000000));                 // ignore flipping and rotating
                    // Tiled add's a 1 to the tile so that 0 can be blank
                    tile--;
                    Coordinates newCoords = new Coordinates(x, tileInts.GetLength(0) - 1 - y);
                    newCoords.x += r.pos.x;
                    newCoords.y += r.pos.y;
                    newCoords.x -= r.size.x / 2;
                    //				newCoords.y -= r.size.y;
                    newCoords.y -= r.size.y / 2;

                    if (tile == spikeTile)
                    {
                        map.SetTile(newCoords.x, newCoords.y, (int)TileLayer.Spike, tile);
                    }

                    // Set tile flags
                    bool          flipHorizontal = (rawTile & 0x80000000) != 0;
                    bool          flipVertical   = (rawTile & 0x40000000) != 0;
                    bool          flipDiagonal   = (rawTile & 0x20000000) != 0;
                    tk2dTileFlags tileFlags      = 0;
                    if (flipDiagonal)
                    {
                        tileFlags |= (tk2dTileFlags.Rot90 | tk2dTileFlags.FlipX);
                    }
                    if (flipHorizontal)
                    {
                        tileFlags ^= tk2dTileFlags.FlipX;
                    }
                    if (flipVertical)
                    {
                        tileFlags ^= tk2dTileFlags.FlipY;
                    }
                    map.SetTileFlags(newCoords.x, newCoords.y, (int)TileLayer.Spike, tileFlags);
                }
            }
        }