예제 #1
0
        //path takes you to "\world\levels\"
        public static level[] LoadLevels(ContentManager content)
        {
            StreamReader sr;                              //sr is the obj created to help us read file contents.
            #region FindNumberOfLevels
            int i_levelCount = 0; bool b_invalid = false; //these vars are created to help find the number of levels in the dir.

            while (!b_invalid)
            {
                #region CheckValidity
                try
                {
                    sr = new StreamReader(content.RootDirectory + "/world/levels/" + i_levelCount.ToString() + ".alvl");
                }
                catch
                {
                    b_invalid = true;
                }
                #endregion
                #region KeepCount
                if (!b_invalid)
                {
                    i_levelCount++;
                }
                #endregion
            }
            #endregion

            level[] l_out = new level[i_levelCount];      //variable is created that is large enough to hold the world

            #region LoadLevels
            for (int i = 0; i != i_levelCount; i++)
            {
                sr = new StreamReader(BasePath+ "/world/levels/" + i.ToString() + ".alvl");
                //try
                //{
                    l_out[i].name = sr.ReadLine();
                    l_out[i].props = new prop[Convert.ToInt32(sr.ReadLine())];
                    for (int j = 0; j != l_out[i].props.Length; j++)
                    {
                        l_out[i].props[j].name = sr.ReadLine();
                        l_out[i].props[j].texture_path = sr.ReadLine();
                        l_out[i].props[j].texture = content.Load<Texture2D>(l_out[i].props[j].texture_path);
                        l_out[i].props[j].X = Convert.ToInt32(Convert.ToInt32(sr.ReadLine()));// * vars.globalScale);
                        l_out[i].props[j].Y = Convert.ToInt32(Convert.ToInt32(sr.ReadLine()));// * vars.globalScale);
                        l_out[i].props[j].angle = Convert.ToSingle(sr.ReadLine());
                        l_out[i].props[j].scale = Convert.ToSingle(sr.ReadLine());
                    }
                //}
                //catch { l_out[i].props = new prop[0]; }
                try
                {
                    l_out[i].regions = new region[Convert.ToUInt32(sr.ReadLine())];
                    for (int j = 0; j != l_out[i].regions.Length; j++)
                    {
                        l_out[i].regions[j].name = sr.ReadLine();
                        #region GetType
                        string temp = sr.ReadLine();
                        if (temp == "floor")
                        {
                            l_out[i].regions[j].type = regionType.floor;
                        }
                        if (temp == "building")
                        {
                            l_out[i].regions[j].type = regionType.building;
                        }
                        if (temp == "portal")
                        {
                            l_out[i].regions[j].type = regionType.portal;
                        }
                        #endregion
                        l_out[i].regions[j].corners = new Vector2[4];

                        #region DealWithCornerShit
                        Vector2 smallest = Vector2.Zero;
                        Vector2 largest = Vector2.Zero;
                        for (int k = 0; k != 4; k++)
                        {
                            l_out[i].regions[j].corners[k] = new Vector2(Convert.ToSingle(sr.ReadLine()), Convert.ToSingle(sr.ReadLine()));
                            if (l_out[i].regions[j].corners[k].X <= smallest.X || smallest.X == 0)
                            {
                                if (l_out[i].regions[j].corners[k].Y <= smallest.Y || smallest.Y == 0)
                                {
                                    smallest = l_out[i].regions[j].corners[k];
                                }
                            }
                            if (l_out[i].regions[j].corners[k].X >= largest.X || largest.X == 0)
                            {
                                if (l_out[i].regions[j].corners[k].Y >= largest.Y || largest.Y == 0)
                                {
                                    largest = l_out[i].regions[j].corners[k];
                                }
                            }
                        }
                        l_out[i].regions[j].corners = new Vector2[2];
                        l_out[i].regions[j].corners[0] = smallest;
                        l_out[i].regions[j].corners[1] = largest;
                        #endregion
                        l_out[i].regions[j].special = sr.ReadLine();
                        l_out[i].regions[j].toLevel = sr.ReadLine();

                    }
                }
                catch { l_out[i].regions = new region[0]; }
                l_out[i].row = Convert.ToInt32 (sr.ReadLine());
                l_out[i].column = Convert.ToInt32(sr.ReadLine());
                l_out[i].indoor = Convert.ToBoolean(sr.ReadLine());
            }
            #endregion

            return l_out;
        }
예제 #2
0
 public static int findFloor(level lvl)
 {
     int tag = -1;
     if (lvl.regions[0].type == regionType.floor)
     {
         tag = 0;
     }
     else
     {
         for (int i = 0; i != lvl.regions.Length; i++)
         {
             if (lvl.regions[i].type == regionType.floor)
             {
                 tag = i;
             }
         }
     }
     return tag;
 }
예제 #3
0
        public static level removeCharacter(level l, string name)
        {
            int Char = findNPC(name) ;
            character[] lower = new character[Char];
            character[] upper = new character[l.char_living.Length - (Char + 1)];

            for (int i = 0; i != l.char_living.Length; i++)
            {
                if (i < Char)
                {
                    lower[i] = l.char_living[i];
                }
                if (i > Char)
                {
                    upper[i - (Char + 1)] = l.char_living[i];
                }
            }
            l.char_living = new character[l.char_living.Length - 1];

            for (int i = 0; i != l.char_living.Length; i++)
            {
                if (i < lower.Length)
                {
                    l.char_living[i] = lower[i];
                }
                else
                {
                    l.char_living[i] = upper[i - lower.Length];
                }
            }

            return l;
        }
예제 #4
0
 public static void draw(SpriteBatch sb, Vector2 camPos, level current)
 {
     sb.Begin();
     //shaders.DesaturateBegin();
         for (int i = 0; i != current.props.Length; i++)
         {
             sb.Draw(current.props[i].texture,
                     (new Vector2(current.props[i].X, current.props[i].Y) - camPos)*camera.scale+(Game1.v_resolution/2),
                     null,
                     Color.White,
                     0,
                     new Vector2(current.props[i].texture.Width / 2, current.props[i].texture.Height / 2),
                     camera.scale,
                     SpriteEffects.None,
                     0);
         }
         //shaders.DesaturateEnd();
     sb.End();
 }