Пример #1
0
        /// <summary>
        /// Configures the Area's Defined Total space, as well as MapCamera operating restriction space
        /// </summary>
        /// <param name="mapAreaName">Reference name for Area being used to set the boundaries</param>
        private void SetAreaBoundaries(string mapAreaName)
        {
            MapAreaDefinition _currentArea = null;

            foreach (MapAreaDefinition _area in Areas)
            {
                if (_area.Name == mapAreaName)
                {
                    _currentArea   = _area;
                    ActiveAreaName = _area.Name;
                }
            }

            if (ActiveArea != null)
            {
                ActiveArea = _currentArea.BoundingBox;
            }
            else
            {
                ActiveArea = new Rectangle((int)_currentArea.BoundingBox.X, (int)_currentArea.BoundingBox.Y, (int)_currentArea.BoundingBox.Width, (int)_currentArea.BoundingBox.Height);
            }
        }
Пример #2
0
        /// <summary>
        /// Loads MapObjects for the Active Map, iterates through them, and instantiates objects
        /// based on the information found in the Map ObjectLayers
        /// </summary>
        private void LoadMapObjectLayers()
        {
            TiledMapObjectLayer _mapEntityObjectLayer   = MapCurrent.GetLayer <TiledMapObjectLayer>("Entity Layer");
            TiledMapObjectLayer _mapCollisionLayer      = MapCurrent.GetLayer <TiledMapObjectLayer>("Collision Layer");
            TiledMapObjectLayer _mapAreaDefinitionLayer = MapCurrent.GetLayer <TiledMapObjectLayer>("Area Definitions");

            foreach (TiledMapObject _entityObject in _mapEntityObjectLayer.Objects)
            {
                switch (_entityObject.Name)
                {
                case "mapPlayerSpawn":
                {
                    // Run Player Spawn Code Here
                    PlayerSpawnX  = Convert.ToInt32(_entityObject.Position.X);
                    PlayerSpawnY  = Convert.ToInt32(_entityObject.Position.Y);
                    IsPlayerSpawn = true;

                    break;
                }

                case "mapTransition":
                {
                    // Create Transition Objects
                    float destinationX, destinationY;

                    destinationX = Convert.ToInt32(_entityObject.Properties["mapDestinationX"]);
                    destinationY = Convert.ToInt32(_entityObject.Properties["mapDestinationY"]);

                    MapTransitionHandler mapTransition = new MapTransitionHandler(contentManager, _entityObject.Properties["mapDestination"],
                                                                                  new Vector2((float)destinationX, (float)destinationY), new Rectangle((int)_entityObject.Position.X, (int)_entityObject.Position.Y, (int)_entityObject.Size.Width, (int)_entityObject.Size.Height),
                                                                                  _entityObject.Properties["mapDestinationArea"], _entityObject.Properties["mapDestinationFacing"]);

                    MapObjects.Add(mapTransition);
                    break;
                }

                case "mapEntitySpawn":
                {
                    // Get AssetManager Data
                    AnimationLibrary _animationLibrary = AssetManager.GetAnimationLibrary(_entityObject.Properties["AnimationLibraryName"]);

                    // Spawn the Entity
                    bool isSolid = Convert.ToBoolean(_entityObject.Properties["IsSolid"]);

                    MapEntityStatic _mapEntity = new MapEntityStatic(isSolid, new Vector2(_entityObject.Position.X, _entityObject.Position.Y), (int)_entityObject.Size.Width, (int)_entityObject.Size.Height, _entityObject.Properties["AnimationLibraryName"]);
                    _mapEntity.ConstructAnimationLibrary(_animationLibrary.Name, _entityObject.Properties["CurrentAnimation"]);

                    Entities.Add(_mapEntity);
                    break;
                }
                }
            }
            foreach (TiledMapObject _collisionObject in _mapCollisionLayer.Objects)
            {
                switch (_collisionObject.Name)
                {
                case "solidStatic":
                {
                    MapCollisionSolidStatic solid = new MapCollisionSolidStatic(_collisionObject.Position, (int)_collisionObject.Size.Width, (int)_collisionObject.Size.Height);
                    CollisionObjects.Add(solid);
                    break;
                }
                }
            }
            foreach (TiledMapObject _areaDefintion in _mapAreaDefinitionLayer.Objects)
            {
                MapAreaDefinition area = new MapAreaDefinition(_areaDefintion.Name, new Vector2((int)_areaDefintion.Position.X, (int)_areaDefintion.Position.Y),
                                                               new Rectangle((int)_areaDefintion.Position.X, (int)_areaDefintion.Position.Y, (int)_areaDefintion.Size.Width, (int)_areaDefintion.Size.Height));

                Areas.Add(area);
            }
        }