diff options
author | Kai Stevenson <kai@kaistevenson.com> | 2025-06-28 18:41:15 -0700 |
---|---|---|
committer | Kai Stevenson <kai@kaistevenson.com> | 2025-06-28 18:41:15 -0700 |
commit | ffcdb8b126c5267040ddc8f0304b153fa88755e5 (patch) | |
tree | 2b4dc37b743c12b6175022d68472974f2bcd831b /src/run.ts |
local play, some physics
Diffstat (limited to 'src/run.ts')
-rw-r--r-- | src/run.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/run.ts b/src/run.ts new file mode 100644 index 0000000..c798f87 --- /dev/null +++ b/src/run.ts @@ -0,0 +1,37 @@ +import { advanceState } from "./game"; +import { Action } from "./game/types"; +import { createSessionState, SessionState } from "./state"; +import { renderState, createAndBindHandler, prepareTerminal, Key } from "./ui"; + +export const run = async () => { + let state: SessionState = createSessionState("xyz"); + let actionQueue: Action[] = []; + + const updateAction = (key: Key) => { + if (actionQueue.length > 1) { + actionQueue = actionQueue.slice(1); + } + switch (key) { + case Key.LEFT_ARROW: + actionQueue.push(Action.MOVE_LEFT); + break; + case Key.RIGHT_ARROW: + actionQueue.push(Action.MOVE_RIGHT); + break; + default: + break; + } + }; + + prepareTerminal(); + + createAndBindHandler(updateAction, process.exit); + + while (true) { + let nextAction = actionQueue.pop(); + state = await advanceState(state, nextAction); + renderState(state); + } +}; + +run().then(console.log).catch(console.error); |