Ejemplo n.º 1
0
        public void Init()
        {
            _tiles = new GraphicTile[16, 16];

            for (int j = 0; j < Height; j++)
            {
                for (int i = 0; i < Width; i++)
                {
                    _tiles[i, j] = new GraphicTile(i == j ? 1 : 0, 0);
                }
            }
        }
Ejemplo n.º 2
0
        public static GraphicTile[,] CalculateTiles(LevelTile[,] tiles)
        {
            const int SPRITE_SHEET_SIZE = 4;
            var       width             = tiles.GetLength(0);
            var       height            = tiles.GetLength(1);
            var       gTiles            = new GraphicTile[width, height];

            System.Func <int, int, bool> inBounds = (x, y) => x >= 0 && x < width && y >= 0 && y < height;

            for (int j = 0; j < height; j++)
            {
                for (int i = 0; i < width; i++)
                {
                    var tile = tiles[i, j];
                    if (tile.Type == LevelTile.TileTypes.Wall)
                    {
                        var wallSpriteInfo = GetWallSpriteInfo(
                            inBounds(i + 1, j) ? tiles[i + 1, j].Type == LevelTile.TileTypes.Wall : false,                             // right
                            inBounds(i + 1, j + 1) ? tiles[i + 1, j + 1].Type == LevelTile.TileTypes.Wall : false,                     // topRight
                            inBounds(i, j + 1) ? tiles[i, j + 1].Type == LevelTile.TileTypes.Wall : false,                             // top
                            inBounds(i - 1, j + 1) ? tiles[i - 1, j + 1].Type == LevelTile.TileTypes.Wall : false,                     // topLeft
                            inBounds(i - 1, j) ? tiles[i - 1, j].Type == LevelTile.TileTypes.Wall : false,                             // left
                            inBounds(i - 1, j - 1) ? tiles[i - 1, j - 1].Type == LevelTile.TileTypes.Wall : false,                     // bottomLeft
                            inBounds(i, j - 1) ? tiles[i, j - 1].Type == LevelTile.TileTypes.Wall : false,                             // bottom
                            inBounds(i + 1, j - 1) ? tiles[i + 1, j - 1].Type == LevelTile.TileTypes.Wall : false                      // bottomRight
                            );
                        gTiles[i, j] = new GraphicTile
                                           (wallSpriteInfo.SpritePosition % SPRITE_SHEET_SIZE,
                                           wallSpriteInfo.SpritePosition / SPRITE_SHEET_SIZE,
                                           wallSpriteInfo.Rotation * 90);
                    }
                }
            }

            return(gTiles);
        }