public void ProcessInputs(ProcessInputsEvent _) { var secondaryAnalogStick = this.gamepad_[AnalogStickType.SECONDARY]; var secStickX = secondaryAnalogStick.RawAxes.X; var secStickY = secondaryAnalogStick.RawAxes.Y; var secStickMag = TrigMath.DistanceBetween(0, 0, secStickX, secStickY); if (secStickMag < GamepadConstants.DEADZONE) { secStickMag = 0; } var wasShieldOut = this.isShieldOut_; this.isShieldOut_ = secStickMag > 0; if (this.isShieldOut_) { var secStickDeg = TrigMath.DegreesBetween(0, 0, secStickX, secStickY); var toHandDeg = secStickDeg; var maxHorizontalHandDis = this.playerRigidbody_.Width / 2 + 2; var maxVerticalHandDis = this.playerRigidbody_.Height / 2 + 2; var maxHandDis = FloatMath.Abs( TrigMath.LenDegX(maxHorizontalHandDis, secStickDeg)) + FloatMath.Abs( TrigMath.LenDegY(maxVerticalHandDis, secStickDeg)); var toHandDis = maxHandDis * secStickMag; if (!wasShieldOut) { this.handDis_ = toHandDis; this.handDeg_ = toHandDeg; } else { var accFactor = 3; this.handDis_ += (toHandDis - this.handDis_) / accFactor; this.handDeg_ += TrigMath.DifferenceInDegrees(toHandDeg, this.handDeg_) / accFactor; } } }
public void ProcessInputs(ProcessInputsEvent _) { if (this.whipTimeFraction_ >= 1) { this.isWhipping_ = false; } if (this.isWhipping_) { this.whipTimeFraction_ = MathF.Min(this.whipTimeFraction_ + .1f, 1); return; } var secondaryAnalogStick = this.gamepad_[AnalogStickType.SECONDARY]; var secStickX = secondaryAnalogStick.RawAxes.X; var secStickY = secondaryAnalogStick.RawAxes.Y; var secStickMag = TrigMath.DistanceBetween(0, 0, secStickX, secStickY); if (secStickMag < GamepadConstants.DEADZONE) { secStickMag = 0; } this.isStoring_ = secStickMag > .8f; if (this.isStoring_) { var secStickDeg = TrigMath.DegreesBetween(0, 0, secStickX, secStickY); this.storedWhipTimer_ = 5; this.whipStrength_ = secStickMag; this.whipDeg_ = secStickDeg + 180; } var wasFlicked = this.storedWhipTimer_-- > 0 && secStickMag == 0; if (wasFlicked) { this.isStoring_ = false; this.storedWhipTimer_ = -1; this.isWhipping_ = true; this.whipTimeFraction_ = 0; // TODO: Move this out. this.playerSounds_.PlayWhipSound(); } }
private void ProcessManualInputs_() { var secondaryAnalogStick = this.gamepad_[AnalogStickType.SECONDARY]; var secStickX = secondaryAnalogStick.RawAxes.X; var secStickY = secondaryAnalogStick.RawAxes.Y; var secStickMag = TrigMath.DistanceBetween(0, 0, secStickX, secStickY); if (secStickMag < GamepadConstants.DEADZONE) { secStickMag = 0; } var secStickDeg = TrigMath.DegreesBetween(0, 0, secStickX, secStickY); var isResting = secStickMag == 0; // TODO: Detect arcs? /*if (isResting) { * var xVel = this.playerRigidbody_.XVelocity; * if (xVel != 0) { * var sign = FloatMath.Sign(xVel); * * this.handDis_ = this.maxHandDis_; * * if (this.stateMachine_.State == PlayerState.WALKING) { * this.handDeg_ = 90 - sign * (90 + 45); * this.swordDeg_ = 90 - sign * 45; * } else if (this.stateMachine_.State == PlayerState.RUNNING) { * this.handDeg_ = 90 + sign * (90 + 22); * this.swordDeg_ = 90 + sign * (90 + 22); * } * } * return; * }*/ // Stick moves hands to lift sword. Angle needs to be closer to have // more of an effect. var diffToHeld = TrigMath.DifferenceInDegrees(secStickDeg, this.handDeg_); var normalizedDiffToHeld = MathF.Abs(diffToHeld / 180); var moveFactor = 1 - normalizedDiffToHeld; var diffToTop = TrigMath.DifferenceInDegrees(90, this.handDeg_); var isLifting = FloatMath.Sign(diffToTop) == FloatMath.Sign(diffToHeld); var moveForce = 0f; var liftFactor = secStickMag * MathF.Pow(moveFactor, 5); // 4, 6, 7 if (isLifting) { var liftForce = .6f * diffToHeld * liftFactor; // .5f moveForce = liftForce; } else { var dropFactor = secStickMag; var dropForce = .8f * diffToHeld * dropFactor; moveForce = dropForce; } var initDiffToGround = TrigMath.DifferenceInDegrees(270, this.handDeg_); var gravitationalForce = 3 * FloatMath.Sign(initDiffToGround); var forceOnHands = moveForce + gravitationalForce; // TODO: Use euler method? this.handDegVel_ += forceOnHands; this.handDeg_ += this.handDegVel_; var minAngle = 45; var finalDiffToGround = TrigMath.DifferenceInDegrees(this.handDeg_, 270); if (FloatMath.Abs(finalDiffToGround) < minAngle) { this.handDeg_ = 270 + FloatMath.Sign(finalDiffToGround) * minAngle; if (FloatMath.Abs(this.handDegVel_) > 2) { this.handDegVel_ *= -.5f; } else { this.handDegVel_ = 0; } } // TODO: This line should theoretically not be here?? //this.handDeg_ += diffToHeld * liftFactor; this.handDeg_ %= 360; // TODO: Keep this value when the player lets go of the stick this.handDis_ = 16 * secStickMag; // TODO: Should be based on velocity instead. // If lifting sword, sword angle lags behind. //this.swordDeg_ = this.handDeg_; var swordDegAccFac = 1 / (1 + MathF.Abs(this.handDegVel_)); this.swordDeg_ += TrigMath.DifferenceInDegrees(this.handDeg_, this.swordDeg_) * swordDegAccFac; }