-
Notifications
You must be signed in to change notification settings - Fork 26
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 #143 from webdevcody/add-in-multiplayer-support
Add in multiplayer support
- Loading branch information
Showing
57 changed files
with
1,726 additions
and
869 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"use client"; | ||
|
||
import { useQuery } from "convex/react"; | ||
import { Page, PageTitle } from "@/components/Page"; | ||
import { Visualizer } from "@/components/Visualizer"; | ||
import { api } from "@/convex/_generated/api"; | ||
import { Id } from "@/convex/_generated/dataModel"; | ||
|
||
export default function MultiplayerPage({ | ||
params, | ||
}: { | ||
params: { multiplayerGameId: Id<"multiplayerGames"> }; | ||
}) { | ||
const multiplayerGame = useQuery(api.multiplayerGames.getMultiplayerGame, { | ||
multiplayerGameId: params.multiplayerGameId, | ||
}); | ||
|
||
if (multiplayerGame === undefined) { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
if (multiplayerGame === null) { | ||
return <div>Game not found.</div>; | ||
} | ||
|
||
return ( | ||
<Page> | ||
<PageTitle>Multiplayer</PageTitle> | ||
<div className="flex justify-center"> | ||
<Visualizer | ||
controls={false} | ||
map={multiplayerGame.boardState} | ||
simulatorOptions={{ multiplayer: true }} | ||
/> | ||
</div> | ||
</Page> | ||
); | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { useEffect, useState } from "react"; | ||
import { DEFAULT_REPLAY_SPEED } from "@/constants/visualizer"; | ||
import { Renderer } from "@/renderer"; | ||
import { ZombieSurvival } from "@/simulator"; | ||
|
||
export function useRenderer( | ||
map: string[][] | null | undefined, | ||
canvas: React.MutableRefObject<HTMLCanvasElement | null>, | ||
cellSize: number = 64, | ||
replaySpeed: number = DEFAULT_REPLAY_SPEED, | ||
) { | ||
const [renderer, setRenderer] = useState<Renderer | null>(null); | ||
|
||
useEffect(() => { | ||
if (map === null || map === undefined) { | ||
return; | ||
} | ||
|
||
const boardWidth = ZombieSurvival.boardWidth(map); | ||
const boardHeight = ZombieSurvival.boardHeight(map); | ||
|
||
async function handleInitializeRenderer() { | ||
if (canvas.current === null) { | ||
return; | ||
} | ||
|
||
const renderer = new Renderer( | ||
boardWidth, | ||
boardHeight, | ||
canvas.current, | ||
cellSize, | ||
replaySpeed, | ||
); | ||
|
||
await renderer.initialize(); | ||
setRenderer(renderer); | ||
} | ||
|
||
void handleInitializeRenderer(); | ||
}, [map, cellSize, replaySpeed]); | ||
|
||
return renderer; | ||
} |
Oops, something went wrong.