Tiled Mapper's tile, a single element of the tiled map.
コード例 #1
0
ファイル: Tile.cs プロジェクト: SnakeSolidNL/tools
 public Tile AttachToTile(Tile tile, int fromDir)
 {
     tile.attachTile(this, fromDir);
     neighbours[(fromDir + 2) % 4] = tile;
     blocks[(fromDir + 2) % 4] = tile.GetBlock(fromDir);
     return this;
 }
コード例 #2
0
 private int test2(Tile tile, int dir1, int dir2, int value)
 {
     if (!tile.IsPath(dir1) || !tile.IsPath(dir2)) return value;
     if (!tile.GetNeighbour(dir1).IsPath(dir2)) return value;
     if (!tile.GetNeighbour(dir2).IsPath(dir1)) return value;
     return 0;
 }
コード例 #3
0
ファイル: Changes.cs プロジェクト: SnakeSolidNL/tools
 public ChangeInternalResize(int dir, int size, Tile[,] tiles)
     : base(ChangeType.InternalResize)
 {
     Dir = dir;
     Size = size;
     Tiles = tiles;
     if (dir != Directions.North) StopUndo = false;
     if (dir != Directions.West) StopRedo = false;
 }
コード例 #4
0
ファイル: Map.Resizing.cs プロジェクト: SnakeSolidNL/tools
        /// <summary>
        /// Resize the map instance.
        /// </summary>
        /// <param name="n">Number or rows to be added to or removed from the north side</param>
        /// <param name="e">Number or columns to be added to or removed from the east side</param>
        /// <param name="s">Number or rows to be added to or removed from the south side</param>
        /// <param name="w">Number or columns to be added to or removed from the west side</param>
        public void Resize(int n, int e, int s, int w)
        {
            if (-n >= Height || -s >= Height || -e >= Width || -w >= Width) return;
            if (-(n + s) >= Height || -(e + w) >= Width) return;
            Tile[,] cutTiles;
            if (n < 0)
            {
                cutTiles = new Tile[Width, -n];
                for (int x = 0; x < Width; x++)
                    for (int y = 0; y < -n; y++)
                        cutTiles[x, y] = tiles[x, y];
            }
            else cutTiles = null;
            ChangeInternalResize ch = new ChangeInternalResize(Directions.North, n, cutTiles);
            apply(ch);

            if (e < 0)
            {
                cutTiles = new Tile[-e, Height];
                for (int x = Width + e; x < Width; x++)
                    for (int y = 0; y < Height; y++)
                        cutTiles[x - (Width + e), y] = tiles[x, y];
            }
            else cutTiles = null;
            ch = new ChangeInternalResize(Directions.East, e, cutTiles);
            apply(ch);

            if (s < 0)
            {
                cutTiles = new Tile[Width, -s];
                for (int x = 0; x < Width; x++)
                    for (int y = Height + s; y < Height; y++)
                        cutTiles[x, y - (Height + s)] = tiles[x, y];
            }
            else cutTiles = null;
            ch = new ChangeInternalResize(Directions.South, s, cutTiles);
            apply(ch);

            if (w < 0)
            {
                cutTiles = new Tile[-w, Height];
                for (int x = 0; x < -w; x++)
                    for (int y = 0; y < Height; y++)
                        cutTiles[x, y] = tiles[x, y];
            }
            else cutTiles = null;
            ch = new ChangeInternalResize(Directions.West, w, cutTiles);
            apply(ch);

            FullRedraw();
        }
コード例 #5
0
        public int GetTileHash(Tile tile)
        {
            int hash = 0;
            hash += test2(tile, Directions.South, Directions.East, b(0));
            hash += test(tile, Directions.South, b(1));
            hash += test2(tile, Directions.South, Directions.West, b(2));
            hash += test(tile, Directions.East, b(3));
            hash += test(tile, Directions.West, b(4));
            hash += test2(tile, Directions.North, Directions.East, b(5));
            hash += test(tile, Directions.North, b(6));
            hash += test2(tile, Directions.North, Directions.West, b(7));

            return hash;
        }
コード例 #6
0
        public int GetTileCorridorHash(Tile tile)
        {
            int tHash = GetTileHash(tile);
            int hash = 0;
            // vertical at corners
            hash += ctest2(tHash, b(6), b(7), b(0));
            hash += ctest2(tHash, b(6), b(5), b(1));
            hash += ctest2(tHash, b(1), b(2), b(2));
            hash += ctest2(tHash, b(1), b(0), b(3));

            // horizontal at corners
            hash += ctest2(tHash, b(4), b(7), b(4));
            hash += ctest2(tHash, b(3), b(5), b(5));
            hash += ctest2(tHash, b(4), b(2), b(6));
            hash += ctest2(tHash, b(3), b(0), b(7));

            // vertical
            hash += ctest(tHash, b(4), b(8));
            hash += ctest(tHash, b(3), b(9));
            hash += ctest(tHash, b(6), b(10));
            hash += ctest(tHash, b(1), b(11));

            return hash;
        }
コード例 #7
0
ファイル: Tile.cs プロジェクト: SnakeSolidNL/tools
 protected void attachTile(Tile tile, int fromDir)
 {
     neighbours[fromDir] = tile;
 }
コード例 #8
0
 private int test(Tile tile, int dir, int value)
 {
     if (tile.IsPath(dir)) return 0;
     return value;
 }
