proper hero death / respawn
This commit is contained in:
@@ -2,7 +2,7 @@ import { useEffect } from "react";
|
||||
import type { GameManager } from "../../src";
|
||||
|
||||
export const useKeyBindings = (gameManager: GameManager) => {
|
||||
const { gameStatus, startGame, quitGame, keyManager } = gameManager;
|
||||
const { gameStatus, renderBoard, startGame, quitGame, keyManager } = gameManager;
|
||||
const { clearLog } = keyManager;
|
||||
|
||||
useEffect(() => {
|
||||
@@ -11,6 +11,7 @@ export const useKeyBindings = (gameManager: GameManager) => {
|
||||
if (ev.code === "Space") {
|
||||
if (["waiting", "game-over", "game-won"].includes(gameStatus)) {
|
||||
clearLog();
|
||||
renderBoard();
|
||||
if (gameStatus === "game-over" || gameStatus === "game-won") {
|
||||
quitGame();
|
||||
setTimeout(() => startGame(), 0);
|
||||
|
||||
@@ -22,6 +22,15 @@ export function useHero(board: BoardManager, gameStatus: GameStatus) {
|
||||
}
|
||||
}, [gameStatus, heroPos, mazeRef]);
|
||||
|
||||
useEffect(() => {
|
||||
if (gameStatus === 'waiting' || gameStatus === 'game-over' || gameStatus === 'game-won') {
|
||||
setHeroPos(null);
|
||||
const container = containerRef.current;
|
||||
container?.querySelector("#maze")?.classList.remove("finished");
|
||||
container?.querySelectorAll(".hero").forEach((el) => el.classList.remove("hero"));
|
||||
}
|
||||
}, [gameStatus, containerRef]);
|
||||
|
||||
const getCellEl = useCallback((r: number, c: number): HTMLElement | null => {
|
||||
const container = containerRef.current;
|
||||
if (!container) return null;
|
||||
|
||||
Reference in New Issue
Block a user