コード例 #1
0
        private void HandleCrosshairEvents(object sender, CrosshairArgs crosshairArgs)
        {
            _crosshairPos = crosshairArgs.Data.Position;

            //get angle between player's gun and a crosshair
            var rotation = (float)Math.Atan2(_crosshairPos.Y - GunPoint.Y, _crosshairPos.X - GunPoint.X);

            //change players direction if necessary
            UpdateDirection(ref rotation);

            //wrap angle and apply boundaries
            rotation = MathHelper.WrapAngle(rotation);
            rotation = MathHelper.Clamp(rotation, -MathHelper.Pi / 3, MathHelper.Pi / 4);

            _gunRotation = rotation;

            _stationaryGunPoint = Vector2Util.RotateAboutOrigin(_stationaryGunPoint, _topOrigin, (float)_gunRotation);

            GunPoint = _stationaryGunPoint;
        }