コード例 #9
0
ファイル: Map.Resizing.cs プロジェクト: SnakeSolidNL/tools
        private void undoWestResize(ChangeInternalResize ch)
        {
            int size = ch.Size;
            Tile[,] newTiles = new Tile[Width - size, Height];
            if (size > 0)
            {
                for (int x = size; x < Width; x++)
                    for (int y = 0; y < Height; y++)
                        newTiles[x - size, y] = tiles[x, y];
                for (int y = 0; y < Height; y++)
                    newTiles[0, y].DropTile(Directions.West);
            }
            else
            {
                for (int x = -size; x < Width - size; x++)
                    for (int y = 0; y < Height; y++)
                        newTiles[x, y] = tiles[x + size, y];
                Tile[,] oldTiles = ch.Tiles;
                for (int x = 0; x < -size; x++)
                    for (int y = 0; y < Height; y++)
                        newTiles[x, y] = oldTiles[x, y];

                joinTiles(newTiles, Width - size, Height);
                for (int y = 0; y < Height; y++)
                    newTiles[-size - 1, y].AttachToTile(newTiles[-size, y], Directions.West);
            }
            tiles = newTiles;
            Width -= size;
            fixScrollblockers(-size, 0);
            reattachScrollBlockers();
        }
コード例 #10
0
ファイル: Map.Resizing.cs プロジェクト: SnakeSolidNL/tools
        private void undoSouthResize(ChangeInternalResize ch)
        {
            int size = ch.Size;
            Tile[,] newTiles = new Tile[Width, Height - size];
            if (size > 0)
            {
                for (int x = 0; x < Width; x++)
                    for (int y = 0; y < Height - size; y++)
                        newTiles[x, y] = tiles[x, y];
                for (int x = 0; x < Width; x++)
                    newTiles[x, Height - size - 1].DropTile(Directions.South);
            }
            else
            {
                for (int x = 0; x < Width; x++)
                    for (int y = 0; y < Height; y++)
                        newTiles[x, y] = tiles[x, y];
                Tile[,] oldTiles = ch.Tiles;
                for (int x = 0; x < Width; x++)
                    for (int y = 0; y < -size; y++)
                        newTiles[x, Height + y] = oldTiles[x, y];

                joinTiles(newTiles, Width, Height - size);
                for (int x = 0; x < Width; x++)
                    newTiles[x, Height].AttachToTile(newTiles[x, Height - 1], Directions.South);
            }
            tiles = newTiles;
            Height -= size;
            fixScrollblockers(0, 0);
            reattachScrollBlockers();
        }
コード例 #11
0
ファイル: Map.Resizing.cs プロジェクト: SnakeSolidNL/tools
        private void redoNorthResize(ChangeInternalResize ch)
        {
            int size = ch.Size;
            Tile[,] newTiles = new Tile[Width, Height + size];
            if (size > 0)
            {
                for (int x = 0; x < Width; x++)
                    for (int y = 0; y < Height; y++)
                        newTiles[x, y + size] = tiles[x, y];
                for (int x = 0; x < Width; x++)
                    for (int y = 0; y < size; y++)
                        newTiles[x, y] = new Tile();

                joinTiles(newTiles, Width, Height + size);
                for (int x = 0; x < Width; x++)
                    newTiles[x, size - 1].AttachToTile(newTiles[x, size], Directions.North);
            }
            else
            {
                for (int x = 0; x < Width; x++)
                    for (int y = 0; y < Height + size; y++)
                        newTiles[x, y] = tiles[x, y - size];
                for (int x = 0; x < Width; x++)
                    newTiles[x, 0].DropTile(Directions.North);
            }
            tiles = newTiles;
            Height += size;
            fixScrollblockers(0, size);
        }
コード例 #12
0
ファイル: Map.Resizing.cs プロジェクト: SnakeSolidNL/tools
        private void redoEastResize(ChangeInternalResize ch)
        {
            int size = ch.Size;
            Tile[,] newTiles = new Tile[Width + size, Height];
            if (size > 0)
            {
                for (int x = 0; x < Width; x++)
                    for (int y = 0; y < Height; y++)
                        newTiles[x, y] = tiles[x, y];
                for (int x = Width; x < Width + size; x++)
                    for (int y = 0; y < Height; y++)
                        newTiles[x, y] = new Tile();

                joinTiles(newTiles, Width + size, Height);
                for (int y = 0; y < Height; y++)
                    newTiles[Width - 1, y].AttachToTile(newTiles[Width, y], Directions.East);
            }
            else
            {
                for (int x = 0; x < Width + size; x++)
                    for (int y = 0; y < Height; y++)
                        newTiles[x, y] = tiles[x, y];
                for (int y = 0; y < Height; y++)
                    newTiles[Width + size - 1, y].DropTile(Directions.East);
            }
            tiles = newTiles;
            Width += size;
            fixScrollblockers(0, 0);
        }
コード例 #13
0
ファイル: Map.cs プロジェクト: SnakeSolidNL/tools
 private static Tile[,] makeTiles(int width, int height)
 {
     Tile[,] tiles = new Tile[width, height];
     for (int x = 0; x < width; x++)
         for (int y = 0; y < height; y++)
         {
             tiles[x, y] = new Tile(0, false);
             if (x > 0) tiles[x, y].AttachToTile(tiles[x - 1, y], Directions.East);
             if (y > 0) tiles[x, y].AttachToTile(tiles[x, y - 1], Directions.South);
         }
     return tiles;
 }
コード例 #14
0
ファイル: Map.cs プロジェクト: SnakeSolidNL/tools
 private static void joinTiles(Tile[,] tiles, int width, int height)
 {
     for (int x = 0; x < width; x++)
         for (int y = 0; y < height; y++)
         {
             if (x > 0) tiles[x, y].AttachToTile(tiles[x - 1, y], Directions.East);
             if (y > 0) tiles[x, y].AttachToTile(tiles[x, y - 1], Directions.South);
         }
 }