Ejemplo n.º 1
0
        /// <summary>
        /// Read all enemy objects present in the level.
        /// </summary>
        /// <returns></returns>
        public static LinkedList<Enemy> readEnemies()
        {
            int EnemyCount;
            LinkedList<Enemy> enemies = new LinkedList<Enemy>();
            string content;

            if (currentReadTarget == null)
                throw new Exception("File read target not set. LevelParser.readEnemies");

            using (System.Xml.XmlReader r = System.Xml.XmlReader.Create(currentReadTarget))
            {
                r.MoveToContent();
                r.ReadToFollowing("objects");
                r.ReadToDescendant("enemies");

                content = r.ReadElementContentAsString();
                r.Close();
            }

            String[] EnemyString = CleanUp(content);

            EnemyCount = EnemyString.Length / 3;

            for (int i = 0; i < EnemyCount; ++i)
            {
                int[] rectangleValues = getNumbers(EnemyString[i * 3].Substring(4));
                Rectangle r = new Rectangle(rectangleValues[0], rectangleValues[1], rectangleValues[2], rectangleValues[3]);

                //get the patrol values for this enemy
                int[] textureNums = getNumbers(EnemyString[(i * 3) + 2].Substring(4));

                Enemy final = new Enemy(r, textureNums[0], ObjectShape.Rectangle);
                if (!EnemyString[(i * 3) + 1].Equals("nopatrol"))
                {
                    int[] patrolValues = getNumbers(EnemyString[(i * 3) + 1].Substring(4));
                    PatrolModel p = new PatrolModel();

                    for (int j = 0; j < patrolValues.Length / 3; j++)
                    {
                        p.addVector(new Vector2((float)patrolValues[j * 3], (float)patrolValues[j * 3 + 1]), patrolValues[j * 3 + 2]);
                    }
                    final.setPatrolModel(p);

                }

                enemies.AddLast(final);
            }

            return enemies;
        }
Ejemplo n.º 2
0
 public void enemyCheck(Enemy e)
 {
     if (e.IsAlive())
     {
         MusicManager.PlaySoundEffect(SoundEffects.deathsound2);
         e.death();
     }
     /*switch (type)
     {
         case ItemType.Sword:
             e.death();
             break;
         case ItemType.Shuriken:
             e.death();
             break;
     }*/
 }