Beispiel #1
0
        public void LoadContent(Vector2 tileDimensions, Vector2 tileOffset, Vector2 mapDimensions)
        {
            if (Image.Path != String.Empty)
            {
                Image.LoadContent();
            }
            Vector2 position = -tileDimensions;

            position.X += mapDimensions.X;
            position.Y -= Height * tileDimensions.X / 8;
            TileOffset  = tileOffset;

            // Save the dimensions of the layer
            LayerDimensions.Y = TMap.Row.Count;
            LayerDimensions.X = TMap.Row[0].Split('[').Length - 1;

            int numTile = 0; int numRows = 0;

            foreach (string row in TMap.Row)
            {
                // Get the tiles
                string[] split = row.Split(']');
                position.X  = -tileDimensions.X - tileOffset.X * numRows + mapDimensions.X;;
                position.Y += tileDimensions.X / 2 - tileOffset.Y * numTile - tileOffset.Y; // tile dimensions.x/2 is a hack to get the sample to work

                // Loop through all of the tiles and load their content from the tile sheet based on val1 and val2
                numTile = 0;
                foreach (string s in split)
                {
                    if (s != String.Empty)
                    {
                        position += tileOffset;
                        if (!s.Contains("x"))
                        {
                            // Create a new tile and add it to the list
                            IsometricTile t   = new IsometricTile();
                            string        str = s.Replace("[", String.Empty);
                            t.Value1       = int.Parse(str.Substring(0, str.IndexOf(':')));
                            t.Value2       = int.Parse(str.Substring(str.IndexOf(':') + 1));
                            t.GridLocation = new Point(numTile, numRows);
                            t.Height       = Height;
                            t.LoadContent(position, new Rectangle(t.Value1 * (int)tileDimensions.X, t.Value2 * (int)tileDimensions.Y,
                                                                  (int)tileDimensions.X, (int)tileDimensions.Y));

                            if (OverlayTiles.Contains("[" + t.Value1.ToString() + ":" + t.Value2.ToString() + "]"))
                            {
                                _overlayTiles.Add(t);
                            }
                            else
                            {
                                _underlayTiles.Add(t);
                            }
                        }
                        numTile++;
                    }
                }
                numRows++;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Converts the tilemap into a two dimensional Tile array
        /// </summary>
        /// <returns>2D Tile array</returns>
        public IsometricTile[,] GetTileArray2D()
        {
            IsometricTile[,] data = new IsometricTile[(int)LayerDimensions.X, (int)LayerDimensions.Y];

            foreach (IsometricTile t in _underlayTiles)
            {
                data[t.GridLocation.X, t.GridLocation.Y] = t;
            }

            return(data);
        }
Beispiel #3
0
        public void LoadContent(Vector2 layerDimensions, Vector2 tileDimensions)
        {
            _layerDimensions = layerDimensions;
            _tileDimensions  = tileDimensions;
            _tiles           = new IsometricTile[(int)layerDimensions.X, (int)layerDimensions.Y];

            for (int y = 0; y < layerDimensions.Y; y++)
            {
                for (int x = 0; x < layerDimensions.X; x++)
                {
                    _tiles[x, y] = new IsometricTile();
                }
            }
        }