public UnitManager(string strXMLFileSprites, string strXMLFileBullets, ContentManager contentManager) { try { XmlDocument doc = new XmlDocument(); //load all sprites doc.Load(strXMLFileSprites); XmlNodeList nodeList = doc.GetElementsByTagName("Unit"); m_nSampleUnit = nodeList.Count; m_SampleUnit = new Sprite[m_nSampleUnit]; for (int i = 0; i < m_nSampleUnit; i++) { if (nodeList[i].Attributes.Count > 0 && nodeList[i].Attributes["name"].Value.CompareTo("Player") == 0) { m_SampleUnit[i] = new UserControlledSprite(); } else { m_SampleUnit[i] = new AutomatedSprite(); } m_SampleUnit[i].LoadFromXml(nodeList[i], contentManager); } //load all bullets doc.Load(strXMLFileBullets); nodeList = doc.GetElementsByTagName("Bullet"); m_nSampleBullet = nodeList.Count; m_SampleBullet = new Bullet[m_nSampleBullet]; for (int i = 0; i < m_nSampleBullet; i++) { m_SampleBullet[i] = new Bullet(); m_SampleBullet[i].LoadFromXml(nodeList[i], contentManager); } } catch (Exception ex) { throw ex; } }
public Bullet Clone() { Bullet tmp = new Bullet(); tmp.asSprite = this.asSprite.Clone(); tmp.bActive = this.bActive; tmp.bVisible = this.bVisible; tmp.iSpeed = this.iSpeed; tmp.iCollisionBufferX = this.iCollisionBufferX; tmp.iCollisionBufferY = this.iCollisionBufferY; tmp.m_CurrDirection = this.m_CurrDirection; tmp.v2Target = this.v2Target; tmp.m_iNumBullet = this.m_iNumBullet; tmp.m_SoundGun = this.m_SoundGun; tmp.m_iAttack = this.m_iAttack; tmp.m_strName = this.m_strName; tmp.rectPlayField = this.rectPlayField; tmp.m_strName = this.m_strName; tmp.m_iPoint = this.m_iPoint; tmp.m_fTimeToLive = this.m_fTimeToLive; tmp.m_fCurrTime = this.m_fCurrTime; tmp.bLoop = this.bLoop; tmp.m_iMaxNumBullet = this.m_iMaxNumBullet; return tmp; }
public void AddBullet(Bullet bullet) { int index = SearchBullet(bullet); if (index == -1) { bullet.TimeToLive = -1; m_lstBullets.Add(bullet); } else { m_lstBullets[index].NumBullet += bullet.NumBullet; } }
private int SearchBullet(Bullet bullet) { for (int i = 0; i < m_lstBullets.Count; i++) { if (bullet.Name.Equals(m_lstBullets[i].Name)) { return i; } } return -1; }
public void InitNextBullet(Bullet[] arrBullet) { int i; for (i = 0; i < arrBullet.Length; i++) { arrBullet[i] = m_lstBullets[m_iBulletUsing].Clone(); } }