proper hero death / respawn

This commit is contained in:
2025-10-19 02:43:32 +01:00
parent ef635f6112
commit 7e9058b2c9
2 changed files with 11 additions and 1 deletions
+2 -1
View File
@@ -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);
+9
View File
@@ -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;