Skip to content
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

fix: add dpr and scale the tracks and marbles #2

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added public/assets/sounds/high_whack.wav
Binary file not shown.
Binary file added public/assets/sounds/low_whack.wav
Binary file not shown.
Binary file added public/assets/sprite/weapons/whack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 18 additions & 17 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@ import TuneIcon from "@mui/icons-material/Tune";
import { createRandomNumber, formatSecondsTohr } from "./helpers";
import axios from "axios";
import Close from "@mui/icons-material/Close";

export const tracks = [
"01",
"02",
// "02",
"03",
"06",
"07",
"11",
"14",
// "11",
// "14",
"16",
"21",
"22",
// "21",
// "22",
];

function App() {
Expand All @@ -68,7 +67,9 @@ function App() {
if (localTracks) {
const arr = JSON.parse(localTracks);
// unique array
return [...new Set(arr)] as string[];
return [...new Set(arr)].filter((t) =>
tracks.includes(t as string)
) as string[];
}
return tracks?.slice(0, 10);
}
Expand All @@ -77,7 +78,7 @@ function App() {
const [downloadProgress, setDownloadProgress] = useState(0);
const [startSectionIdx, setStartSectionIdx] = useState(3);
const [noOfRaceTracks, setNoOfRaceTracks] = useState(6);
const [marbleSpeed, setMarbleSpeed] = useState(0.2);
const [marbleSpeed, setMarbleSpeed] = useState(0.8);
const theme = useTheme();
const isMobileView = useMediaQuery(theme.breakpoints.down("md"));
const canvasElemWidth = window.innerWidth > 414 ? 414 : window.innerWidth;
Expand Down Expand Up @@ -249,7 +250,7 @@ function App() {
]
);
setBgPaths(nonMotionBgPaths);
setMotionBgPaths(motionBgPaths);
// setMotionBgPaths(motionBgPaths);
})();
(async () => {
const _trailsPath = await listAllTrails();
Expand Down Expand Up @@ -538,9 +539,9 @@ function App() {
<Typography>Speed</Typography>
<Slider
sx={{ width: 200 }}
min={0.1}
step={0.1}
max={0.8}
min={0.2}
step={0.2}
max={2}
value={marbleSpeed}
onChange={(_, val) =>
setMarbleSpeed(val as number)
Expand Down Expand Up @@ -964,9 +965,9 @@ function App() {
<Typography>Speed</Typography>
<Slider
sx={{ width: 200 }}
min={0.1}
step={0.1}
max={0.8}
min={0.2}
step={0.2}
max={2}
value={marbleSpeed}
onChange={(_, val) =>
setMarbleSpeed(val as number)
Expand Down Expand Up @@ -1087,7 +1088,7 @@ function App() {
}}
/>
))}
{motionBgPaths.map((path) => (
{/* {motionBgPaths.map((path) => (
<img
key={path}
src={path}
Expand All @@ -1108,7 +1109,7 @@ function App() {
setEnableMotion(true);
}}
/>
))}
))} */}
</Stack>
<SelectTracks
setSelectedTracksList={setSelectedTracksList}
Expand Down
2 changes: 1 addition & 1 deletion src/components/SelectVoices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const SelectVoices = ({ selectedVoices, setSelectedVoices, voices }: Props) => {
>
<Stack p={2} gap={1}>
<Typography>Choose Voice</Typography>
<Stack direction={"row"} gap={1}>
<Stack direction={"row"} gap={1} flexWrap={"wrap"}>
{voices
.filter(
(v) =>
Expand Down
31 changes: 27 additions & 4 deletions src/game/PhaserGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { forwardRef, useLayoutEffect, useRef, useState } from "react";
import StartGame from "./main";
import { GameVoiceInfo } from "./scenes/Preloader";
import * as Tone from "tone";
import { Box } from "@mui/material";

export interface IRefPhaserGame {
game: Phaser.Game | null;
Expand All @@ -25,6 +26,9 @@ export interface IGameDataParams {
trailEndSize: number;
recordDuration: number;
isRecord: boolean;
height?: number;
dprAdjustedWidth?: number;
dprAdjustedHeight?: number;
}

interface IProps extends IGameDataParams {
Expand Down Expand Up @@ -61,11 +65,12 @@ export const PhaserGame = forwardRef<IRefPhaserGame, IProps>(
},
ref
) {
const height = (width * 16) / 10;
const game = useRef<Phaser.Game | null>(null!);

const [mediaRecorder, setMediaRecorder] =
useState<null | MediaRecorder>(null);
const [isRecording, setIsRecording] = useState(false);
const [, setMediaRecorder] = useState<null | MediaRecorder>(null);
const [, setIsRecording] = useState(false);
const [dpr] = useState(window.devicePixelRatio);

const startRecording = (canvas: HTMLCanvasElement) => {
// const canvas = canvasRef.current;
Expand Down Expand Up @@ -110,6 +115,9 @@ export const PhaserGame = forwardRef<IRefPhaserGame, IProps>(
};

useLayoutEffect(() => {
const dprAdjustedWidth = width * dpr;
const dprAdjustedHeight = height * dpr;

game.current = StartGame("game-container", {
voices,
coverDocId,
Expand All @@ -119,7 +127,10 @@ export const PhaserGame = forwardRef<IRefPhaserGame, IProps>(
selectedTracks,
noOfRaceTracks,
gravityY,
dprAdjustedWidth,
dprAdjustedHeight,
width,
height,
enableMotion,
trailPath,
trailsLifeSpace,
Expand Down Expand Up @@ -148,7 +159,19 @@ export const PhaserGame = forwardRef<IRefPhaserGame, IProps>(
};
}, [ref]);

return <div id="game-container" style={{ height: "100%" }}></div>;
return (
<Box
id="game-container"
sx={{
height: "100%",
"& canvas": {
width,
height,
// border: "1px solid red",
},
}}
></Box>
);
}
);

17 changes: 14 additions & 3 deletions src/game/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ const config: Phaser.Types.Core.GameConfig = {
// debug: true,
},
},
pixelArt: true,
// pixelArt: true,
// antialias: false,
// scale: {
// mode: Phaser.Scale.FIT,
// },
// render: {
// pixelArt: true,
// },
// mode: Phaser.Scale.FIT,
// autoRound: false,
powerPreference: "high-performance",
scene: [Preloader, GameScene],
};

Expand All @@ -26,9 +36,10 @@ const StartGame = (parent: string, data: IGameDataParams) => {
config.physics.matter.gravity.y = data.gravityY;
const game = new Game({
...config,
width: data.width,
height: (data.width * 16) / 9,
width: data.dprAdjustedWidth,
height: data.dprAdjustedHeight,
parent,
// scale: { mode: Phaser.Scale.FIT, autoRound: true },
});
game.scene.start("preloader", data);
// // Add an event listener to apply the border radius once the game canvas is created
Expand Down
Loading