From 8027ffd894ce5be623a34e7a010258e08f0c7a06 Mon Sep 17 00:00:00 2001 From: "prompt.ac/@jeffrey" Date: Sat, 10 Oct 2026 17:15:16 -0700 Subject: [PATCH] Xbox: the controller into the piece's pad; the corridor walks on the sticks --- kidlisp/examples/meshes/corridor.lisp | 17 +++++++++++++---- kidlisp/tools/native-tv-script.mjs | 17 ++++++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/kidlisp/examples/meshes/corridor.lisp b/kidlisp/examples/meshes/corridor.lisp index 9766a6c083..5a6c86e8d5 100644 --- a/kidlisp/examples/meshes/corridor.lisp +++ b/kidlisp/examples/meshes/corridor.lisp @@ -16,12 +16,21 @@ (mesh guard (cube 36 90 20 60 120 200)) (def tt 0) (now tt (/ frame 60)) -(def camx 0) (now camx (* (sin (* tt 0.5)) 80)) -(def camz 0) (now camz (+ (% (* tt 220) 3400) 200)) ; the walk loops before the corridor ends -(def yaw 0) (now yaw (* (sin (* tt 0.7)) 0.25)) +; the left stick walks, the right stick looks; with no pad the camera walks itself +(def camx 0) (def camz 200) (def yaw 0) (def pitch 0) +(def held 0) (now held (+ (abs (pad leftx)) (abs (pad lefty)) (abs (pad rightx)) (abs (pad righty)))) +(if (> held 0.05) + (now yaw (+ yaw (* (pad rightx) 0.04))) + (now pitch (clamp (- pitch (* (pad righty) 0.03)) -0.8 0.8)) + (now camx (+ camx (* (pad leftx) 6 (cos yaw)) (* (pad lefty) -6 (sin yaw)))) + (now camz (+ camz (* (pad lefty) -6 (cos yaw)) (* (pad leftx) -6 (sin yaw)))) else + (now camx (* (sin (* tt 0.5)) 80)) + (now camz (+ (% (* tt 220) 3400) 200)) + (now yaw (* (sin (* tt 0.7)) 0.25))) +(now camx (clamp camx -560 560)) (now camz (clamp camz 100 3900)) (wipe 90 140 210) -(camera camx 60 camz yaw 0 70 NEAR_PLANE) +(camera camx 60 camz yaw pitch 70 NEAR_PLANE) (place floor 0 -150 2000) (place ceiling 0 150 2000) ; two long walls of bricks, staggered rows. Inside a loop a value is set diff --git a/kidlisp/tools/native-tv-script.mjs b/kidlisp/tools/native-tv-script.mjs index 97761b0c14..368ff21f8f 100644 --- a/kidlisp/tools/native-tv-script.mjs +++ b/kidlisp/tools/native-tv-script.mjs @@ -160,7 +160,22 @@ function load(index) { frames = 0; lastSwitch = Date.now(); } function boot() { try { bench(); } catch (_) {} screen(); api.screen.width = W; api.screen.height = H; load(0); } -function sim() {} +// The host's pad into the piece's pad: sticks and triggers as numbers, the +// down list as 0/1 under the evaluator's names (a b x y lb rb lt rt back +// start ls rs up down left right). +const PAD_NAMES = { A: "a", B: "b", X: "x", Y: "y", LeftShoulder: "lb", RightShoulder: "rb", LeftTrigger: "lt", RightTrigger: "rt", View: "back", Menu: "start", LeftThumbstick: "ls", RightThumbstick: "rs", DPadUp: "up", DPadDown: "down", DPadLeft: "left", DPadRight: "right" }; +const PAD_BUTTONS = ["a", "b", "x", "y", "lb", "rb", "lt", "rt", "back", "start", "ls", "rs", "up", "down", "left", "right"]; +function readPad() { + if (!lisp || typeof gamepad !== "function") return; + let p = null; try { p = gamepad(0); } catch (_) { return; } + const st = lisp.padState; + if (!p || !p.connected) { for (const k of PAD_BUTTONS) st[k] = 0; st.leftx = st.lefty = st.rightx = st.righty = 0; return; } + st.leftx = +p.leftX || 0; st.lefty = +p.leftY || 0; st.rightx = +p.rightX || 0; st.righty = +p.rightY || 0; + st.lt = +p.leftTrigger || 0; st.rt = +p.rightTrigger || 0; + for (const k of PAD_BUTTONS) if (k !== "lt" && k !== "rt") st[k] = 0; + if (Array.isArray(p.down)) for (const name of p.down) { const k = PAD_NAMES[name]; if (k) st[k] = 1; } +} +function sim() { readPad(); } function paint() { screen(); api.screen.width = W; api.screen.height = H; if (Date.now() - lastSwitch > SWITCH_EVERY) load((current + 1) % ORDER.length); -- 2.54.0