Added return to menu functionality for kb/ kbm/ gamepad
This commit is contained in:
1 parent
fa5c8b4f60
commit
f25076b904
5 files changed
+45
-4
No files matched your search
+5
-2
@@ -16,8 +16,10 @@ export const Controls = {
|
||||
boost: 'boost',
|
||||
shoot: 'shoot',
|
||||
slow: 'slow',
|
||||
reset: 'reset'
|
||||
reset: 'reset',
|
||||
escape: 'escape'
|
||||
}
|
||||
|
||||
function App() {
|
||||
const map = useMemo(
|
||||
() => [
|
||||
@@ -28,7 +30,8 @@ function App() {
|
||||
{ name: Controls.jump, keys: ['Space'] },
|
||||
{ name: Controls.slow, keys: ['Shift'] },
|
||||
{ name: Controls.shoot, keys: ['KeyE', 'Click'] },
|
||||
{ name: Controls.reset, keys: ['KeyR'] }
|
||||
{ name: Controls.reset, keys: ['KeyR'] },
|
||||
{ name: Controls.escape, keys: ['Escape']}
|
||||
],
|
||||
[]
|
||||
)
|
||||
|
||||
@@ -40,6 +40,7 @@ export const PlayerController = ({
|
||||
const jumpPressed = useKeyboardControls((state) => state[Controls.jump]);
|
||||
const shootPressed = useKeyboardControls((state) => state[Controls.shoot]);
|
||||
const resetPressed = useKeyboardControls((state) => state[Controls.reset]);
|
||||
const escPressed = useKeyboardControls((state) => state[Controls.escape]);
|
||||
|
||||
const [isOnGround, setIsOnGround] = useState(false);
|
||||
const body = useRef();
|
||||
@@ -114,6 +115,10 @@ export const PlayerController = ({
|
||||
0,
|
||||
-Math.cos(kartRotation)
|
||||
);
|
||||
|
||||
if (escPressed) {
|
||||
actions.setGameStarted(false);
|
||||
}
|
||||
|
||||
if (leftPressed && currentSpeed > 0) {
|
||||
steeringAngle = currentSteeringSpeed;
|
||||
|
||||
@@ -86,7 +86,7 @@ export const PlayerControllerGamepad = ({
|
||||
|
||||
const { actions, shouldSlowDown, item, bananas, coins, id, controls } = useStore();
|
||||
const slowDownDuration = useRef(1500);
|
||||
const { buttonA, buttonB, RB, LB, joystick, select} = useGamepad();
|
||||
const { buttonA, buttonB, RB, LB, joystick, select, start } = useGamepad();
|
||||
|
||||
useFrame(({ pointer, clock }, delta) => {
|
||||
if (player.id !== id) return;
|
||||
@@ -110,6 +110,10 @@ export const PlayerControllerGamepad = ({
|
||||
-Math.cos(kartRotation)
|
||||
);
|
||||
|
||||
if (start) {
|
||||
actions.setGameStarted(false);
|
||||
}
|
||||
|
||||
// mouse steering
|
||||
|
||||
if (!driftLeft.current && !driftRight.current) {
|
||||
|
||||
@@ -40,6 +40,7 @@ export const PlayerControllerKeyboard = ({
|
||||
const jumpPressed = useKeyboardControls((state) => state[Controls.jump]);
|
||||
const shootPressed = useKeyboardControls((state) => state[Controls.shoot]);
|
||||
const resetPressed = useKeyboardControls((state) => state[Controls.reset]);
|
||||
const escPressed = useKeyboardControls((state) => state[Controls.escape]);
|
||||
|
||||
const [isOnGround, setIsOnGround] = useState(false);
|
||||
const body = useRef();
|
||||
@@ -114,6 +115,10 @@ export const PlayerControllerKeyboard = ({
|
||||
0,
|
||||
-Math.cos(kartRotation)
|
||||
);
|
||||
|
||||
if (escPressed) {
|
||||
actions.setGameStarted(false);
|
||||
}
|
||||
|
||||
if (leftPressed && currentSpeed > 0) {
|
||||
steeringAngle = currentSteeringSpeed;
|
||||
|
||||
Reference in new issue
Block a user