MrGravity.Import_Code.Importer.GetObjects C# (CSharp) Method

GetObjects() public method

Goes through all the entities and finds all of the ones that are Static, or physics(Dynamic maybe in the future) Creates and returns them using the data found in the xml file
public GetObjects ( PhysicsEnvironment &environment ) : List
environment PhysicsEnvironment Environment that these items exist in
return List
        public List<GameObject> GetObjects(ref PhysicsEnvironment environment)
        {
            var objects = new List<GameObject>();
            foreach (var entity in _mEntities)
            {
                //If the object is static, make a static object
                if (entity.MType == XmlKeys.StaticObject)
                {
                    var tile = new Tile(_mContent, .8f, entity);
                    objects.Add(tile);

                }
                //If the object is physics, make a physics object
                if (entity.MType == XmlKeys.PhysicsObject)
                {
                    if (entity.MProperties.ContainsKey("Rail") && entity.MProperties.ContainsKey("Length"))
                        _mRails.Add(entity);

                    var isSquare = entity.MProperties.ContainsKey("Shape") && entity.MProperties["Shape"] == "Square";
                    float mass = 1;
                    if (entity.MProperties.ContainsKey("Mass"))
                    {
                        mass = (float)Convert.ToDouble(entity.MProperties["Mass"]);
                    }
                    if (entity.MProperties.ContainsKey(XmlKeys.Reverse))
                    {
                        var rTile = new ReverseTile(_mContent, ref environment, 0.8f, entity);
                        rTile.Mass = mass;
                        objects.Add(rTile);
                    }
                    else
                    {
                        var mTile = new MovingTile(_mContent, ref environment, 0.8f, entity);
                        mTile.Mass = mass;
                        objects.Add(mTile);
                    }
                }
            }

            return objects;
        }

Usage Example

示例#1
0
        /// <summary>
        /// Loads the level from the content manager
        /// </summary>
        /// <param name="content">Content Manager to load from</param>
        public void Load(ContentManager content)
        {
            _mObjects.Clear();
            Reset();

            var importer = new Importer(content);
            importer.ImportLevel(this);

            _mPlayer = new Player(content, ref _mPhysicsEnvironment,
                _mControls, .8f, EntityInfo.CreatePlayerInfo(GridSpace.GetGridCoord(StartingPoint)));

            _mObjects.Add(_mPlayer);
            _mObjects.AddRange(importer.GetObjects(ref _mPhysicsEnvironment));

            _mPlayerEnd = importer.GetPlayerEnd();
            if (_mPlayerEnd != null)
                _mObjects.Add(_mPlayerEnd);

            _mObjects.AddRange(importer.GetWalls(this).Cast<GameObject>());

            _mRails = importer.GetRails();

            _mTrigger.AddRange(importer.GetTriggers());

            PrepareCollisionMatrix();

            MNumCollected = 0;
            MNumCollectable = 0;

            //Clear the collection lists
            _mCollected.Clear();
            _mRemoveCollected.Clear();

            foreach (var gObject in _mObjects)
            {
                if (gObject.CollisionType == XmlKeys.Collectable)
                    MNumCollectable++;
            }
        }