Beispiel #1
0
        public static Movement GetMovement(float rotation)
        {
            rotation = SharpMathHelper.Loop(0, 360, rotation);

            const float HalfCoverage = 45;

            if (TestDirection(rotation, -HalfCoverage, HalfCoverage) || rotation > 360 - HalfCoverage)
            {
                // Right
                return(Movement.Right);
            }

            if (TestDirection(rotation, HalfCoverage, HalfCoverage * 3f))
            {
                // Right
                return(Movement.Down);
            }

            if (TestDirection(rotation, HalfCoverage * 3f, HalfCoverage * 5f))
            {
                // Right
                return(Movement.Left);
            }

            if (TestDirection(rotation, HalfCoverage * 5f, HalfCoverage * 7f))
            {
                // Right
                return(Movement.Top);
            }

            return(Movement.None);
        }
Beispiel #2
0
        private static bool TestDirection(float rotation, float start, float end)
        {
            bool TestDirection() => start < rotation && rotation <= end;

            if (TestDirection())
            {
                return(true);
            }

            if (start < 0)
            {
                start = SharpMathHelper.Loop(0, 360, start);
            }

            if (end < 0)
            {
                end = SharpMathHelper.Loop(0, 360, start);
            }

            return(TestDirection());
        }