예제 #1
0
        private void UpdateFromGamepad(Transform referenceObj, GamepadInput gamepad)
        {
            float referenceAngle = (referenceObj != null) ? referenceObj.Angle : 0.0f;

            if (gamepad.LeftThumbstick.Length > 0.25f)
            {
                float mappedLength = (gamepad.LeftThumbstick.Length - 0.25f) / 0.75f;
                this.controlMovement = gamepad.LeftThumbstick * mappedLength / gamepad.LeftThumbstick.Length;
            }
            else
            {
                this.controlMovement = Vector2.Zero;
            }

            if (gamepad.RightThumbstick.Length > 0.5f)
            {
                this.controlLookAngle = gamepad.RightThumbstick.Angle;
                this.controlLookSpeed = (gamepad.RightThumbstick.Length - 0.5f) / 0.5f;
            }
            else if (gamepad.LeftThumbstick.Length > 0.25f)
            {
                this.controlLookAngle = gamepad.LeftThumbstick.Angle;
                this.controlLookSpeed = (gamepad.LeftThumbstick.Length - 0.25f) / 0.75f;
            }

            bool targetAimed = MathF.CircularDist(referenceAngle, this.controlLookAngle) < MathF.RadAngle1 * 10;

            this.controlFireWeapon =
                (targetAimed && gamepad.RightThumbstick.Length > 0.9f) ||
                gamepad[GamepadAxis.RightTrigger] > 0.5f ||
                gamepad[GamepadButton.RightShoulder] ||
                gamepad[GamepadButton.A];
            this.controlQuit  = gamepad.ButtonHit(GamepadButton.Back);
            this.controlStart = gamepad.ButtonHit(GamepadButton.Start);
        }
예제 #2
0
        void ICmpUpdatable.OnUpdate()
        {
            // Allow the user to input where to go
            if (DualityApp.Keyboard.KeyHit(Key.Number1))
            {
                this.targetInside = 1.0f;
            }
            if (DualityApp.Keyboard.KeyHit(Key.Number2))
            {
                this.targetInside = 0.0f;
            }

            // Is there a Gamepad we can use?
            GamepadInput gamepad = DualityApp.Gamepads.FirstOrDefault(g => g.IsAvailable);

            if (gamepad != null)
            {
                if (gamepad.ButtonHit(GamepadButton.A))
                {
                    this.targetInside = 1.0f;
                }
                if (gamepad.ButtonHit(GamepadButton.B))
                {
                    this.targetInside = 0.0f;
                }
            }

            // Walk around
            this.inside += (this.targetInside - this.inside) * 0.01f * Time.TimeMult;

            // Make sure we're playing what we're supposed to
            this.SyncSounds(this.soundsInside, ref this.playingInside);
            this.SyncSounds(this.soundsOutside, ref this.playingOutside);

            // Apply settings based on where we are
            for (int i = 0; i < this.playingInside.Length; i++)
            {
                if (this.playingInside[i] == null)
                {
                    continue;
                }
                this.playingInside[i].Volume  = MathF.Lerp(0.1f, 1.0f, this.inside);
                this.playingInside[i].Lowpass = MathF.Lerp(0.1f, 1.0f, this.inside);
            }
            for (int i = 0; i < this.playingOutside.Length; i++)
            {
                if (this.playingOutside[i] == null)
                {
                    continue;
                }
                this.playingOutside[i].Volume  = MathF.Lerp(1.0f, 0.5f, this.inside);
                this.playingOutside[i].Lowpass = MathF.Lerp(1.0f, 0.1f, this.inside);
            }
        }
        void ICmpUpdatable.OnUpdate()
        {
            // Prepare a list of camera controllers, if we don't already have one
            if (this.cameraControllers == null)
            {
                this.cameraControllers = new List <ICameraController>();

                // Use Reflection to get a list of all ICameraController classes
                TypeInfo[] availableCameraControllerTypes = DualityApp.GetAvailDualityTypes(typeof(ICameraController)).ToArray();
                foreach (TypeInfo camControllerType in availableCameraControllerTypes)
                {
                    // Create an instance of each class
                    ICameraController camController = camControllerType.CreateInstanceOf() as ICameraController;
                    if (camController != null)
                    {
                        this.cameraControllers.Add(camController);
                    }
                }
            }

            // Allow the user to select which camera controller to use
            if (DualityApp.Keyboard.KeyHit(Key.Number1))
            {
                this.ActiveCameraController--;
            }
            if (DualityApp.Keyboard.KeyHit(Key.Number2))
            {
                this.ActiveCameraController++;
            }
            if (DualityApp.Keyboard.KeyHit(Key.M))
            {
                this.movementHistoryActive = !this.movementHistoryActive;
            }

            // Is there a Gamepad we can use?
            GamepadInput gamepad = DualityApp.Gamepads.FirstOrDefault(g => g.IsAvailable);

            if (gamepad != null)
            {
                if (gamepad.ButtonHit(GamepadButton.A))
                {
                    this.ActiveCameraController--;
                }
                if (gamepad.ButtonHit(GamepadButton.B))
                {
                    this.ActiveCameraController++;
                }
                if (gamepad.ButtonHit(GamepadButton.X))
                {
                    this.movementHistoryActive = !this.movementHistoryActive;
                }
            }

            // Every 100 ms, draw one visual log entry to document movement
            if (this.movementHistoryActive)
            {
                this.movementHistoryTimer += Time.MsPFMult * Time.TimeMult;
                if (this.movementHistoryTimer > 100.0f)
                {
                    this.movementHistoryTimer -= 100.0f;
                    Vector2 targetPos = this.targetObj.Transform.Pos.Xy;
                    Vector2 cameraPos = this.mainCameraObj.Transform.Pos.Xy;
                    VisualLog.Default.DrawPoint(
                        targetPos.X,
                        targetPos.Y,
                        0.0f)
                    .WithColor(new ColorRgba(255, 128, 0))
                    .KeepAlive(3000.0f);
                    VisualLog.Default.DrawPoint(
                        cameraPos.X,
                        cameraPos.Y,
                        0.0f)
                    .WithColor(new ColorRgba(0, 255, 0))
                    .KeepAlive(3000.0f);
                }
            }
        }
