From ffcdb8b126c5267040ddc8f0304b153fa88755e5 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Sat, 28 Jun 2025 18:41:15 -0700 Subject: local play, some physics --- src/run.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/run.ts (limited to 'src/run.ts') 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); -- cgit v1.2.3-70-g09d2