コード例 #1
0
ファイル: Map.cs プロジェクト: zhaocy1217/War-Clash
        public Vector3d GetProperPosi(Vector3d v1, Vector3d v2, out bool hitx, out bool hity)
        {
            var  offset = v2 - v1;
            long x = v1.x, y = v1.y;

            hitx = hity = false;
            if (offset.x > 0)
            {
                var testPosi = v1 + new Vector3d(offset.x + FixedMath.Half, 0, 0);
                if (IsInObstacle(testPosi))
                {
                    hitx = true;
                    x    = FixedMath.Floor(testPosi.x) - FixedMath.One / 2 - 1;
                    DLog.Log(x.ToFloat() + " " + v1.ToString() + " " + v2);
                }
            }
            else if (offset.x < 0)
            {
                var testPosi = v1 + new Vector3d(offset.x - FixedMath.Half, 0, 0);
                if (IsInObstacle(testPosi))
                {
                    hitx = true;
                    x    = FixedMath.Floor(testPosi.x) + FixedMath.One / 2 + 1;
                }
            }
            if (offset.y > 0)
            {
                var testPosi = v1 + new Vector3d(0, offset.y + FixedMath.One * 2, 0);
                if (IsInObstacle(testPosi))
                {
                    hity = true;
                    y    = FixedMath.Floor(testPosi.y) - FixedMath.One * 2 - 1;
                }
            }
            else if (offset.y < 0)
            {
                var testPosi = v1 + new Vector3d(0, offset.y, 0);
                if (IsInObstacle(testPosi))
                {
                    hity = true;
                    y    = FixedMath.Floor(testPosi.y) + FixedMath.One + 1;
                }
            }
            Vector3d v = new Vector3d(hitx? x : v2.x, hity?y:v2.y, 0);

            return(v);
        }