meshpad 0.0.0 → 0.1.0

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.
@@ -0,0 +1,67 @@
1
+ import { createGame, THREE, type LevelContext, type LevelHooks } from 'meshpad';
2
+
3
+ createGame({
4
+ title: 'Hello, world',
5
+ failure: { type: 'time', seconds: 20 },
6
+ levels: [
7
+ { name: 'Hello, world', setup: (context) => createLevel(context, 3, 0xf9c203) },
8
+ { name: 'A little quicker', setup: (context) => createLevel(context, 5, 0xf02b1f) },
9
+ { name: 'One last spin', setup: (context) => createLevel(context, 7, 0x09a8f8) },
10
+ ],
11
+ });
12
+
13
+ function createLevel(
14
+ context: LevelContext,
15
+ target: number,
16
+ color: THREE.ColorRepresentation,
17
+ ): LevelHooks {
18
+ const { scene, camera, win } = context;
19
+ camera.position.set(4.8, 5.2, 8);
20
+ camera.lookAt(0, 0.35, 0);
21
+
22
+ const cube = new THREE.Mesh(
23
+ new THREE.BoxGeometry(1.55, 1.55, 1.55, 1, 1, 1),
24
+ new THREE.MeshStandardMaterial({ color, roughness: 0.25, metalness: 0.15 }),
25
+ );
26
+ cube.position.y = 0.35;
27
+ scene.add(cube);
28
+
29
+ const platform = new THREE.Mesh(
30
+ new THREE.CylinderGeometry(2.5, 2.7, 0.35, 64),
31
+ new THREE.MeshStandardMaterial({ color: 0x4a40aa, roughness: 0.7 }),
32
+ );
33
+ platform.position.y = -1;
34
+ scene.add(platform);
35
+
36
+ const ring = new THREE.Mesh(
37
+ new THREE.TorusGeometry(2.25, 0.018, 8, 80),
38
+ new THREE.MeshBasicMaterial({ color }),
39
+ );
40
+ ring.rotation.x = -Math.PI / 2;
41
+ ring.position.y = -0.81;
42
+ scene.add(ring);
43
+
44
+ const grid = new THREE.GridHelper(30, 30, 0x3a3388, 0x2e2868);
45
+ grid.position.y = -1.19;
46
+ scene.add(grid);
47
+ scene.fog = new THREE.Fog(0x221e4e, 12, 28);
48
+
49
+ let taps = 0;
50
+ let spin = 0;
51
+
52
+ return {
53
+ debug: () => ({ taps, target, timeLeft: context.failure.remaining }),
54
+ update(dt, elapsed) {
55
+ cube.rotation.y += dt * (0.3 + spin);
56
+ cube.rotation.z = Math.sin(elapsed * 0.7) * 0.08;
57
+ cube.position.y = 0.35 + Math.sin(elapsed * 1.8) * 0.12;
58
+ spin *= Math.exp(-dt * 3);
59
+ },
60
+ pointer({ type, hits }) {
61
+ if (type !== 'pointerdown' || hits([cube]).length === 0) return;
62
+ taps += 1;
63
+ spin = 9;
64
+ if (taps >= target) win();
65
+ },
66
+ };
67
+ }
package/three.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from 'three';
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
+ "strict": true,
8
+ "noEmit": true,
9
+ "allowJs": false,
10
+ "isolatedModules": true,
11
+ "verbatimModuleSyntax": true,
12
+ "allowImportingTsExtensions": true,
13
+ "resolveJsonModule": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "skipLibCheck": true
16
+ }
17
+ }