Beispiel #1
0
        /// <summary>
        /// Creates the proper map object layer based on the layer name such as collidables and path nodes.
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="orientation"></param>
        /// <returns></returns>
        private MapObjectLayer CreateObjectLayer(LayerContent layer, Orientation orientation)
        {
            if (layer == null)
            {
                throw new ArgumentNullException("layer");
            }

            ObjectLayerContent objectLayerContent = layer as ObjectLayerContent;

            MapObjectLayerType mapObjectLayerType;
            MapObjectType      mapObjectType;

            if (objectLayerContent.Name == "DeadZones")
            {
                mapObjectLayerType = MapObjectLayerType.DeadZone;
                mapObjectType      = MapObjectType.DeadZone;
            }
            else if (objectLayerContent.Name == "PathNodes")
            {
                mapObjectLayerType = MapObjectLayerType.PathNode;
                mapObjectType      = MapObjectType.PathNode;
            }
            else if (objectLayerContent.Name == "Equipment")
            {
                mapObjectLayerType = MapObjectLayerType.Equipment;
                mapObjectType      = MapObjectType.Equipment;
            }
            else
            {
                throw new Exception("Unknown map object layer type. Did you name your layer correctly? \"DeadZones\", \"PathNodes\", and \"Equipment\" are valid layers.");
            }

            MapObjectLayer mapObjectLayer = new MapObjectLayer(objectLayerContent.Name, mapObjectLayerType);

            foreach (ObjectContent objectContent in objectLayerContent.MapObjects)
            {
                if (mapObjectLayer.Type == MapObjectLayerType.PathNode)
                {
                    PathNode pathNode = new PathNode(objectContent.Name, objectContent.Bounds, orientation, objectContent.Properties);
                    mapObjectLayer.AddMapObject(pathNode);
                }
                else if (mapObjectLayer.Type == MapObjectLayerType.Equipment)
                {
                    EquipmentObjectType equipmentObjectType = GetEquipmentObjectType(objectContent);
                    EquipmentObject     equipmentObject     = new EquipmentObject(objectContent.Name, objectContent.Bounds, orientation, objectContent.Properties, equipmentObjectType);
                    mapObjectLayer.AddMapObject(equipmentObject);
                }
                else
                {
                    MapObject mapObject = new MapObject(objectContent.Name, objectContent.Bounds, orientation, mapObjectType, objectContent.Properties);
                    mapObjectLayer.AddMapObject(mapObject);
                }
            }

            return(mapObjectLayer);
        }
Beispiel #2
0
        /// <summary>
        /// Create tile layers and object layers based on what we find in the Tiled Map TMX file.
        /// </summary>
        /// <param name="mapContent">Map contentManager.</param>
        private void CreateLayers(MapContent mapContent)
        {
            if (mapContent == null)
            {
                throw new ArgumentNullException("mapContent");
            }

            foreach (LayerContent layerContent in mapContent.Layers)
            {
                if (layerContent is TileLayerContent)
                {
                    TileLayer tileLayer = CreateTileLayer(layerContent, mapContent.TileSets);
                    tileLayers.Add(tileLayer);
                }
                else if (layerContent is ObjectLayerContent)
                {
                    MapObjectLayer mapObjectLayer = CreateObjectLayer(layerContent, mapContent.Orientation);
                    mapObjectLayers.Add(mapObjectLayer);
                }
            }
        }