@vibechain/os 0.2.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +110 -201
- package/README.md +78 -7
- package/SECURITY.md +22 -3
- package/dist/app-runtime.d.ts +1 -1
- package/dist/app-runtime.js +11 -3
- package/dist/bundle.js +10 -0
- package/dist/canvas.d.ts +40 -0
- package/dist/canvas.js +41 -0
- package/dist/cli.js +1 -1
- package/dist/listing.d.ts +35 -0
- package/dist/listing.js +56 -0
- package/dist/loop.d.ts +34 -0
- package/dist/loop.js +47 -0
- package/dist/manifest.d.ts +70 -1
- package/dist/manifest.js +117 -9
- package/dist/preview-ui.js +1 -1
- package/dist/scaffold.js +20 -7
- package/dist/testing.d.ts +29 -0
- package/dist/testing.js +49 -0
- package/examples/paw-beat/README.md +50 -0
- package/examples/paw-beat/cat.ts +129 -0
- package/examples/paw-beat/game.ts +151 -0
- package/examples/paw-beat/index.html +65 -0
- package/examples/paw-beat/main.ts +243 -0
- package/examples/paw-beat/music.ts +123 -0
- package/examples/paw-beat/store/icon.png +0 -0
- package/examples/paw-beat/store/screenshot-1.webp +0 -0
- package/examples/paw-beat/store/screenshot-2.webp +0 -0
- package/examples/paw-beat/vibemarket.json +21 -0
- package/examples/vibexp-app/README.md +19 -3
- package/examples/vibexp-app/store/icon.png +0 -0
- package/examples/vibexp-app/store/screenshot-1.png +0 -0
- package/examples/vibexp-app/vibemarket.json +21 -1
- package/package.json +19 -2
- package/examples/chonk-stack/card-slice.ts +0 -17
- package/examples/chonk-stack/cat3d.ts +0 -57
- package/examples/chonk-stack/game.css +0 -174
- package/examples/chonk-stack/index.html +0 -32
- package/examples/chonk-stack/main.ts +0 -149
- package/examples/chonk-stack/model.ts +0 -40
- package/examples/chonk-stack/renderer.ts +0 -263
- package/examples/chonk-stack/skins.ts +0 -47
- package/examples/chonk-stack/vibemarket.json +0 -21
- package/examples/collection-room/index.html +0 -3
- package/examples/collection-room/main.ts +0 -31
- package/examples/collection-room/vibemarket.json +0 -12
- package/examples/tsconfig.json +0 -4
package/dist/testing.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { checkpointValue, lifecycleValue } from "./app-protocol.js";
|
|
2
|
+
import { gameFinishInput } from "./completion.js";
|
|
3
|
+
/**
|
|
4
|
+
* An in-memory stand-in for the VibeMarket OS host, for unit tests. It applies the same
|
|
5
|
+
* checkpoint, score and lifecycle validation as the real host and the same single-shot
|
|
6
|
+
* completion rule, but has no window, no port, no time limit and no request budget.
|
|
7
|
+
* Passing here does not replace a run in the preview.
|
|
8
|
+
*/
|
|
9
|
+
export function createFakeApp(options = {}) {
|
|
10
|
+
let checkpoint = checkpointValue(options.checkpoint ?? null);
|
|
11
|
+
let state = lifecycleValue({ active: true, width: 800, height: 600, ...options.lifecycle });
|
|
12
|
+
let ready = false, destroyed = false, finished = null;
|
|
13
|
+
const listeners = new Set();
|
|
14
|
+
const open = () => { if (destroyed)
|
|
15
|
+
throw Error("Game session ended."); };
|
|
16
|
+
const app = Object.freeze({
|
|
17
|
+
game: Object.freeze({
|
|
18
|
+
async finish(input) {
|
|
19
|
+
open();
|
|
20
|
+
const result = gameFinishInput(input);
|
|
21
|
+
if (finished && finished.score !== result.score)
|
|
22
|
+
throw Error("This game has already finished.");
|
|
23
|
+
finished ??= result;
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
async ready() { open(); ready = true; },
|
|
27
|
+
checkpoint: Object.freeze({
|
|
28
|
+
async read() { open(); return checkpointValue(checkpoint); },
|
|
29
|
+
async write(value) { open(); checkpoint = checkpointValue(value); },
|
|
30
|
+
}),
|
|
31
|
+
lifecycle: Object.freeze({
|
|
32
|
+
current: () => state,
|
|
33
|
+
onChanged(listener) { listeners.add(listener); return () => { listeners.delete(listener); }; },
|
|
34
|
+
}),
|
|
35
|
+
destroy() { destroyed = true; listeners.clear(); },
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
app,
|
|
39
|
+
setLifecycle(next) {
|
|
40
|
+
state = lifecycleValue({ ...state, ...next });
|
|
41
|
+
for (const listener of [...listeners])
|
|
42
|
+
listener(state);
|
|
43
|
+
},
|
|
44
|
+
get ready() { return ready; },
|
|
45
|
+
get finished() { return finished; },
|
|
46
|
+
get checkpoint() { return checkpointValue(checkpoint); },
|
|
47
|
+
get destroyed() { return destroyed; },
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Paw Beat
|
|
2
|
+
|
|
3
|
+
A 3D rhythm game for VibeMarket OS, written in TypeScript with Three.js. Arrows slide down four lanes toward their targets. Press the matching key as each one lands (arrow keys, WASD or the on-screen pads) and Biscuit the cat dances the step. Timing is judged perfect, great or good; every ten steps in a row adds 10% to each step, up to double. One song lasts about a minute.
|
|
4
|
+
|
|
5
|
+
It is a complete example of the app API:
|
|
6
|
+
|
|
7
|
+
| File | What it shows |
|
|
8
|
+
|---|---|
|
|
9
|
+
| `game.ts` | The chart generator and judging as pure TypeScript with no DOM, renderer or audio, so they can be unit-tested |
|
|
10
|
+
| `cat.ts` | A procedural 3D cat built from primitives at runtime; no model or texture files |
|
|
11
|
+
| `music.ts` | The whole song synthesized with Web Audio and scheduled on the audio clock, which also times the steps |
|
|
12
|
+
| `main.ts` | `connectVibeMarketApp()`, `fitCanvas` and `createLoop` from the SDK helpers, a checkpoint for the personal best, and `game.finish({ score })` |
|
|
13
|
+
|
|
14
|
+
Everything in the game is generated in code, so the bundle is `index.html`, one script, the manifest and the three store images in `store/`. The steps and the lead melody come from a seed, so each round is a little different and any round can be replayed in a test.
|
|
15
|
+
|
|
16
|
+
## Build and run
|
|
17
|
+
|
|
18
|
+
In your own project, with `@vibechain/os`, `three`, `@types/three`, `esbuild` and `typescript` installed:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npx esbuild main.ts --bundle --minify --format=esm --target=es2022 --outfile=dist/game.js
|
|
22
|
+
cp index.html vibemarket.json dist/
|
|
23
|
+
cp -R store dist/
|
|
24
|
+
npx os preview dist
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Open the printed `http://127.0.0.1:PORT` address. Use a unique `id` and `version` in `vibemarket.json` before packaging your own game.
|
|
28
|
+
|
|
29
|
+
## Listing in VibeStore
|
|
30
|
+
|
|
31
|
+
`vibemarket.json` uses manifest schema version 2, so it carries a complete VibeStore listing: a `window` of 960 x 600 that can be resized, and a `store` object with the icon, two screenshots, a plain-text description, the `game` category, a content rating (violence `none`, language `none`, not mature) and a support link.
|
|
32
|
+
|
|
33
|
+
The requirements are checked when you submit from the VibeStore **Submit** tab, and `os pack` and `os preview` check the same things locally:
|
|
34
|
+
|
|
35
|
+
- the icon is a PNG of exactly 256 x 256 pixels, at most 256 KiB;
|
|
36
|
+
- there are 1 to 4 screenshots, PNG, JPEG or WebP, each at most 1 MiB, with contents that match the extension;
|
|
37
|
+
- the description is 40 to 2,000 characters of plain text;
|
|
38
|
+
- the support contact is an `https://` URL or an email address;
|
|
39
|
+
- the window is 320 to 1600 by 200 to 1200 pixels;
|
|
40
|
+
- there is no SVG anywhere in the bundle.
|
|
41
|
+
|
|
42
|
+
`store/icon.png` is Biscuit drawn by `cat.ts` itself, and the screenshots are captures of this game running in the SDK preview. Replace all three, and the listing text, with your own before submitting a game of your own.
|
|
43
|
+
|
|
44
|
+
## What the score means
|
|
45
|
+
|
|
46
|
+
The score is reported to the host with `game.finish`. It is display data. The game cannot grant Cash, XP or items, and the preview awards nothing.
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
MIT, with the rest of the `@vibechain/os` package. Biscuit, the song and all of the code here are original to this example.
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import type { Lane } from "./game";
|
|
3
|
+
|
|
4
|
+
export interface Cat {
|
|
5
|
+
readonly root: THREE.Group;
|
|
6
|
+
/** Play the move for a step that landed. */
|
|
7
|
+
dance(lane: Lane): void;
|
|
8
|
+
/** A missed step: ears back, a wobble. */
|
|
9
|
+
stumble(): void;
|
|
10
|
+
/** `beatPhase` runs 0 to 1 across each beat, so the idle bounce lands on the music. */
|
|
11
|
+
animate(seconds: number, beatPhase: number): void;
|
|
12
|
+
dispose(): void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const FUR = "#e8944a", FUR_DARK = "#b9652a", CREAM = "#fff1dc", PINK = "#ff9db5", INK = "#2a1a2e";
|
|
16
|
+
type Triple = [number, number, number];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Biscuit, a procedural dancing cat. Everything is built from primitives at runtime:
|
|
20
|
+
* there is no model file, texture or other downloaded asset.
|
|
21
|
+
*/
|
|
22
|
+
export function createCat(): Cat {
|
|
23
|
+
const root = new THREE.Group(), figure = new THREE.Group(), head = new THREE.Group();
|
|
24
|
+
root.add(figure);
|
|
25
|
+
const geometries: THREE.BufferGeometry[] = [], materials: THREE.Material[] = [];
|
|
26
|
+
const sphere = new THREE.SphereGeometry(1, 28, 20), cone = new THREE.ConeGeometry(0.3, 0.52, 4);
|
|
27
|
+
geometries.push(sphere, cone);
|
|
28
|
+
const paint = (color: string, roughness = 0.85) => {
|
|
29
|
+
const material = new THREE.MeshStandardMaterial({ color, roughness });
|
|
30
|
+
materials.push(material);
|
|
31
|
+
return material;
|
|
32
|
+
};
|
|
33
|
+
const fur = paint(FUR), dark = paint(FUR_DARK), cream = paint(CREAM), pink = paint(PINK, 0.6), ink = paint(INK, 0.3);
|
|
34
|
+
const part = (parent: THREE.Object3D, geometry: THREE.BufferGeometry, material: THREE.Material, position: Triple, scale: Triple) => {
|
|
35
|
+
const mesh = new THREE.Mesh(geometry, material);
|
|
36
|
+
mesh.position.set(position[0], position[1], position[2]);
|
|
37
|
+
mesh.scale.set(scale[0], scale[1], scale[2]);
|
|
38
|
+
parent.add(mesh);
|
|
39
|
+
return mesh;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Upright body with a cream tummy and two stripes.
|
|
43
|
+
part(figure, sphere, fur, [0, 1.0, 0], [0.78, 0.95, 0.7]);
|
|
44
|
+
part(figure, sphere, cream, [0, 0.92, 0.36], [0.5, 0.62, 0.42]);
|
|
45
|
+
for (const y of [1.25, 1.0]) part(figure, sphere, dark, [0, y, -0.62], [0.42, 0.06, 0.08]);
|
|
46
|
+
|
|
47
|
+
// Feet stay planted; front paws are the arms that do the dancing.
|
|
48
|
+
for (const side of [-1, 1]) part(figure, sphere, cream, [side * 0.36, 0.14, 0.2], [0.26, 0.15, 0.36]);
|
|
49
|
+
const leftPaw = part(figure, sphere, cream, [-0.74, 1.05, 0.25], [0.2, 0.2, 0.2]);
|
|
50
|
+
const rightPaw = part(figure, sphere, cream, [0.74, 1.05, 0.25], [0.2, 0.2, 0.2]);
|
|
51
|
+
|
|
52
|
+
const tail: THREE.Mesh[] = [];
|
|
53
|
+
for (let i = 0; i < 7; i++) {
|
|
54
|
+
const size = 0.17 - i * 0.01;
|
|
55
|
+
tail.push(part(figure, sphere, dark, [0, 0.45 + i * 0.17, -0.7 - i * 0.1], [size, size, size]));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
head.position.set(0, 2.2, 0.08);
|
|
59
|
+
figure.add(head);
|
|
60
|
+
part(head, sphere, fur, [0, 0, 0], [0.74, 0.64, 0.66]);
|
|
61
|
+
const ears = [-1, 1].map(side => {
|
|
62
|
+
const ear = part(head, cone, fur, [side * 0.44, 0.58, -0.02], [1, 1, 0.6]);
|
|
63
|
+
ear.rotation.z = side * -0.3;
|
|
64
|
+
part(ear, cone, pink, [0, -0.04, 0.12], [0.6, 0.7, 0.5]);
|
|
65
|
+
return { ear, side };
|
|
66
|
+
});
|
|
67
|
+
for (const side of [-1, 1]) part(head, sphere, cream, [side * 0.26, -0.2, 0.5], [0.24, 0.18, 0.2]);
|
|
68
|
+
part(head, sphere, pink, [0, -0.1, 0.66], [0.07, 0.05, 0.05]);
|
|
69
|
+
const eyes = [-1, 1].map(side => part(head, sphere, ink, [side * 0.27, 0.1, 0.57], [0.09, 0.13, 0.05]));
|
|
70
|
+
const whiskers = new THREE.LineBasicMaterial({ color: "#ffffff", transparent: true, opacity: 0.7 });
|
|
71
|
+
materials.push(whiskers);
|
|
72
|
+
for (const side of [-1, 1]) {
|
|
73
|
+
for (let i = 0; i < 3; i++) {
|
|
74
|
+
const geometry = new THREE.BufferGeometry().setFromPoints([
|
|
75
|
+
new THREE.Vector3(side * 0.34, -0.16 - i * 0.05, 0.6),
|
|
76
|
+
new THREE.Vector3(side * 0.95, -0.1 - i * 0.13, 0.5),
|
|
77
|
+
]);
|
|
78
|
+
geometries.push(geometry);
|
|
79
|
+
head.add(new THREE.Line(geometry, whiskers));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Each move is a short pulse (1 fading to 0) that the pose below reads.
|
|
84
|
+
const pulse = { left: 0, right: 0, up: 0, down: 0, stumble: 0 };
|
|
85
|
+
let clock = 0;
|
|
86
|
+
return {
|
|
87
|
+
root,
|
|
88
|
+
dance(lane) {
|
|
89
|
+
pulse[lane] = 1;
|
|
90
|
+
},
|
|
91
|
+
stumble() {
|
|
92
|
+
pulse.stumble = 1;
|
|
93
|
+
},
|
|
94
|
+
animate(seconds, beatPhase) {
|
|
95
|
+
clock += seconds;
|
|
96
|
+
for (const key of Object.keys(pulse) as (keyof typeof pulse)[]) pulse[key] = Math.max(0, pulse[key] - seconds * 3.2);
|
|
97
|
+
const ease = (value: number) => Math.sin(value * Math.PI); // up and back down over one pulse
|
|
98
|
+
const side = ease(pulse.right) - ease(pulse.left), jump = ease(pulse.up), crouch = ease(pulse.down), wobble = pulse.stumble;
|
|
99
|
+
// The idle bounce: a quick dip right on the beat that relaxes before the next one.
|
|
100
|
+
const bounce = Math.pow(1 - beatPhase, 3);
|
|
101
|
+
|
|
102
|
+
figure.position.x = side * 0.75;
|
|
103
|
+
figure.position.y = jump * 1.1;
|
|
104
|
+
figure.rotation.z = -side * 0.28 + Math.sin(clock * 38) * 0.07 * wobble;
|
|
105
|
+
figure.rotation.y = side * 0.35;
|
|
106
|
+
figure.scale.y = 1 - bounce * 0.07 - crouch * 0.38 + jump * 0.08;
|
|
107
|
+
figure.scale.x = figure.scale.z = 1 + bounce * 0.04 + crouch * 0.2;
|
|
108
|
+
|
|
109
|
+
head.rotation.x = bounce * 0.18 + crouch * 0.25 - jump * 0.2;
|
|
110
|
+
head.rotation.z = side * 0.2;
|
|
111
|
+
|
|
112
|
+
// Paws: the stepping side punches out, both go up for a jump, both drop for a crouch.
|
|
113
|
+
const leftUp = Math.max(ease(pulse.left), jump), rightUp = Math.max(ease(pulse.right), jump);
|
|
114
|
+
leftPaw.position.set(-0.74 - ease(pulse.left) * 0.45, 1.05 + leftUp * 0.85 - crouch * 0.4 + bounce * 0.06, 0.25);
|
|
115
|
+
rightPaw.position.set(0.74 + ease(pulse.right) * 0.45, 1.05 + rightUp * 0.85 - crouch * 0.4 + bounce * 0.06, 0.25);
|
|
116
|
+
|
|
117
|
+
// Eyes squeeze shut on a landed jump; ears go flat on a stumble.
|
|
118
|
+
for (const eye of eyes) eye.scale.y = 0.13 * (1 - jump * 0.7) * (1 - wobble * 0.5);
|
|
119
|
+
for (const { ear, side: earSide } of ears) ear.rotation.z = earSide * (-0.3 - wobble * 0.8);
|
|
120
|
+
tail.forEach((segment, index) => {
|
|
121
|
+
segment.position.x = Math.sin(clock * 6 + index * 0.55) * 0.05 * index + side * -0.06 * index;
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
dispose() {
|
|
125
|
+
for (const geometry of geometries) geometry.dispose();
|
|
126
|
+
for (const material of materials) material.dispose();
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paw Beat rules. Pure TypeScript: no DOM, no renderer, no audio, no SDK. main.ts feeds
|
|
3
|
+
* in the song clock and key presses and reads state out, so every rule is unit-testable.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const LANES = ["left", "down", "up", "right"] as const;
|
|
7
|
+
export type Lane = typeof LANES[number];
|
|
8
|
+
|
|
9
|
+
export const BPM = 120;
|
|
10
|
+
export const BEAT_SECONDS = 60 / BPM;
|
|
11
|
+
/** Four silent beats to count in, then 112 beats of steps: one minute in all. */
|
|
12
|
+
export const COUNT_IN_BEATS = 4;
|
|
13
|
+
export const SONG_BEATS = 116;
|
|
14
|
+
export const SONG_SECONDS = SONG_BEATS * BEAT_SECONDS;
|
|
15
|
+
/** The host accepts integer scores up to this value. */
|
|
16
|
+
export const SCORE_LIMIT = 1_000_000_000;
|
|
17
|
+
|
|
18
|
+
/** How close to the beat a press must land, in seconds, and what it pays. */
|
|
19
|
+
const WINDOWS = [
|
|
20
|
+
{ judgement: "perfect", within: 0.05, points: 100 },
|
|
21
|
+
{ judgement: "great", within: 0.1, points: 60 },
|
|
22
|
+
{ judgement: "good", within: 0.16, points: 30 },
|
|
23
|
+
] as const;
|
|
24
|
+
const MISS_AFTER = WINDOWS[2].within;
|
|
25
|
+
|
|
26
|
+
export type Judgement = typeof WINDOWS[number]["judgement"] | "miss";
|
|
27
|
+
export interface Note { readonly time: number; readonly lane: Lane }
|
|
28
|
+
export interface NoteView extends Note { readonly index: number; readonly judged: Judgement | null }
|
|
29
|
+
|
|
30
|
+
export interface DanceState {
|
|
31
|
+
readonly time: number;
|
|
32
|
+
readonly score: number;
|
|
33
|
+
readonly combo: number;
|
|
34
|
+
readonly bestCombo: number;
|
|
35
|
+
readonly counts: Readonly<Record<Judgement, number>>;
|
|
36
|
+
readonly finished: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface DanceGame {
|
|
40
|
+
readonly notes: readonly NoteView[];
|
|
41
|
+
readonly state: DanceState;
|
|
42
|
+
/** Move the song clock to `time` seconds. Notes that scrolled past unhit become misses. */
|
|
43
|
+
advance(time: number): readonly NoteView[];
|
|
44
|
+
/** Visit every note timed from `from` to `to` seconds, in order, without allocating. For drawing. */
|
|
45
|
+
each(from: number, to: number, visit: (note: Note, judged: Judgement | null) => void): void;
|
|
46
|
+
/** A press in `lane` at the current clock. Returns the note it hit, or null for a stray press. */
|
|
47
|
+
press(lane: Lane): NoteView | null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Small deterministic generator, so a seed replays the same steps. */
|
|
51
|
+
function random(seed: number): () => number {
|
|
52
|
+
let state = seed >>> 0;
|
|
53
|
+
return () => {
|
|
54
|
+
state = (state + 0x6d2b79f5) >>> 0;
|
|
55
|
+
let value = Math.imul(state ^ (state >>> 15), 1 | state);
|
|
56
|
+
value = (value + Math.imul(value ^ (value >>> 7), 61 | value)) ^ value;
|
|
57
|
+
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Write the steps for one song. It warms up on the beat, adds off-beat steps in the
|
|
63
|
+
* middle and two-paw jumps near the end. The same lane never repeats on an off-beat,
|
|
64
|
+
* so every pattern is playable with four keys.
|
|
65
|
+
*/
|
|
66
|
+
export function createChart(seed: number): Note[] {
|
|
67
|
+
const next = random(seed), notes: Note[] = [];
|
|
68
|
+
const pick = (avoid?: Lane): Lane => {
|
|
69
|
+
const pool = LANES.filter(lane => lane !== avoid);
|
|
70
|
+
return pool[Math.floor(next() * pool.length)] ?? "left";
|
|
71
|
+
};
|
|
72
|
+
let previous: Lane | undefined;
|
|
73
|
+
for (let beat = COUNT_IN_BEATS; beat < SONG_BEATS - 2; beat++) {
|
|
74
|
+
const progress = (beat - COUNT_IN_BEATS) / (SONG_BEATS - COUNT_IN_BEATS);
|
|
75
|
+
// Leave a breath at the end of every eight-beat phrase.
|
|
76
|
+
if (beat % 8 === 7 && progress < 0.75) continue;
|
|
77
|
+
const lane = pick(previous);
|
|
78
|
+
notes.push({ time: beat * BEAT_SECONDS, lane });
|
|
79
|
+
previous = lane;
|
|
80
|
+
if (progress > 0.7 && next() < 0.3) {
|
|
81
|
+
// A jump: a second paw on the same beat.
|
|
82
|
+
notes.push({ time: beat * BEAT_SECONDS, lane: pick(lane) });
|
|
83
|
+
} else if (progress > 0.3 && next() < 0.4) {
|
|
84
|
+
const between = pick(previous);
|
|
85
|
+
notes.push({ time: (beat + 0.5) * BEAT_SECONDS, lane: between });
|
|
86
|
+
previous = between;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return notes;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function createGame(seed = 1): DanceGame {
|
|
93
|
+
const chart = createChart(seed);
|
|
94
|
+
const judged: (Judgement | null)[] = chart.map(() => null);
|
|
95
|
+
const counts: Record<Judgement, number> = { perfect: 0, great: 0, good: 0, miss: 0 };
|
|
96
|
+
let time = 0, score = 0, combo = 0, bestCombo = 0, firstOpen = 0;
|
|
97
|
+
const view = (index: number): NoteView => ({ ...chart[index]!, index, judged: judged[index] ?? null });
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
get notes() { return chart.map((_, index) => view(index)); },
|
|
101
|
+
get state(): DanceState {
|
|
102
|
+
return { time, score, combo, bestCombo, counts: { ...counts }, finished: time >= SONG_SECONDS };
|
|
103
|
+
},
|
|
104
|
+
advance(next) {
|
|
105
|
+
if (!Number.isFinite(next) || next <= time) return [];
|
|
106
|
+
time = Math.min(next, SONG_SECONDS);
|
|
107
|
+
const missed: NoteView[] = [];
|
|
108
|
+
for (let index = firstOpen; index < chart.length && chart[index]!.time < time - MISS_AFTER; index++) {
|
|
109
|
+
if (judged[index] === null) {
|
|
110
|
+
judged[index] = "miss";
|
|
111
|
+
counts.miss += 1;
|
|
112
|
+
combo = 0;
|
|
113
|
+
missed.push(view(index));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
while (firstOpen < chart.length && judged[firstOpen] !== null) firstOpen++;
|
|
117
|
+
return missed;
|
|
118
|
+
},
|
|
119
|
+
each(from, to, visit) {
|
|
120
|
+
// Binary search for the first note at or after `from`.
|
|
121
|
+
let low = 0, high = chart.length;
|
|
122
|
+
while (low < high) {
|
|
123
|
+
const middle = (low + high) >> 1;
|
|
124
|
+
if (chart[middle]!.time < from) low = middle + 1;
|
|
125
|
+
else high = middle;
|
|
126
|
+
}
|
|
127
|
+
for (let index = low; index < chart.length && chart[index]!.time <= to; index++) visit(chart[index]!, judged[index] ?? null);
|
|
128
|
+
},
|
|
129
|
+
press(lane) {
|
|
130
|
+
if (time >= SONG_SECONDS) return null;
|
|
131
|
+
// The closest unjudged note in this lane, if it is inside the widest window.
|
|
132
|
+
let best = -1, bestOff = Infinity;
|
|
133
|
+
for (let index = firstOpen; index < chart.length && chart[index]!.time <= time + MISS_AFTER; index++) {
|
|
134
|
+
const off = Math.abs(chart[index]!.time - time);
|
|
135
|
+
if (judged[index] === null && chart[index]!.lane === lane && off < bestOff) {
|
|
136
|
+
best = index;
|
|
137
|
+
bestOff = off;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const window = WINDOWS.find(item => bestOff <= item.within);
|
|
141
|
+
if (best < 0 || !window) return null;
|
|
142
|
+
judged[best] = window.judgement;
|
|
143
|
+
counts[window.judgement] += 1;
|
|
144
|
+
combo += 1;
|
|
145
|
+
bestCombo = Math.max(bestCombo, combo);
|
|
146
|
+
// Every ten steps in a row adds 10%, up to double.
|
|
147
|
+
score = Math.min(SCORE_LIMIT, score + Math.round(window.points * Math.min(2, 1 + Math.floor(combo / 10) * 0.1)));
|
|
148
|
+
return view(best);
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<title>Paw Beat</title>
|
|
7
|
+
<style>
|
|
8
|
+
html, body { margin: 0; height: 100%; overflow: hidden; background: #150f24; color: #fff6ea; font: 16px/1.4 system-ui, sans-serif; }
|
|
9
|
+
canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
|
|
10
|
+
.hud { position: fixed; left: 0; right: 0; top: 0; display: flex; gap: 24px; padding: 12px 16px; pointer-events: none; font-weight: 700; text-shadow: 0 1px 2px #000a; }
|
|
11
|
+
.hud span { font-variant-numeric: tabular-nums; font-size: 22px; }
|
|
12
|
+
.hud small { display: block; font-weight: 500; opacity: .7; letter-spacing: .08em; font-size: 11px; }
|
|
13
|
+
#call { position: fixed; left: 0; right: 0; top: 22%; text-align: center; font: 800 40px system-ui, sans-serif; letter-spacing: .04em; pointer-events: none; opacity: 0; text-shadow: 0 2px 8px #000c; }
|
|
14
|
+
#call.show { animation: pop .45s ease-out; }
|
|
15
|
+
#call[data-kind="perfect"] { color: #ffd166; }
|
|
16
|
+
#call[data-kind="great"] { color: #7bd88f; }
|
|
17
|
+
#call[data-kind="good"] { color: #4cc9f0; }
|
|
18
|
+
#call[data-kind="miss"] { color: #ff5c8a; }
|
|
19
|
+
@keyframes pop { 0% { opacity: 1; transform: scale(1.25); } 100% { opacity: 0; transform: scale(1); } }
|
|
20
|
+
@media (prefers-reduced-motion: reduce) { #call.show { animation: none; opacity: 1; } }
|
|
21
|
+
.pads { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 10px; }
|
|
22
|
+
.pads button { margin: 0; padding: 14px 0; border-radius: 14px; border: 2px solid #ffffff38; background: #ffffff14; color: #fff; font: 700 24px system-ui, sans-serif; touch-action: none; }
|
|
23
|
+
.pads button:active, .pads button.down { background: #ffffff40; }
|
|
24
|
+
.card { position: fixed; inset: 0; display: grid; place-items: center; background: #150f24e0; text-align: center; padding: 24px; }
|
|
25
|
+
.card[hidden], .hud[hidden], .pads[hidden] { display: none; }
|
|
26
|
+
.card h1 { font-size: 46px; margin: 0 0 8px; }
|
|
27
|
+
.card p { max-width: 440px; margin: 8px auto; opacity: .85; }
|
|
28
|
+
.card button { margin-top: 16px; border: 0; border-radius: 999px; padding: 14px 30px; font: 700 18px system-ui, sans-serif; background: #ffd166; color: #150f24; cursor: pointer; }
|
|
29
|
+
button:disabled { opacity: .5; cursor: default; }
|
|
30
|
+
button:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
|
|
31
|
+
kbd { padding: 1px 6px; border-radius: 5px; background: #ffffff26; font: inherit; }
|
|
32
|
+
</style>
|
|
33
|
+
</head>
|
|
34
|
+
<body>
|
|
35
|
+
<canvas id="scene" aria-label="Biscuit the cat dancing on a stage, with step arrows moving toward four targets."></canvas>
|
|
36
|
+
<div class="hud" id="hud" hidden>
|
|
37
|
+
<div><small>SCORE</small><span id="score">0</span></div>
|
|
38
|
+
<div><small>COMBO</small><span id="combo">0</span></div>
|
|
39
|
+
<div><small>TIME</small><span id="time">58</span></div>
|
|
40
|
+
</div>
|
|
41
|
+
<div id="call" role="status" aria-live="polite"></div>
|
|
42
|
+
<div class="pads" id="pads" hidden>
|
|
43
|
+
<button type="button" data-lane="left" aria-label="Left step">←</button>
|
|
44
|
+
<button type="button" data-lane="down" aria-label="Down step">↓</button>
|
|
45
|
+
<button type="button" data-lane="up" aria-label="Up step">↑</button>
|
|
46
|
+
<button type="button" data-lane="right" aria-label="Right step">→</button>
|
|
47
|
+
</div>
|
|
48
|
+
<section class="card" id="intro">
|
|
49
|
+
<div>
|
|
50
|
+
<h1>Paw Beat</h1>
|
|
51
|
+
<p>Arrows slide toward the targets. Press the matching key as each one lands: <kbd>←</kbd> <kbd>↓</kbd> <kbd>↑</kbd> <kbd>→</kbd> or <kbd>A</kbd> <kbd>S</kbd> <kbd>W</kbd> <kbd>D</kbd>, or tap the pads. Biscuit dances every step you hit.</p>
|
|
52
|
+
<p id="best"></p>
|
|
53
|
+
<button id="start" type="button" disabled>Connecting…</button>
|
|
54
|
+
</div>
|
|
55
|
+
</section>
|
|
56
|
+
<section class="card" id="done" hidden>
|
|
57
|
+
<div>
|
|
58
|
+
<h1 id="done-score">0</h1>
|
|
59
|
+
<p id="done-note"></p>
|
|
60
|
+
<button id="again" type="button">Dance again</button>
|
|
61
|
+
</div>
|
|
62
|
+
</section>
|
|
63
|
+
<script type="module" src="./game.js"></script>
|
|
64
|
+
</body>
|
|
65
|
+
</html>
|