-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unified digital steering for smoother control #435
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2024 Compl Yue | ||
* | ||
* This file is part of Pixel Wheels. | ||
* | ||
* Pixel Wheels is free software: you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License as published by the Free | ||
* Software Foundation, either version 3 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.agateau.pixelwheels.gameinput; | ||
|
||
import com.agateau.pixelwheels.GamePlay; | ||
import com.badlogic.gdx.math.MathUtils; | ||
|
||
public class DigitalSteering { | ||
|
||
private float mRawDirection = 0; | ||
|
||
public float direction() { | ||
// use parabolic curve to smooth the ctrl | ||
return mRawDirection * mRawDirection * Math.signum(mRawDirection); | ||
} | ||
|
||
public float steer(boolean left, boolean right) { | ||
if (left && right) { | ||
// both left and right, full steer in original direction. | ||
// currently there are 2 folds to do it this way: | ||
// | ||
// * with two-sides button control, I seldom purposfully do a | ||
// straight braking/slow-down, almost always meant to reverse at | ||
// a direction, then I always press the other button too quickly | ||
// after pressed the 1st button, making it reverse almost | ||
// straightly, the treatment here meant to make that op easy. | ||
// also there are times I'd mean slow-down & turn-hard, this case | ||
// works pretty well like a trick - just release the other button | ||
// after the speed is sufficiently slowed down, and keep holding | ||
// the 1st button to keep hard turning toward the original direction | ||
// using full steering during the whole course. | ||
// | ||
// * for kbd control (maybe also pie-touch), this happens to enable | ||
// a hard-turning trick - the player first press the button for the | ||
// target direction, immediately followed by a press on the other | ||
// button, it'll skip the gradually increasing steering output, and | ||
// do an instant, full steering. | ||
mRawDirection = Math.signum(mRawDirection); | ||
} else if (left) { | ||
mRawDirection += GamePlay.instance.steeringStep; | ||
} else if (right) { | ||
mRawDirection -= GamePlay.instance.steeringStep; | ||
} else { | ||
mRawDirection *= 0.4; | ||
} | ||
mRawDirection = MathUtils.clamp(mRawDirection, -1, 1); | ||
return this.direction(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
/** Handle input using buttons on the sides */ | ||
public class SidesTouchInputHandler implements GameInputHandler { | ||
private final GameInput mInput = new GameInput(); | ||
private final DigitalSteering mSteer = new DigitalSteering(); | ||
private HudButton mLeftButton, mRightButton, mBonusButton; | ||
|
||
public static class Factory implements GameInputHandlerFactory { | ||
|
@@ -61,11 +62,7 @@ public Array<GameInputHandler> getAllHandlers() { | |
public GameInput getGameInput() { | ||
mInput.braking = isBraking(); | ||
mInput.accelerating = !mInput.braking; | ||
if (!mInput.braking) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you need to keep the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this meant to propagate the player action to |
||
mInput.direction = | ||
TouchInputUtils.applyDirectionInput( | ||
mLeftButton, mRightButton, mInput.direction); | ||
} | ||
mInput.direction = mSteer.steer(mLeftButton.isPressed(), mRightButton.isPressed()); | ||
mInput.triggeringBonus = mBonusButton.isPressed(); | ||
return mInput; | ||
} | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This comment is for line 2 but GitHub won't let me comment on it)
You should change the copyright year and owner of this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.