Esempio n. 1
0
        void _controller_KeyControlEngaged(int control)
        {
            KeyMappings.PolarMouseGameControls c = (KeyMappings.PolarMouseGameControls)control;
            var     player         = (Player)ActiveMap.Player;
            Vector2 mouseDirection = (new Vector2(Mouse.GetState().X, Mouse.GetState().Y)) - player.Position;
            var     rad            = mouseDirection.Length();

            mouseDirection.Normalize();

            switch (c)
            {
            case KeyMappings.PolarMouseGameControls.MoveIn:
                PhysicsManager.AddInstantaneousForce(new InstantaneousForce((IRigidBody)player, player.Mass * player.SpeedScale * mouseDirection));
                break;

            case KeyMappings.PolarMouseGameControls.MoveOut:
                PhysicsManager.AddInstantaneousForce(new InstantaneousForce((IRigidBody)player, -player.Mass * player.SpeedScale * mouseDirection));
                break;

            case KeyMappings.PolarMouseGameControls.MoveClockwise:
                var tangentCW = mouseDirection.RotateInPlace(-(float)Math.PI / 2);
                var tangVel   = Vector2.Dot(player.Velocity, tangentCW);
                player.Velocity = tangentCW * tangVel;
                PhysicsManager.AddInstantaneousForce(new InstantaneousForce((IRigidBody)player, player.Mass * player.SpeedScale * tangentCW));
                break;

            case KeyMappings.PolarMouseGameControls.MoveCounterClockwise:
                var tangentCCW = mouseDirection.RotateInPlace((float)Math.PI / 2);
                var tangVelCCW = Vector2.Dot(player.Velocity, tangentCCW);
                player.Velocity = tangentCCW * tangVelCCW;
                PhysicsManager.AddInstantaneousForce(new InstantaneousForce((IRigidBody)player, player.Mass * player.SpeedScale * tangentCCW));
                break;
            }
        }