Example #1
0
        private void DrawStick(VirtualStick stick, SpriteBatch spriteBatch, Vector2?debugTextLocation = null)
        {
            if (debugTextLocation.HasValue)
            {
                spriteBatch.DrawString(Drawing.font, $@"======
LOC {stick.StartLocation}
SIZ {stick.AliveZoneSize}
POS {stick.StickPos}
DIR {stick.StickDirection}
MAG {stick.StickMagnitude}
??? {stick.StickPos - stick.StartLocation}
",
                                       debugTextLocation.Value, Color.Black);

                Drawing.DrawStringCentered($"A", new Vector2(stick.StickStartRegion.Left, virtualGamepad.left.StickStartRegion.Top), Color.Black, spriteBatch);
                Drawing.DrawStringCentered($"B", new Vector2(stick.StickStartRegion.Right, virtualGamepad.left.StickStartRegion.Top), Color.Black, spriteBatch);
                Drawing.DrawStringCentered($"C", new Vector2(stick.StickStartRegion.Left, virtualGamepad.left.StickStartRegion.Bottom), Color.Black, spriteBatch);
                Drawing.DrawStringCentered($"D", new Vector2(stick.StickStartRegion.Right, virtualGamepad.left.StickStartRegion.Bottom), Color.Black, spriteBatch);

                Drawing.DrawStringCentered($"><", stick.StickPos, Color.Black, spriteBatch);
            }

            Drawing.DrawStringCentered($"x", stick.StartLocation, Color.Black, spriteBatch);

            var betterDirection = stick.StickDirection * new Vector2(1, -1);
            var pos             = betterDirection * stick.AliveZoneSize + stick.StartLocation;

            Drawing.DrawStringCentered($"@", pos, Color.Black, spriteBatch);
        }
Example #2
0
        // CONSTRUCTOR
        public VirtualGamepad(int width, int height)
        {
            var aliveZoneSize         = System.Math.Min(width, height) * 0.3f;
            var aliveZoneFollowFactor = 1.3f;
            var aliveZoneFollowSpeed  = 0.05f;

            var leftFixedLocation = new Vector2(
                aliveZoneSize * aliveZoneFollowFactor,
                height - aliveZoneSize * aliveZoneFollowFactor);

            var leftStartRegion = new Rectangle(
                0, 100,
                (int)(width * 0.3f), (int)height - 100);

            var rightFixedLocation = new Vector2(
                width - aliveZoneSize * aliveZoneFollowFactor,
                height - aliveZoneSize * aliveZoneFollowFactor);

            var rightStartRegion = new Rectangle(
                (int)(width * 0.5f), 100,
                (int)(width * 0.5f), (int)height - 100);

            left = new VirtualStick
            {
                AliveZoneSize         = aliveZoneSize,
                AliveZoneFollowFactor = aliveZoneFollowFactor,
                AliveZoneFollowSpeed  = aliveZoneFollowSpeed,
                DeadZoneSize          = 5.0f,
                DistFromScreenEdge    = 25.0f,
                StickStartRegion      = leftStartRegion,
                FixedLocation         = leftFixedLocation,
                StickStyle            = TouchStickStyle.Fixed,
                IsLeft = true,
            };

            right = new VirtualStick
            {
                AliveZoneSize         = aliveZoneSize,
                AliveZoneFollowFactor = aliveZoneFollowFactor,
                AliveZoneFollowSpeed  = aliveZoneFollowSpeed,
                DeadZoneSize          = 5.0f,
                DistFromScreenEdge    = 25.0f,
                StickStartRegion      = rightStartRegion,
                FixedLocation         = rightFixedLocation,
                StickStyle            = TouchStickStyle.Fixed,
                IsLeft = false,
            };
        }