Add tap-controlled incremental space-knight game
Auto-flying knight, crystal zones, pirate/boss combat, shop upgrades, falling/golden asteroids, particle juice, droid evolution, and a supernova prestige cutscene, per the design spec. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D5SuZW1XGCkahPX7cHMoRP
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
9f903a5094
commit
cbd547944e
@@ -0,0 +1,24 @@
|
||||
import { useEffect, useRef, useState, type RefObject } from 'react';
|
||||
import { GameEngine } from '../game/GameEngine';
|
||||
import type { GameSnapshot } from '../game/types';
|
||||
|
||||
export function useGameEngine(canvasRef: RefObject<HTMLCanvasElement | null>) {
|
||||
const engineRef = useRef<GameEngine | null>(null);
|
||||
const [snapshot, setSnapshot] = useState<GameSnapshot | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const canvas = canvasRef.current;
|
||||
if (!canvas) return;
|
||||
const engine = new GameEngine(canvas);
|
||||
engineRef.current = engine;
|
||||
const unsubscribe = engine.subscribe(setSnapshot);
|
||||
engine.start();
|
||||
return () => {
|
||||
unsubscribe();
|
||||
engine.stop();
|
||||
engineRef.current = null;
|
||||
};
|
||||
}, [canvasRef]);
|
||||
|
||||
return { engine: engineRef, snapshot };
|
||||
}
|
||||
Reference in New Issue
Block a user