예제 #1
0
        public void LoadItems(string file)
        {
            List <ItemData> myObjects  = new List <ItemData>();
            XmlSerializer   serializer = new XmlSerializer(typeof(List <ItemData>), new XmlRootAttribute("Map"));

            using (XmlReader reader = XmlReader.Create(file))
            {
                myObjects = (List <ItemData>)serializer.Deserialize(reader);
            }
            if (file == "./LevelLoader/Level1.xml")
            {
                for (int i = 800; i < 1100; i += 32)
                {
                    GameObjectManager.itemList.Add(new Coin(new Vector2(i, 578)));
                    GameObjectManager.itemList.Add(new Coin(new Vector2(i, 514)));
                }
                for (int i = 820; i < 1100; i += 32)
                {
                    GameObjectManager.itemList.Add(new Coin(new Vector2(i, 546)));
                }
            }
            foreach (ItemData item in myObjects)
            {
                switch (item.itemType)
                {
                case ItemType.Coin:
                    GameObjectManager.itemList.Add(new Coin(new Vector2(item.xLocation, item.yLocation)));
                    break;

                case ItemType.Flower:
                    GameObjectManager.itemList.Add(new FireFlower(new Vector2(item.xLocation, item.yLocation)));
                    break;

                case ItemType.SuperMushroom:
                    GameObjectManager.itemList.Add(new SuperMushroom(new Vector2(item.xLocation, item.yLocation)));
                    break;

                case ItemType.UpMushroom:
                    GameObjectManager.itemList.Add(new UpMushroom(new Vector2(item.xLocation, item.yLocation)));
                    break;

                case ItemType.Star:
                    GameObjectManager.itemList.Add(new Star(new Vector2(item.xLocation, item.yLocation)));
                    break;

                case ItemType.Flag:
                    GameObjectManager.itemList.Add(new Flag(new Vector2(item.xLocation, item.yLocation)));
                    break;

                case ItemType.FlagTop:
                    GameObjectManager.itemList.Add(new FlagTop(new Vector2(item.xLocation, item.yLocation)));
                    break;

                case ItemType.FlagPole:
                    ScoringSystem.RegisgerFlagPole(new FlagPole(new Vector2(item.xLocation, item.yLocation)));
                    GameObjectManager.itemList.Add(new FlagPole(new Vector2(item.xLocation, item.yLocation)));
                    break;

                case ItemType.PiranhaPlants:
                    GameObjectManager.itemList.Add(new PiranhaPlants(new Vector2(item.xLocation, item.yLocation), mario));
                    break;
                }
            }
        }