Пример #1
0
        /// <summary>
        /// Adds collision types to the places on the map where it is needed.
        /// </summary>
        /// <param name="mapLayers"> The map layers the map is created from. </param>
        /// <param name="tilesets"> The tilesets the map is created from. </param>
        public void AddCollision(List <MapLayer> mapLayers, List <Tileset> tilesets)
        {
            // Finds the layer with the name "collision" in the list of layers.
            var collisionLayer = new MapLayer("collision", this.width, this.height);

            foreach (var mapLayer in mapLayers.Where(mapLayer => mapLayer.LayerName.Equals("collision")))
            {
                collisionLayer = mapLayer;
            }

            this.mapData = new MapCell[collisionLayer.Height, collisionLayer.Width];

            // Iterates over all the cells in the collisionlayer and stores their type of
            // collision in the respective cell in the mapData.
            for (int i = 0; i < this.height; i++)
            {
                for (int j = 0; j < this.width; j++)
                {
                    var cell = new MapCell
                    {
                        Collision =
                            (CollisionType)
                            (collisionLayer.GetTile(j, i).TileID - tilesets.ToArray()[collisionLayer.GetTile(j, i).TileSet].StartID)
                    };

                    this.mapData[i, j] = cell;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Adds collision types to the places on the map where it is needed.
        /// </summary>
        /// <param name="mapLayers"> The map layers the map is created from. </param>
        /// <param name="tilesets"> The tilesets the map is created from. </param>
        public void AddCollision(List<MapLayer> mapLayers, List<Tileset> tilesets)
        {
            // Finds the layer with the name "collision" in the list of layers.
            var collisionLayer = new MapLayer("collision", this.width, this.height);
            foreach (var mapLayer in mapLayers.Where(mapLayer => mapLayer.LayerName.Equals("collision")))
            {
                collisionLayer = mapLayer;
            }

            this.mapData = new MapCell[collisionLayer.Height, collisionLayer.Width];

            // Iterates over all the cells in the collisionlayer and stores their type of
            // collision in the respective cell in the mapData.
            for (int i = 0; i < this.height; i++)
            {
                for (int j = 0; j < this.width; j++)
                {
                    var cell = new MapCell
                    {
                        Collision =
                            (CollisionType)
                            (collisionLayer.GetTile(j, i).TileID - tilesets.ToArray()[collisionLayer.GetTile(j, i).TileSet].StartID)
                    };

                    this.mapData[i, j] = cell;
                }
            }
        }