diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-03-01 18:56:58 -0700 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-03-01 18:56:58 -0700 |
commit | a8d07a790395e14fe7aedd3ba638db466f9c0842 (patch) | |
tree | 644f60a6bca79ceb55f24fcab7bdb3dee52c2d6e /src/components | |
parent | aa08a8943a9a2d4a0e51893eebe6900bca7a7251 (diff) | |
download | the-abstraction-engine-a8d07a790395e14fe7aedd3ba638db466f9c0842.tar.gz the-abstraction-engine-a8d07a790395e14fe7aedd3ba638db466f9c0842.zip |
boundingbox + draw player
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/GameCanvas.tsx | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/components/GameCanvas.tsx b/src/components/GameCanvas.tsx index ea93c64..5cb40a6 100644 --- a/src/components/GameCanvas.tsx +++ b/src/components/GameCanvas.tsx @@ -1,4 +1,5 @@ -import { useRef } from "react"; +import { useState, useEffect, useRef } from "react"; +import { TheAbstractionEngine, Game } from "../engine"; export interface GameCanvasProps { width: number; @@ -7,6 +8,25 @@ export interface GameCanvasProps { export const GameCanvas = ({ width, height }: GameCanvasProps) => { const canvasRef = useRef<HTMLCanvasElement>(null); + const [_game, setGame] = useState<TheAbstractionEngine>(); + + useEffect(() => { + if (canvasRef.current) { + const canvas = canvasRef.current; + const ctx = canvas.getContext("2d"); + if (ctx) { + const game = new Game(); + const theAbstractionEngine = new TheAbstractionEngine(game, ctx); + + theAbstractionEngine.init().then(() => { + theAbstractionEngine.play(); + setGame(theAbstractionEngine); + }); + + return () => theAbstractionEngine.stop(); + } + } + }, [canvasRef]); return ( <div className="centered-game"> |