Exemple #1
0
 /// <summary>
 /// Simple constructor of a motionless platform. 
 /// </summary>
 /// <param name="rect">Position and size of the platform.</param>
 /// <param name="Velocity">Vector2: initial velocity of the platform.</param>
 /// <param name="tex">Texture2D: texture for the platform.</param>
 /// <param name="Shape">ObjectShape: shape of the platform.</param>
 /// <param name="IsHazardous">boolean: Platform is hazardous.</param>
 /// <param name="gravity">boolen: Platform is affected by gravity.</param>
 public Platform(Rectangle rect, int textureIndex, ObjectShape Shape, bool IsHazardous, bool gravity)
     : base(rect, textureArray[textureIndex], Shape)
 {
     isHazardous = IsHazardous;
     hasGravity = gravity;
     base.isTiled = true;
     patrol = null;
     suspendRopes = new List<SuspendRope>();
 }
        public void PatrolModel_CurrentVelocityTest()
        {
            PatrolModel p = new PatrolModel();

            Vector2 a = new Vector2(2.0f, 5.0f);
            Vector2 b = new Vector2(3.0f, -7.0f);

            p.addVector(a, 5);
            p.addVector(b, 12);

            Assert.Equal(p.getCurrentVector(3).Equals(a), true); // Make sure it picks the first item
            Assert.Equal(p.getCurrentVector(9).Equals(b), true); // Make sure it picks the second item
            Assert.Equal(p.getCurrentVector(20).Equals(a), true); // Make sure it picks the first item again
        }
 public void SetPatrol(PatrolModel newPatrol)
 {
     patrol = newPatrol;
 }
        /// <summary>
        /// Read all the platform objects from the currentReadTarget file
        /// </summary>
        /// <returns></returns>
        public static LinkedList<Platform> readPlatforms()
        {
            const int platformObjSize = 8;
            string content;

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

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

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

            LinkedList<Platform> platforms = new LinkedList<Platform>();

            String[] PlatformString = CleanUp(content);
            for (int i = 0; i < PlatformString.Length / platformObjSize; i++)
            {
                //create the rectangle for this platform
                int[] rectangleValues = getNumbers(PlatformString[i*platformObjSize].Substring(4));
                Rectangle r = new Rectangle(rectangleValues[0], rectangleValues[1], rectangleValues[2], rectangleValues[3]);

                //determine whether or not this platform has gravitic properties
                bool hasGravity = PlatformString[i*platformObjSize + 1].Equals("yesgravity", StringComparison.CurrentCultureIgnoreCase);

                // check hazard status
                bool isHazardous = PlatformString[i * platformObjSize + 3].Equals("hazardous", StringComparison.CurrentCultureIgnoreCase);
                bool goThrough = PlatformString[i*platformObjSize+6].Equals("through", StringComparison.CurrentCultureIgnoreCase);
                bool isTiled = PlatformString[i*platformObjSize+7].Equals("tile", StringComparison.CurrentCultureIgnoreCase);
                bool isAnimated = PlatformString[i*platformObjSize+4].Contains("hplatform");
                // parse texture
                string texName = "Interactive/" + PlatformString[i * platformObjSize + 4];

                Platform final = new Platform(r, texName, isHazardous, isAnimated, hasGravity, goThrough, isTiled);

                //get the patrol values for this platform (out of parse order because it has to be created after the platform object)
                if (!PlatformString[i * platformObjSize + 2].Equals("nopatrol"))
                {
                    int[] patrolValues = getNumbers(PlatformString[i * platformObjSize + 2].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.SetPatrol(p);

                }

                // read trigger
                if (!PlatformString[i * platformObjSize + 5].Equals("notrigger"))
                {
                    int [] triggerValues = getNumbers(PlatformString[i*platformObjSize+5].Substring(8));
                    for (int j = 0; j < triggerValues.Length; j+=4)
                    {
                        final.addTrigger(new Trigger(new Rectangle(triggerValues[j],triggerValues[j+1],triggerValues[j+2],triggerValues[j+3]), final));
                    }
                }
                platforms.AddFirst(final);
            }
            return platforms;
        }
        /// <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;
        }
Exemple #6
0
 /// <summary>
 /// Simple constructor of a motionless platform. 
 /// </summary>
 /// <param name="rect">Position and size of the platform.</param>
 /// <param name="Velocity">Vector2: initial velocity of the platform.</param>
 /// <param name="tex">Texture2D: texture for the platform.</param>
 /// <param name="Shape">ObjectShape: shape of the platform.</param>
 /// <param name="IsHazardous">boolean: Platform is hazardous.</param>
 /// <param name="gravity">boolen: Platform is affected by gravity.</param>
 public Platform(Rectangle rect, Texture2D drawTex, ObjectShape Shape, bool IsHazardous, bool gravity)
     : base(rect, drawTex, Shape)
 {
     isHazardous = IsHazardous;
     hasGravity = gravity;
     patrol = null;
     suspendRopes = new List<SuspendRope>();
 }
Exemple #7
0
 public void setPatrolModel(PatrolModel model)
 {
     patrol = model;
 }