Example #1
0
        public void CreateBots(XmlNodeList nodes, Vector2[] edges)
        {
            Console.WriteLine(nodes.Count);

            foreach (XmlNode botNode in nodes)
            {
                if (botNode.Name == "Award")
                {
                    this.winReward = int.Parse(botNode.InnerText);
                    continue;
                }
                XmlNodeList innerNodes = botNode.ChildNodes;

                Bot.Player AIType;

                Console.WriteLine(innerNodes[0].InnerText);

                SPRAI control;

                switch (innerNodes[0].InnerText)
                {
                case "HumanAI":
                    AIType  = Bot.Player.Human;
                    control = new HumanAI(sprWorld);
                    break;

                case "BrickAI":
                    AIType  = Bot.Player.Computer;
                    control = new BrickAI(sprWorld);
                    break;

                case "ModeAI":
                    AIType  = Bot.Player.Computer;
                    control = new ModeAI(sprWorld);
                    break;

                default:
                    AIType  = Bot.Player.Human;
                    control = new HumanAI(sprWorld);
                    break;
                }

                float     health   = float.Parse(innerNodes[1].InnerText);
                Texture2D texture  = TextureStatic.Get(innerNodes[2].InnerText);
                Vector2   position = new Vector2(int.Parse(innerNodes[3].InnerText), int.Parse(innerNodes[4].InnerText));

                Body tempBody = BodyFactory.CreateBody(world);
                tempBody.BodyType = BodyType.Dynamic;
                Fixture f = FixtureFactory.CreatePolygon(new Vertices(edges), 10f, tempBody);
                f.OnCollision += MyOnCollision;
                f.Friction     = .5f;
                f.Restitution  = 0f;
                tempBody.SetTransform(position * Settings.MetersPerPixel, 0);

                Bot newBot = new Bot(sprWorld, tempBody, AIType, Bot.Type.FourSided, control, texture, 2 * botHalfWidth * Settings.MetersPerPixel, 2 * botHalfWidth * Settings.MetersPerPixel, health);
                f.UserData = newBot;

                for (int weaponNumber = 0; weaponNumber < 4; weaponNumber++)
                {
                    XmlNodeList weaponChilds = innerNodes[weaponNumber + 5].ChildNodes;
                    int         side         = weaponNumber;
                    WeaponType  weaponType;
                    switch (weaponChilds[0].InnerText)
                    {
                    case "gun":
                        weaponType = WeaponType.gun;
                        break;

                    case "shield":
                        weaponType = WeaponType.shield;
                        break;

                    case "melee":
                        weaponType = WeaponType.melee;
                        break;

                    default:
                        weaponType = WeaponType.gun;
                        break;
                    }
                    String weaponTexture = weaponChilds[1].InnerText;
                    float  weaponHealth  = float.Parse(weaponChilds[2].InnerText);
                    float  weaponPower   = float.Parse(weaponChilds[3].InnerText);

                    newBot.AddWeapon(weaponNumber, weaponTexture, weaponType, weaponHealth, weaponPower);
                }

                sprWorld.AddEntity(newBot);
            }
        }