Example #1
0
 protected virtual bool CanMove2Neighbour(PillarSetting setting, ushort curH, ushort curMaxH,
                                          ushort neighbourH, ushort neighbourMaxH)
 {
     //jumpable
     if (Math.Abs(curH - neighbourH) * setting.heightPerGrade > setting.jumpableHeight)
     {
         return(false);
     }
     //gap like this, cant go
     // _____|
     //      _______
     //      |
     // _____|
     if (neighbourH > curH)
     {
         float gapHeight = (curMaxH - neighbourH) * setting.heightPerGrade;
         if (gapHeight >= setting.boundHeight)
         {
             return(true);
         }
     }
     else
     {
         if (neighbourMaxH > curH)
         {
             float gapHeight = (neighbourMaxH - curH) * setting.heightPerGrade;
             if (gapHeight >= setting.boundHeight)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Example #2
0
        public static bool SaveData(string path, PillarSetting setting, QuadTreeBase[] trees)
        {
            if (File.Exists(path))
            {
                File.Delete(path);
            }
            FileStream stream = File.Open(path, FileMode.Create);

            byte[] stbuff = setting.ToArray();
            stream.Write(stbuff, 0, stbuff.Length);
            //trees
            byte[] bRootLeafBuff = new byte[1] {
                1 << 4
            };
            for (int x = 0; x < setting.maxX; ++x)
            {
                for (int z = 0; z < setting.maxZ; ++z)
                {
                    QuadTreeBase subTree = trees[x * setting.maxZ + z];
                    if (subTree is QuadTreeLeafSerializable)
                    {
                        stream.Write(bRootLeafBuff, 0, 1);
                        QuadTreeLeafSerializable leaf = (QuadTreeLeafSerializable)subTree;
                        leaf.Serialize(stream);
                    }
                    else
                    {
                        QuadTreeNodeSerializable node = (QuadTreeNodeSerializable)subTree;
                        node.Serialize(stream);
                    }
                }
            }
            stream.Close();
            MPLog.Log("create data successed!");
            return(true);
        }
Example #3
0
        public static float heightVal(PillarSetting setting, uint val)
        {
            ushort grade = (ushort)(val >> 48);

            return(setting.heightValRange[0] + grade * setting.heightPerGrade);
        }