/// <summary>
        /// Get ammo packs attributes
        /// </summary>
        /// <param name="xmlDoc">XML document that contains the attributes</param>
        public static void LoadGunsAttributes(XmlDocument xmlDoc, ref GameEntityList sceneObjects)
        {
            Debug.Assert(xmlDoc != null);
            Debug.Assert(sceneObjects != null);

            XmlNodeList nodeList = xmlDoc.GetElementsByTagName("guns");

            if (nodeList.Count > 0) //if XML has ammopacks...
            {
                //get list of guns in scene
                XmlElement nodeElement = (XmlElement)nodeList.Item(0);

                //List available gun types in project
                List<String> guntypeNames = new List<String>(Enum.GetNames(typeof(GunType)));
                Int32[] guntypeValues = (Int32[])Enum.GetValues(typeof(GunType));

                //get all guns definitions from XML file
                foreach (XmlElement xmle in nodeElement.ChildNodes)
                {
                    String assetName = null;
                    Gun g = new Gun();

                    try
                    {
                        assetName = Convert.ToString(xmle.GetAttribute("name"));
                        g.NumberOfBullets = Convert.ToInt32(xmle.GetAttribute("bullets"));

                        //traduz o string em um tipo enumerado
                        Int32 position = guntypeNames.IndexOf(xmle.GetAttribute("guntype"));
                        g.GunType = (GunType)guntypeValues[position];
                        g.IsRotatable = Convert.ToBoolean(xmle.GetAttribute("isRotatable"));

                        if (g.IsRotatable == true)
                            g.AngleOffset = Convert.ToSingle(xmle.GetAttribute("angleOffset"));

                        String spriteName = Convert.ToString(xmle.GetAttribute("spriteAssetName"));
                        String bulletAssetName = Convert.ToString(xmle.GetAttribute("bulletAssetName"));
                        Model bulletModel = SystemResources.Content.Load<Model>(@bulletAssetName);
                        int bulletLifeTime = Convert.ToInt32(xmle.GetAttribute("bulletLifeTime"));

                        g.Sprite = SystemResources.Content.Load<Texture2D>(@spriteName);
                        g.Bullet = new Bullet(bulletLifeTime, bulletModel.Meshes[0]);
                        g.Bullet.Damage = Convert.ToInt32(xmle.GetAttribute("bulletDamage"));
                        g.Bullet.BulletModel = bulletModel;
                    }
                    catch (InvalidCastException e)
                    {
                        Log.Write("BuildObjectsList: InvalidCastExpcetion raised (did you forget some ammopack setting?)");
                        Log.Write(e.Message);
                    }

                    sceneObjects.Add(assetName, g);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Add a new gun to the list of arms
        /// </summary>
        /// <param name="g">IT MUST HAVE TO BE A GUN!!!</param>
        public void Add(GameObjectEntity goe)
        {
            if (goe is Gun)
            {
                Gun g = (Gun)goe;
                arms.Add(g);

                if (this.actualGun == null)
                    this.actualGun = g;
            }
            else
            {
                Log.Write("Erro: Player.Add esperava um objeto do tipo 'Gun'");
            }
        }