Пример #1
0
        /// <summary>
        /// 向目标点移动,当前有误差,移动时会来回抖动
        /// </summary>
        /// <param name="targetPos"></param>
        public void MoveToPos(IntVector2 targetPos)
        {
            if (targetPos == mUnit.Position)
            {
                return;
            }
            IntVector2 offset  = targetPos - mUnit.Position;
            int        speed   = mUnit.GetAttribute(FighterAttributeType.Speed);
            IntVector2 newPos  = targetPos;
            IntVector2 fromPos = mUnit.Position;

            if (offset.SqrMagnitude > speed * speed)
            {
                short angle = (short)ATanFuncTable.GetAngle(offset.x, offset.y);

                IntegerFloat cosValue = CosFuncByTable.CosAngle(angle);
                IntegerFloat sinValue = SinFuncByTable.SinAngle(angle);
                newPos.x = mUnit.Position.x + (cosValue * speed).ToInt();
                newPos.y = mUnit.Position.y + (sinValue * speed).ToInt();
                newPos   = LimitPos(newPos);
                if (mUnit.ID == 6)
                {
                    Logger.LogError("MoveToPos " + angle + "  offset " + (newPos - fromPos).ToString());
                }
            }
            mUnit.Position = newPos;
            OnPosChanged(fromPos);
        }
Пример #2
0
        public static Matrix3x3 Create(short angle, IntVector2 offset)
        {
            IntegerFloat cosFloat = CosFuncByTable.CosAngle(angle);
            IntegerFloat sinFloat = SinFuncByTable.SinAngle(angle);

            Matrix3x3 ma3x3 = Matrix3x3.Identity;

            ma3x3.m00 = cosFloat;
            ma3x3.m10 = sinFloat.NegativeValue();
            ma3x3.m01 = sinFloat;
            ma3x3.m11 = cosFloat;
            ma3x3.m20 = new IntegerFloat(offset.x);
            ma3x3.m21 = new IntegerFloat(offset.y);
            return(ma3x3);
        }