summaryrefslogtreecommitdiff
path: root/client/src/logic/logic.ts
diff options
context:
space:
mode:
authorTyler Murphy <tylerm@tylerm.dev>2023-06-16 20:38:55 -0400
committerTyler Murphy <tylerm@tylerm.dev>2023-06-16 20:38:55 -0400
commit44334fc3852eb832280a335f72e6416c93a9f19f (patch)
tree4a97b6064a97c4ad58c07d89050ad8a11e7a4f70 /client/src/logic/logic.ts
parentbetter map bg renderer (diff)
downloadtuxman-44334fc3852eb832280a335f72e6416c93a9f19f.tar.gz
tuxman-44334fc3852eb832280a335f72e6416c93a9f19f.tar.bz2
tuxman-44334fc3852eb832280a335f72e6416c93a9f19f.zip
ts
Diffstat (limited to 'client/src/logic/logic.ts')
-rw-r--r--client/src/logic/logic.ts80
1 files changed, 80 insertions, 0 deletions
diff --git a/client/src/logic/logic.ts b/client/src/logic/logic.ts
new file mode 100644
index 0000000..1cca2b7
--- /dev/null
+++ b/client/src/logic/logic.ts
@@ -0,0 +1,80 @@
+import { genItems, loadMap, getMap } from "../map.js";
+import { updatePlayers } from "./players.js"
+import { updateUI } from "./ui.js"
+import { updateMovement } from "./movement.js"
+import { updateItems } from "./items.js"
+import { GameState, Input } from "../types.js";
+
+
+export const InitialState: GameState = {
+ started: false,
+ input: {},
+ players: [],
+ items: {},
+ mapId: undefined
+}
+
+export const onLogic = (
+ pastData: GameState = InitialState,
+ input: Input = { players: {} },
+ _frame: number
+) => {
+
+ let data = structuredClone(pastData)
+
+ let startPressed = updatePlayers(data, input);
+
+ if (data.started) {
+ updateMovement(data)
+ updateItems(data)
+ } else {
+ updateUI(data)
+ }
+
+ if (startPressed && !data.started) {
+ initMap(data)
+ data.started = true;
+ }
+
+ return data
+
+}
+
+const initMap = (data: GameState) => {
+
+ document.getElementById("lobby").style.display = "none"
+
+ data.mapId = 0
+
+ if (getMap(0)) return
+
+ let width = 21
+ let height = 21
+ let m_data = [
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+ 1,0,0,0,0,0,0,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