예제 #4
0
		private void UpdateFromGamepad(Transform referenceObj, GamepadInput gamepad)
		{
			float referenceAngle = (referenceObj != null) ? referenceObj.Angle : 0.0f;

			if (gamepad.LeftThumbstick.Length > 0.25f)
			{
				float mappedLength = (gamepad.LeftThumbstick.Length - 0.25f) / 0.75f;
				this.controlMovement = gamepad.LeftThumbstick * mappedLength / gamepad.LeftThumbstick.Length;
			}
			else
			{
				this.controlMovement = Vector2.Zero;
			}

			if (gamepad.RightThumbstick.Length > 0.5f)
			{
				this.controlLookAngle = gamepad.RightThumbstick.Angle;
				this.controlLookSpeed = (gamepad.RightThumbstick.Length - 0.5f) / 0.5f;
			}
			else if (gamepad.LeftThumbstick.Length > 0.25f)
			{
				this.controlLookAngle = gamepad.LeftThumbstick.Angle;
				this.controlLookSpeed = (gamepad.LeftThumbstick.Length - 0.25f) / 0.75f;
			}

			bool targetAimed = MathF.CircularDist(referenceAngle, this.controlLookAngle) < MathF.RadAngle1 * 10;
			this.controlFireWeapon = 
				(targetAimed && gamepad.RightThumbstick.Length > 0.9f) ||
				gamepad[GamepadAxis.RightTrigger] > 0.5f ||
				gamepad[GamepadButton.RightShoulder] ||
				gamepad[GamepadButton.A];
			this.controlQuit = gamepad.ButtonHit(GamepadButton.Back);
			this.controlStart = gamepad.ButtonHit(GamepadButton.Start);
		}
예제 #5
0
파일: Player.cs 프로젝트: ilexp/bmj2017-12
        void ICmpUpdatable.OnUpdate()
        {
            GamepadInput gamepad = DualityApp.Gamepads[0];

            Vector2 moveDir   = gamepad.LeftThumbstick.Normalized;
            float   moveSpeed = MathF.Clamp((gamepad.LeftThumbstick.Length - 0.3f) / 0.7f, 0.0f, 1.0f);

            Vector2 lookDir       = gamepad.RightThumbstick.Normalized;
            float   lookIntensity = MathF.Clamp((gamepad.RightThumbstick.Length - 0.3f) / 0.7f, 0.0f, 1.0f);

            this.controlTarget.ThrusterActivity = moveDir * moveSpeed;
            this.controlTarget.RotateActivity   = lookDir * lookIntensity;

            if (gamepad.RightTrigger > 0.5f)
            {
                this.controlTarget.FireWeapons();
            }

            if (gamepad.ButtonHit(GamepadButton.Start))
            {
                if (musicInstance != null && !musicInstance.Disposed)
                {
                    musicInstance.Lowpass = 1.0f;
                }
                Scene.Reload();
            }
            if (gamepad.ButtonHit(GamepadButton.Back))
            {
                DualityApp.Terminate();
            }

            if (musicInstance == null || musicInstance.Disposed)
            {
                musicInstance        = DualityApp.Sound.PlaySound(this.backgroundMusic);
                musicInstance.Looped = true;
                musicInstance.Volume = 0.4f;
                musicInstance.BeginFadeIn(5.0f);
            }
            else
            {
                float targetLowPass = 1.0f;
                if (this.controlTarget == null || this.controlTarget.Disposed)
                {
                    targetLowPass = 0.05f;
                }
                else
                {
                    targetLowPass = 1.0f;
                }

                float changeDir = MathF.Sign(targetLowPass - musicInstance.Lowpass);
                float changeAbs = MathF.Abs(targetLowPass - musicInstance.Lowpass);
                if (changeAbs <= 0.01f)
                {
                    musicInstance.Lowpass = targetLowPass;
                }
                else
                {
                    musicInstance.Lowpass += changeDir * Time.TimeMult * Time.SPFMult / 8.0f;
                }
            }
        }