Skip to content

Commit

Permalink
Merge pull request #26 from Waiklam/main
Browse files Browse the repository at this point in the history
Added return to menu (input select) in game on all inputs (issue #20)
  • Loading branch information
Lunakepio authored Feb 19, 2024
2 parents 5ac25a1 + e466e32 commit 4d02008
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 5 deletions.
26 changes: 25 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ export const Controls = {
boost: 'boost',
shoot: 'shoot',
slow: 'slow',
reset: 'reset'
reset: 'reset',
escape: 'escape'
}

function App() {
const map = useMemo(
() => [
Expand All @@ -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']}
],
[]
)
Expand Down
20 changes: 20 additions & 0 deletions src/HUD.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,26 @@ export const HUD = () => {
>
item
</div>
<div
className="controls menuButton"
onMouseDown={(e) => {
actions.setMenuButton(true);
}}
onMouseUp={(e) => {
actions.setMenuButton(false);
}}
onTouchStart={(e) => {
e.preventDefault();
actions.setMenuButton(true);
}}
onTouchEnd={(e) => {
e.preventDefault();
actions.setMenuButton(false);
}}

>
menu
</div>
</>
)}
</>
Expand Down
5 changes: 5 additions & 0 deletions src/components/PlayerController.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -114,6 +115,10 @@ export const PlayerController = ({
0,
-Math.cos(kartRotation)
);

if (escPressed) {
actions.setGameStarted(false);
}

if (leftPressed && currentSpeed > 0) {
steeringAngle = currentSteeringSpeed;
Expand Down
6 changes: 5 additions & 1 deletion src/components/PlayerControllerGamepad.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -110,6 +110,10 @@ export const PlayerControllerGamepad = ({
-Math.cos(kartRotation)
);

if (start) {
actions.setGameStarted(false);
}

// mouse steering

if (!driftLeft.current && !driftRight.current) {
Expand Down
5 changes: 5 additions & 0 deletions src/components/PlayerControllerKeyboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -114,6 +115,10 @@ export const PlayerControllerKeyboard = ({
0,
-Math.cos(kartRotation)
);

if (escPressed) {
actions.setGameStarted(false);
}

if (leftPressed && currentSpeed > 0) {
steeringAngle = currentSteeringSpeed;
Expand Down
6 changes: 5 additions & 1 deletion src/components/PlayerControllerTouch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const PlayerControllerTouch = ({
const effectiveBoost = useRef(0);
const text = useRef();

const { actions, shouldSlowDown, item, bananas, coins, id, controls, joystickX, driftButton, itemButton } = useStore();
const { actions, shouldSlowDown, item, bananas, coins, id, controls, joystickX, driftButton, itemButton, menuButton } = useStore();
const slowDownDuration = useRef(1500);

useFrame(({ pointer, clock }, delta) => {
Expand All @@ -109,6 +109,10 @@ export const PlayerControllerTouch = ({
-Math.cos(kartRotation)
);

if (menuButton) {
actions.setGameStarted(false);
}

// mouse steering

if (!driftLeft.current && !driftRight.current) {
Expand Down
4 changes: 4 additions & 0 deletions src/components/store.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const useStore = create((set, get) => ({
joystickX: 0,
driftButton: false,
itemButton: false,
menuButton: false,
addPastPosition: (position) => {
set((state) => ({
pastPositions: [position, ...state.pastPositions.slice(0, 499)],
Expand Down Expand Up @@ -160,6 +161,9 @@ export const useStore = create((set, get) => ({
setItemButton: (itemButton) => {
set({ itemButton });
},
setMenuButton: (menuButton) => {
set({ menuButton });
},
},

}));
17 changes: 17 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,23 @@ body::-webkit-scrollbar {
cursor: pointer;
}

.controls.menuButton {
right: 50px;
top: 60px;
font-family: "Hanken Grotesk";
border-radius: 100px;
background: rgba(255, 255, 255, 0.5);
height: 66.6667px;
width: 66.6667px;
border: none;
flex-shrink: 0;
touch-action: none;
color: white;
display: grid;
place-content: center;
cursor: pointer;
}

@media screen and (max-width: 1000px) {
.home {
gap: 50px;
Expand Down

0 comments on commit 4d02008

Please sign in to comment.