Exemple #1
0
        /// <summary>
        /// Load layout for current level from XML file
        /// </summary>
        private void LoadLevelLayout()
        {
            XDocument doc = XDocument.Load(@"leveldefinitions.xml");
            var definitions = doc.Document.Descendants(XName.Get("Level"));

            XElement levelDef = null;

            /*Find this level in the XML file*/
            foreach (var definition in definitions)
            {
                if (int.Parse(definition.Attribute(XName.Get("Number")).Value) == this.level_number)
                {
                    levelDef = definition;
                    break;
                }
            }

            /*If a definition for this level is found, build it*/
            if (levelDef != null)
            {
                /*Grab "Spawn" element and kids from XML then build Spawner*/
                XElement spawn_info = levelDef.Element(XName.Get("Spawn"));
                this.bag = Spawner.Build(spawn_info);
            }
        }
        // default constructor.
        public ActorManager(float levelWidth, float levelHeight)
        {
            _levelWidth = levelHeight;
            _levelHeight = levelWidth;

            // create lists and default objects.
            machineComponentList = new LinkedList<MachineComponent>();
            environmentObjectList = new LinkedList<EnvironmentObject>();
            levelSpawner = new Spawner(new Vector2(XNACS1Base.World.WorldDimension.X / 2, 140f), spawns: 100, rand_angle: 5f);
            levelReceptacle = new Receptacle(new Vector2(XNACS1Base.World.WorldDimension.X / 2 + 15f, 5f), 10f, 10f);

            // invisible rectangles on screen right, left and floor to hold coins in the world.
            // left world bound.
            environmentObjectList.AddLast(new Wall(new Vector2(-50f - 4f, _levelHeight / 2 + 100), width: 100, height: _levelHeight + 200, bounce: 1.0f));
            // right world bound.
            environmentObjectList.AddLast(new Wall(new Vector2(_levelWidth + 4f, _levelHeight/2 + 100), width: 100, height: _levelHeight + 200, bounce: 1.0f));
            // floor world bound.
            environmentObjectList.AddLast(new Wall(new Vector2(_levelWidth / 2, -50), width: 200 + _levelWidth, height: 100, bounce: 0.75f, static_friction: 0.05f));

            // horiz obstacle wall in middle of screen
            //environmentObjectList.AddLast(new Wall(new Vector2(XNACS1Base.World.WorldDimension.X / 2 - 20, XNACS1Base.World.WorldDimension.Y / 2 - 20f),
            //    width: 25, height: 5, bounce: 0.75f, static_friction: 0.025f));
            environmentObjectList.AddLast(new Wall(new Vector2(XNACS1Base.World.WorldDimension.X / 2 + 15, XNACS1Base.World.WorldDimension.Y / 2 - 35f),
                width: 25, height: 5, bounce: 0.75f, static_friction: 0.025f));
        }