-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #460 from agateau/unified-digital-steering
Unify digital steering
- Loading branch information
Showing
5 changed files
with
27 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
kind: Changed | ||
body: Steering is now smoother, especially on Android. | ||
time: 2024-08-26T08:02:22.121774707+02:00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2019 Aurélien Gâteau <[email protected]> | ||
* Copyright 2024 Compl Yue | ||
* | ||
* This file is part of Pixel Wheels. | ||
* | ||
|
@@ -19,18 +19,21 @@ | |
package com.agateau.pixelwheels.gameinput; | ||
|
||
import com.agateau.pixelwheels.GamePlay; | ||
import com.agateau.pixelwheels.racescreen.HudButton; | ||
import com.badlogic.gdx.math.MathUtils; | ||
|
||
class TouchInputUtils { | ||
static float applyDirectionInput(HudButton leftButton, HudButton rightButton, float direction) { | ||
if (leftButton.isPressed()) { | ||
direction += GamePlay.instance.steeringStep; | ||
} else if (rightButton.isPressed()) { | ||
direction -= GamePlay.instance.steeringStep; | ||
public class DigitalSteering { | ||
private float mRawDirection = 0; | ||
|
||
public float steer(boolean left, boolean right) { | ||
if (left == right) { | ||
// Either both left & right are pressed or none of them are | ||
mRawDirection *= 0.4; | ||
} else if (left) { | ||
mRawDirection += GamePlay.instance.steeringStep; | ||
} else { | ||
direction = 0; | ||
mRawDirection -= GamePlay.instance.steeringStep; | ||
} | ||
return MathUtils.clamp(direction, -1, 1); | ||
mRawDirection = MathUtils.clamp(mRawDirection, -1, 1); | ||
return mRawDirection * mRawDirection * Math.signum(mRawDirection); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters