proper hero renderer and positioning

This commit is contained in:
2025-10-19 02:39:18 +01:00
parent 310355104a
commit ef635f6112
5 changed files with 232 additions and 12 deletions
+19 -5
View File
@@ -1,12 +1,23 @@
import { useState } from 'react';
import type { GameStatus } from '../types';
import { useState, useCallback } from 'react';
import type { GameStatus, BoardManager, Coord } from '../types';
export function useGameStatus() {
export function useGameStatus(board?: BoardManager, setHeroPos?: (pos: Coord) => void) {
const [gameStatus, setGameStatus] = useState<GameStatus>('waiting');
function startGame() {
const startGame = useCallback(() => {
if (board && setHeroPos) {
const m = board.mazeRef.current;
if (!m.length) return;
for (let c = 0; c < m[0].length; c++) {
if (m[m.length - 1][c].includes("entrance")) {
setHeroPos({ row: m.length - 1, col: c });
break;
}
}
}
setGameStatus('started');
}
}, [board, setHeroPos]);
function togglePause(pause?: boolean) {
if (typeof pause === 'boolean') {
@@ -17,6 +28,9 @@ export function useGameStatus() {
}
function quitGame() {
if (setHeroPos) {
setHeroPos({ row: 0, col: 0 });
}
setGameStatus('waiting');
}