Bash.tv → GitHub → itch.io

Shared-device co-op and versus play for browser games. Press-to-join player slots across keyboard schemes (WASD, arrows, numpad), gamepads (standard mapping, dead zone, d-pad, unplug handling) and on-screen touch players; colors and labels; a shared camera that zooms to keep everyone in view plus a leash at the zoom limit; split-screen viewports for 2-4 players (side by side or stacked for port...

Download skill (.zip) Files on GitHub

Local co-op

No network: everyone plays on one screen. The hard parts are who controls what, keeping everyone visible, and fair controls.

assets/coop.js

import { createCoop, sharedCamera, leash, splitViewports, clipTo, touchZones, KEYBOARD_SCHEMES } from "./coop.js";
const coop = createCoop({ max: 4, schemes: KEYBOARD_SCHEMES.slice(0, 2) }).attach(window);
// lobby scene: each frame
const { joined } = coop.update();      // pressing A on an unused device (F, K, or a controller's A) takes the next slot
draw: for each slot show "P1 · WASD + F/G" or "Press F, K or A to join"; start when a joined player presses start/A again
// play scene: each frame
coop.update();
for (const p of coop.players) movePlayer(p.slot, p.input);   // input: { x, y, a, b, start, aPressed, bPressed, startPressed }
Device Join Notes
Keyboard left F WASD move, F/G buttons, R start
Keyboard right K Arrows move, K/L, Enter
Numpad (optional third) Numpad 0 8456 move
Gamepad (each) A (button 0) left stick + d-pad, B leaves in the lobby, Start; unplug keeps the slot and shows disconnected
Touch your button coop.addVirtual("touch-left"), then set p.input from that player’s on-screen controls

Keeping everyone on screen

Fairness and comfort

Starters

The party-game genre starter (4 players, one key each, screen corners on touch) is a ready base for local versus games. For co-op, take a genre starter and replace its single player with coop.players.

Tested

Node tests: keyboard and gamepad joining in slot order, input values and dead zone, unplug keeping the slot, max players, shared camera zoom limit and centering, leash clamping, split layouts for landscape and portrait.

Pitfalls

The first player who touches anything becomes P1 without choosing, slots that shift when someone leaves (slots are stable here), a camera that zooms so far out nothing is readable, split screen on a phone (too small), and forgetting blur (keys stay held when the window loses focus; handled).