create-threenative 0.2.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.
- package/README.md +16 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +283 -0
- package/dist/threenative.d.ts +6 -0
- package/dist/threenative.js +757 -0
- package/package.json +44 -0
- package/templates/action-rpg/.mcp.json +16 -0
- package/templates/action-rpg/AGENTS.md +40 -0
- package/templates/action-rpg/CLAUDE.md +42 -0
- package/templates/action-rpg/index.html +13 -0
- package/templates/action-rpg/kit.json +7 -0
- package/templates/action-rpg/package.json +47 -0
- package/templates/action-rpg/playtests/combat.playtest.json +61 -0
- package/templates/action-rpg/playtests/fail.playtest.json +21 -0
- package/templates/action-rpg/playtests/inventory.playtest.json +111 -0
- package/templates/action-rpg/playtests/progress.playtest.json +99 -0
- package/templates/action-rpg/playtests/survives.playtest.json +32 -0
- package/templates/action-rpg/playtests/win.playtest.json +30 -0
- package/templates/action-rpg/public/favicon.svg +5 -0
- package/templates/action-rpg/src/abilities/Ability.ts +45 -0
- package/templates/action-rpg/src/entities/Enemy.ts +143 -0
- package/templates/action-rpg/src/entities/Player.ts +83 -0
- package/templates/action-rpg/src/game.ts +40 -0
- package/templates/action-rpg/src/items/Inventory.ts +163 -0
- package/templates/action-rpg/src/loot/drops.ts +40 -0
- package/templates/action-rpg/src/main.ts +15 -0
- package/templates/action-rpg/src/physics.ts +40 -0
- package/templates/action-rpg/src/playtest-events.ts +15 -0
- package/templates/action-rpg/src/progress.ts +35 -0
- package/templates/action-rpg/src/render/camera.ts +26 -0
- package/templates/action-rpg/src/render/lighting.ts +30 -0
- package/templates/action-rpg/src/render/loading.ts +90 -0
- package/templates/action-rpg/src/render/materials.ts +40 -0
- package/templates/action-rpg/src/render/palette.ts +9 -0
- package/templates/action-rpg/src/render/postprocessing.ts +18 -0
- package/templates/action-rpg/src/render/shapes.ts +110 -0
- package/templates/action-rpg/src/render/sky.ts +18 -0
- package/templates/action-rpg/src/render/types.ts +3 -0
- package/templates/action-rpg/src/scenes/Boot.ts +12 -0
- package/templates/action-rpg/src/scenes/Play.ts +449 -0
- package/templates/action-rpg/src/state.ts +40 -0
- package/templates/action-rpg/src/stats/StatBlock.ts +57 -0
- package/templates/action-rpg/src/style.css +32 -0
- package/templates/action-rpg/src/ui/AbilityBar.tsx +28 -0
- package/templates/action-rpg/src/ui/App.tsx +21 -0
- package/templates/action-rpg/src/ui/CharacterPanel.tsx +31 -0
- package/templates/action-rpg/src/ui/Hud.tsx +29 -0
- package/templates/action-rpg/src/ui/InventoryPanel.tsx +37 -0
- package/templates/action-rpg/tailwind.config.ts +7 -0
- package/templates/action-rpg/threenative.config.ts +29 -0
- package/templates/action-rpg/tsconfig.json +17 -0
- package/templates/action-rpg/vite.config.ts +8 -0
- package/templates/defense/.mcp.json +16 -0
- package/templates/defense/AGENTS.md +53 -0
- package/templates/defense/CLAUDE.md +55 -0
- package/templates/defense/README.md +9 -0
- package/templates/defense/index.html +13 -0
- package/templates/defense/kit.json +7 -0
- package/templates/defense/package.json +46 -0
- package/templates/defense/playtests/leak.playtest.json +18 -0
- package/templates/defense/playtests/placement.playtest.json +40 -0
- package/templates/defense/playtests/scan.playtest.json +20 -0
- package/templates/defense/playtests/survive.playtest.json +26 -0
- package/templates/defense/playtests/survives.playtest.json +36 -0
- package/templates/defense/public/favicon.svg +5 -0
- package/templates/defense/src/attackers/Attacker.ts +104 -0
- package/templates/defense/src/board/Route.ts +80 -0
- package/templates/defense/src/economy.ts +36 -0
- package/templates/defense/src/entities/Player.ts +44 -0
- package/templates/defense/src/game.ts +30 -0
- package/templates/defense/src/main.ts +15 -0
- package/templates/defense/src/physics.ts +43 -0
- package/templates/defense/src/placement/Buildable.ts +49 -0
- package/templates/defense/src/playtest-events.ts +15 -0
- package/templates/defense/src/render/camera.ts +10 -0
- package/templates/defense/src/render/lighting.ts +32 -0
- package/templates/defense/src/render/loading.ts +89 -0
- package/templates/defense/src/render/materials.ts +13 -0
- package/templates/defense/src/render/palette.ts +21 -0
- package/templates/defense/src/render/postprocessing.ts +14 -0
- package/templates/defense/src/render/shapes.ts +89 -0
- package/templates/defense/src/render/sky.ts +45 -0
- package/templates/defense/src/scenes/Boot.ts +12 -0
- package/templates/defense/src/scenes/Defense.ts +165 -0
- package/templates/defense/src/state.ts +50 -0
- package/templates/defense/src/style.css +32 -0
- package/templates/defense/src/towers/Tower.ts +96 -0
- package/templates/defense/src/towers/targeting.ts +53 -0
- package/templates/defense/src/ui/App.tsx +17 -0
- package/templates/defense/src/ui/Hud.tsx +61 -0
- package/templates/defense/src/ui/Menu.tsx +7 -0
- package/templates/defense/src/waves.ts +40 -0
- package/templates/defense/tailwind.config.ts +1 -0
- package/templates/defense/threenative.config.ts +29 -0
- package/templates/defense/tsconfig.json +17 -0
- package/templates/defense/vite.config.ts +5 -0
- package/templates/minimal/.mcp.json +16 -0
- package/templates/minimal/AGENTS.md +400 -0
- package/templates/minimal/CLAUDE.md +402 -0
- package/templates/minimal/assets/.gitkeep +0 -0
- package/templates/minimal/index.html +14 -0
- package/templates/minimal/kit.json +7 -0
- package/templates/minimal/package.json +40 -0
- package/templates/minimal/playtests/play.playtest.json +32 -0
- package/templates/minimal/playtests/survives.playtest.json +32 -0
- package/templates/minimal/public/.gitkeep +0 -0
- package/templates/minimal/public/favicon.svg +4 -0
- package/templates/minimal/public/icon.png +0 -0
- package/templates/minimal/src/entities/Player.ts +66 -0
- package/templates/minimal/src/game.ts +28 -0
- package/templates/minimal/src/main.ts +17 -0
- package/templates/minimal/src/render/camera.ts +11 -0
- package/templates/minimal/src/render/hud.ts +53 -0
- package/templates/minimal/src/render/lighting.ts +46 -0
- package/templates/minimal/src/render/loading.ts +113 -0
- package/templates/minimal/src/render/materials.ts +16 -0
- package/templates/minimal/src/render/palette.ts +9 -0
- package/templates/minimal/src/render/postprocessing.ts +20 -0
- package/templates/minimal/src/render/sky.ts +41 -0
- package/templates/minimal/src/scenes/Boot.ts +5 -0
- package/templates/minimal/src/scenes/Play.ts +65 -0
- package/templates/minimal/src/state.ts +1 -0
- package/templates/minimal/src/style.css +41 -0
- package/templates/minimal/threenative.config.ts +32 -0
- package/templates/minimal/tsconfig.json +16 -0
- package/templates/minimal/vite.config.ts +3 -0
- package/templates/platformer/.mcp.json +16 -0
- package/templates/platformer/AGENTS.md +199 -0
- package/templates/platformer/CLAUDE.md +201 -0
- package/templates/platformer/assets/.gitkeep +0 -0
- package/templates/platformer/index.html +13 -0
- package/templates/platformer/kit.json +7 -0
- package/templates/platformer/package.json +50 -0
- package/templates/platformer/playtests/avoidance.playtest.json +23 -0
- package/templates/platformer/playtests/buffer.playtest.json +17 -0
- package/templates/platformer/playtests/chase.playtest.json +21 -0
- package/templates/platformer/playtests/collect.playtest.json +56 -0
- package/templates/platformer/playtests/collision-layers.playtest.json +36 -0
- package/templates/platformer/playtests/coyote.playtest.json +21 -0
- package/templates/platformer/playtests/damage.playtest.json +31 -0
- package/templates/platformer/playtests/dash.playtest.json +21 -0
- package/templates/platformer/playtests/jump.playtest.json +21 -0
- package/templates/platformer/playtests/oneway.playtest.json +17 -0
- package/templates/platformer/playtests/patrol.playtest.json +13 -0
- package/templates/platformer/playtests/performance.playtest.json +21 -0
- package/templates/platformer/playtests/physics.playtest.json +14 -0
- package/templates/platformer/playtests/respawn.playtest.json +31 -0
- package/templates/platformer/playtests/stomp-rise.playtest.json +41 -0
- package/templates/platformer/playtests/stomp.playtest.json +34 -0
- package/templates/platformer/playtests/survives.playtest.json +32 -0
- package/templates/platformer/playtests/terminal-loop-fail.playtest.json +29 -0
- package/templates/platformer/playtests/terminal-loop-win.playtest.json +52 -0
- package/templates/platformer/public/.gitkeep +0 -0
- package/templates/platformer/public/favicon.svg +4 -0
- package/templates/platformer/public/icon.png +0 -0
- package/templates/platformer/src/entities/Character.ts +218 -0
- package/templates/platformer/src/entities/Chaser.ts +118 -0
- package/templates/platformer/src/entities/Patrol.ts +88 -0
- package/templates/platformer/src/entities/Pickup.ts +72 -0
- package/templates/platformer/src/game.ts +27 -0
- package/templates/platformer/src/level/Checkpoints.ts +66 -0
- package/templates/platformer/src/level/Platform.ts +34 -0
- package/templates/platformer/src/main.ts +14 -0
- package/templates/platformer/src/playtest-events.ts +15 -0
- package/templates/platformer/src/render/camera.ts +8 -0
- package/templates/platformer/src/render/lighting.ts +38 -0
- package/templates/platformer/src/render/loading.ts +113 -0
- package/templates/platformer/src/render/materials.ts +11 -0
- package/templates/platformer/src/render/palette.ts +54 -0
- package/templates/platformer/src/render/postprocessing.ts +18 -0
- package/templates/platformer/src/render/rig.ts +60 -0
- package/templates/platformer/src/render/sky.ts +47 -0
- package/templates/platformer/src/render/terrain.ts +31 -0
- package/templates/platformer/src/render/touch-controls.ts +157 -0
- package/templates/platformer/src/render/touch-layout.ts +63 -0
- package/templates/platformer/src/scenes/Boot.ts +12 -0
- package/templates/platformer/src/scenes/Level.ts +176 -0
- package/templates/platformer/src/state.ts +23 -0
- package/templates/platformer/src/style.css +31 -0
- package/templates/platformer/src/ui/App.tsx +17 -0
- package/templates/platformer/src/ui/Hud.tsx +41 -0
- package/templates/platformer/src/ui/Menu.tsx +7 -0
- package/templates/platformer/tailwind.config.ts +2 -0
- package/templates/platformer/threenative.config.ts +32 -0
- package/templates/platformer/tsconfig.json +17 -0
- package/templates/platformer/vite.config.ts +5 -0
- package/templates/racing/.mcp.json +16 -0
- package/templates/racing/AGENTS.md +48 -0
- package/templates/racing/CLAUDE.md +50 -0
- package/templates/racing/index.html +13 -0
- package/templates/racing/kit.json +7 -0
- package/templates/racing/package.json +46 -0
- package/templates/racing/playtests/boost.playtest.json +45 -0
- package/templates/racing/playtests/outcome.playtest.json +78 -0
- package/templates/racing/playtests/ranking.playtest.json +37 -0
- package/templates/racing/playtests/rescue.playtest.json +28 -0
- package/templates/racing/playtests/reverse.playtest.json +37 -0
- package/templates/racing/playtests/shortcut.playtest.json +44 -0
- package/templates/racing/playtests/survives.playtest.json +32 -0
- package/templates/racing/public/favicon.svg +6 -0
- package/templates/racing/src/entities/RacingCar.ts +114 -0
- package/templates/racing/src/entities/Rival.ts +46 -0
- package/templates/racing/src/game.ts +29 -0
- package/templates/racing/src/kart/boost.ts +38 -0
- package/templates/racing/src/main.ts +15 -0
- package/templates/racing/src/playtest-events.ts +15 -0
- package/templates/racing/src/render/camera.ts +28 -0
- package/templates/racing/src/render/lighting.ts +32 -0
- package/templates/racing/src/render/loading.ts +58 -0
- package/templates/racing/src/render/materials.ts +15 -0
- package/templates/racing/src/render/palette.ts +30 -0
- package/templates/racing/src/render/postprocessing.ts +14 -0
- package/templates/racing/src/render/shapes.ts +37 -0
- package/templates/racing/src/render/sky.ts +45 -0
- package/templates/racing/src/scenes/Boot.ts +12 -0
- package/templates/racing/src/scenes/Race.ts +180 -0
- package/templates/racing/src/state.ts +35 -0
- package/templates/racing/src/style.css +32 -0
- package/templates/racing/src/track/Checkline.ts +19 -0
- package/templates/racing/src/track/Lap.ts +104 -0
- package/templates/racing/src/track/Ranking.ts +35 -0
- package/templates/racing/src/track/Track.ts +229 -0
- package/templates/racing/src/track/TrackSector.ts +77 -0
- package/templates/racing/src/track/rescue.ts +21 -0
- package/templates/racing/src/ui/App.tsx +17 -0
- package/templates/racing/src/ui/Hud.tsx +71 -0
- package/templates/racing/src/ui/Menu.tsx +7 -0
- package/templates/racing/tailwind.config.ts +2 -0
- package/templates/racing/threenative.config.ts +29 -0
- package/templates/racing/tsconfig.json +17 -0
- package/templates/racing/vite.config.ts +5 -0
- package/templates/shooter/.mcp.json +16 -0
- package/templates/shooter/AGENTS.md +69 -0
- package/templates/shooter/CLAUDE.md +71 -0
- package/templates/shooter/index.html +13 -0
- package/templates/shooter/kit.json +7 -0
- package/templates/shooter/package.json +46 -0
- package/templates/shooter/playtests/fail.playtest.json +30 -0
- package/templates/shooter/playtests/shooter.playtest.json +89 -0
- package/templates/shooter/playtests/survives.playtest.json +32 -0
- package/templates/shooter/public/favicon.svg +4 -0
- package/templates/shooter/src/combat/damage.ts +41 -0
- package/templates/shooter/src/entities/Pickup.ts +70 -0
- package/templates/shooter/src/entities/Player.ts +93 -0
- package/templates/shooter/src/entities/Target.ts +103 -0
- package/templates/shooter/src/game.ts +36 -0
- package/templates/shooter/src/level/SpawnPoints.ts +28 -0
- package/templates/shooter/src/main.ts +26 -0
- package/templates/shooter/src/physics.ts +49 -0
- package/templates/shooter/src/playtest-events.ts +15 -0
- package/templates/shooter/src/render/camera.ts +29 -0
- package/templates/shooter/src/render/lighting.ts +38 -0
- package/templates/shooter/src/render/loading.ts +86 -0
- package/templates/shooter/src/render/materials.ts +38 -0
- package/templates/shooter/src/render/palette.ts +9 -0
- package/templates/shooter/src/render/postprocessing.ts +19 -0
- package/templates/shooter/src/render/shapes.ts +194 -0
- package/templates/shooter/src/render/sky.ts +37 -0
- package/templates/shooter/src/render/types.ts +3 -0
- package/templates/shooter/src/render/ui.css +212 -0
- package/templates/shooter/src/render/ui.ts +59 -0
- package/templates/shooter/src/scenes/Boot.ts +12 -0
- package/templates/shooter/src/scenes/Play.ts +428 -0
- package/templates/shooter/src/state.ts +29 -0
- package/templates/shooter/src/ui/App.tsx +25 -0
- package/templates/shooter/src/ui/Hud.tsx +49 -0
- package/templates/shooter/src/ui/Menu.tsx +26 -0
- package/templates/shooter/src/waves.ts +50 -0
- package/templates/shooter/src/weapons/Hitscan.ts +43 -0
- package/templates/shooter/src/weapons/Projectile.ts +76 -0
- package/templates/shooter/tailwind.config.ts +5 -0
- package/templates/shooter/threenative.config.ts +29 -0
- package/templates/shooter/tsconfig.json +17 -0
- package/templates/shooter/vite.config.ts +8 -0
- package/templates/starter/.mcp.json +16 -0
- package/templates/starter/AGENTS.md +450 -0
- package/templates/starter/CLAUDE.md +452 -0
- package/templates/starter/assets/.gitkeep +0 -0
- package/templates/starter/index.html +13 -0
- package/templates/starter/kit.json +7 -0
- package/templates/starter/package.json +49 -0
- package/templates/starter/playtests/buffer.playtest.json +29 -0
- package/templates/starter/playtests/coyote.playtest.json +35 -0
- package/templates/starter/playtests/forward.playtest.json +15 -0
- package/templates/starter/playtests/hot-reload.playtest.json +28 -0
- package/templates/starter/playtests/look.playtest.json +43 -0
- package/templates/starter/playtests/monitoring.playtest.json +41 -0
- package/templates/starter/playtests/pause.playtest.json +33 -0
- package/templates/starter/playtests/play.playtest.json +16 -0
- package/templates/starter/playtests/respawn.playtest.json +28 -0
- package/templates/starter/playtests/restart.playtest.json +36 -0
- package/templates/starter/playtests/seed.playtest.json +18 -0
- package/templates/starter/playtests/survives.playtest.json +32 -0
- package/templates/starter/public/.gitkeep +0 -0
- package/templates/starter/public/favicon.svg +4 -0
- package/templates/starter/public/icon.png +0 -0
- package/templates/starter/public/native-proof.glb +0 -0
- package/templates/starter/public/native-proof.png +0 -0
- package/templates/starter/public/pickup.ogg +0 -0
- package/templates/starter/src/entities/Crate.ts +34 -0
- package/templates/starter/src/entities/Player.ts +80 -0
- package/templates/starter/src/game.ts +30 -0
- package/templates/starter/src/main.ts +15 -0
- package/templates/starter/src/render/camera.ts +57 -0
- package/templates/starter/src/render/lighting.ts +55 -0
- package/templates/starter/src/render/materials.ts +12 -0
- package/templates/starter/src/render/palette.ts +9 -0
- package/templates/starter/src/render/postprocessing.ts +18 -0
- package/templates/starter/src/render/shapes.ts +147 -0
- package/templates/starter/src/render/sky.ts +56 -0
- package/templates/starter/src/scenes/Play.ts +161 -0
- package/templates/starter/src/state.ts +10 -0
- package/templates/starter/src/style.css +45 -0
- package/templates/starter/src/ui/App.tsx +19 -0
- package/templates/starter/src/ui/Hud.tsx +37 -0
- package/templates/starter/src/ui/Menu.tsx +43 -0
- package/templates/starter/tailwind.config.ts +2 -0
- package/templates/starter/threenative.config.ts +31 -0
- package/templates/starter/tsconfig.json +17 -0
- package/templates/starter/vite.config.ts +8 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { IGame } from "@threenative/core";
|
|
2
|
+
import type { IPhysicsContext } from "@threenative/physics";
|
|
3
|
+
import { useGameState } from "@threenative/ui";
|
|
4
|
+
import type { GameState } from "../state.js";
|
|
5
|
+
|
|
6
|
+
export function InventoryPanel({ game }: { game: IGame<GameState, IPhysicsContext> }) {
|
|
7
|
+
const items = useGameState(game, (state) => state.inventory);
|
|
8
|
+
const refused = useGameState(game, (state) => state.inventoryFullRefused);
|
|
9
|
+
const pending = useGameState(game, (state) => state.pendingLoot);
|
|
10
|
+
const seen = new Map<string, number>();
|
|
11
|
+
return (
|
|
12
|
+
<aside className="pointer-events-none absolute bottom-6 right-6 w-64 border border-line bg-panel/90 p-3 text-[10px] uppercase tracking-[0.14em]">
|
|
13
|
+
<div className="flex justify-between text-amber">
|
|
14
|
+
<span>inventory</span>
|
|
15
|
+
<span className="text-dim">{items.length} / 6</span>
|
|
16
|
+
</div>
|
|
17
|
+
<div className="mt-3 space-y-1 text-dim">
|
|
18
|
+
{items.length === 0 && <div>empty</div>}
|
|
19
|
+
{items.map((item) => {
|
|
20
|
+
const occurrence = seen.get(item) ?? 0;
|
|
21
|
+
seen.set(item, occurrence + 1);
|
|
22
|
+
return (
|
|
23
|
+
<div className="border-b border-line/60 pb-1 text-text" key={`${item}-${occurrence}`}>
|
|
24
|
+
{item}
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
})}
|
|
28
|
+
</div>
|
|
29
|
+
{refused === 1 && (
|
|
30
|
+
<div className="mt-2 border border-red px-2 py-1 text-red">
|
|
31
|
+
bag full · loot stays on floor
|
|
32
|
+
</div>
|
|
33
|
+
)}
|
|
34
|
+
{pending !== "" && <div className="mt-2 text-amber">waiting: {pending}</div>}
|
|
35
|
+
</aside>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IThreeNativeConfig } from "@threenative/core";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
app: {
|
|
5
|
+
id: "com.threenative.__PROJECT_ID__",
|
|
6
|
+
name: "__PROJECT_NAME__",
|
|
7
|
+
version: "1.0.0",
|
|
8
|
+
build: 1,
|
|
9
|
+
},
|
|
10
|
+
display: {
|
|
11
|
+
orientation: "landscape",
|
|
12
|
+
fullscreen: true,
|
|
13
|
+
keepScreenOn: true,
|
|
14
|
+
},
|
|
15
|
+
window: {
|
|
16
|
+
title: "__PROJECT_NAME__",
|
|
17
|
+
width: 1280,
|
|
18
|
+
height: 720,
|
|
19
|
+
resizable: true,
|
|
20
|
+
},
|
|
21
|
+
loading: {
|
|
22
|
+
backdropColor: "#080b12",
|
|
23
|
+
trackColor: "#182231",
|
|
24
|
+
progressColor: "#e8b86a",
|
|
25
|
+
showProgressBar: true,
|
|
26
|
+
},
|
|
27
|
+
nativeEntry: "src/game.ts",
|
|
28
|
+
renderer: { preferWebGPU: true },
|
|
29
|
+
} satisfies IThreeNativeConfig;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"types": ["vite/client"],
|
|
9
|
+
"strict": true,
|
|
10
|
+
"noUncheckedIndexedAccess": true,
|
|
11
|
+
"noEmit": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"verbatimModuleSyntax": true,
|
|
14
|
+
"isolatedModules": true
|
|
15
|
+
},
|
|
16
|
+
"include": ["src/**/*.ts", "src/**/*.tsx", "tests/**/*.ts", "*.ts"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mcpServers": {
|
|
3
|
+
"threenative-assets": {
|
|
4
|
+
"command": "node",
|
|
5
|
+
"args": ["./node_modules/threenative-asset-mcp/dist/index.js"],
|
|
6
|
+
"env": {
|
|
7
|
+
"ASSET_DOWNLOAD_DIR": "./public/assets",
|
|
8
|
+
"AUDIO_DOWNLOAD_DIR": "./public/audio"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"threenative-sculpt": {
|
|
12
|
+
"command": "node",
|
|
13
|
+
"args": ["./node_modules/threenative-sculpt-mcp/dist/server.js"]
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# AGENTS.md — __PROJECT_NAME__ defense
|
|
2
|
+
|
|
3
|
+
This project is an editable Three.js tower-defense starter. The framework owns the loop,
|
|
4
|
+
renderer, physics bindings and playtest bridge; this repository owns the route, attackers,
|
|
5
|
+
towers, economy, waves and look.
|
|
6
|
+
|
|
7
|
+
## Commands
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm dev
|
|
11
|
+
pnpm build
|
|
12
|
+
pnpm build --target desktop
|
|
13
|
+
pnpm test
|
|
14
|
+
pnpm typecheck
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The portable entry is `src/game.ts`; React mounting stays in `src/main.ts`. Attackers follow
|
|
18
|
+
the authored route with `PathFollow3D`. This kit deliberately has no navmesh, fog of war,
|
|
19
|
+
marquee selection or tech tree: `@threenative/physics/navigation` carries WASM and would make
|
|
20
|
+
the strategy sample web-only on QuickJS native hosts.
|
|
21
|
+
|
|
22
|
+
`src/placement/Buildable.ts` validates a prospective tower with `directSpaceState.intersectShape`
|
|
23
|
+
before the economy spends anything. `src/towers/Tower.ts` acquires attackers through a jittered
|
|
24
|
+
shape scan and fires on its own reload clock. Change route points in `src/board/Route.ts`, tower
|
|
25
|
+
rules in `src/towers/`, and the wave schedule in `src/waves.ts`.
|
|
26
|
+
|
|
27
|
+
`src/render/` owns the camera, palette, sky, lighting, materials and postprocessing. The HUD is
|
|
28
|
+
`src/ui/Hud.tsx` and there is only one of it: this template used to draw a geometry HUD on top of
|
|
29
|
+
the React one, showing every number twice. A native build has no HUD until you add one. The React
|
|
30
|
+
HUD reads `GameState`; it never reaches into an attacker or tower. Register gameplay
|
|
31
|
+
entities with `ctx.entities` so playtests can observe them and the framework can dispose them.
|
|
32
|
+
|
|
33
|
+
`B` places a tower in the next safe build slot for deterministic playtesting; real games place
|
|
34
|
+
with the primary pointer on the board. `X` attempts the route test slot and `O` repeats the last
|
|
35
|
+
safe slot, making the two placement negative controls reproducible.
|
|
36
|
+
Arrow keys or WASD move the registered command beacon, which is the `player` subject used by the
|
|
37
|
+
durable movement proof.
|
|
38
|
+
|
|
39
|
+
`playtests/survives.playtest.json` is the durable smoke proof. Keep it when replacing the
|
|
40
|
+
defense gameplay; the other `playtests/` scenarios are examples for placement, scanning,
|
|
41
|
+
survival, and leaks.
|
|
42
|
+
|
|
43
|
+
The normal physics API selects the native backend on desktop and Android. Keep source portable:
|
|
44
|
+
do not import React from `src/game.ts`, do not use dynamic `import()`, and do not read a raw
|
|
45
|
+
physics handle. No physical mobile or performance parity claim is made by this template.
|
|
46
|
+
|
|
47
|
+
The asset MCP loop is:
|
|
48
|
+
|
|
49
|
+
1. `asset_search_sources`
|
|
50
|
+
2. `ambientcg_search_assets` / `polyhaven_search_assets` / `audio_search_assets`
|
|
51
|
+
3. `ambientcg_list_files` / `polyhaven_list_files`
|
|
52
|
+
4. `asset_download_file` / `audio_download_asset`
|
|
53
|
+
5. Check returned license and attribution fields before committing an asset.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<!-- Generated mirror of AGENTS.md. Do not edit; edit AGENTS.md. -->
|
|
2
|
+
|
|
3
|
+
# AGENTS.md — __PROJECT_NAME__ defense
|
|
4
|
+
|
|
5
|
+
This project is an editable Three.js tower-defense starter. The framework owns the loop,
|
|
6
|
+
renderer, physics bindings and playtest bridge; this repository owns the route, attackers,
|
|
7
|
+
towers, economy, waves and look.
|
|
8
|
+
|
|
9
|
+
## Commands
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
pnpm dev
|
|
13
|
+
pnpm build
|
|
14
|
+
pnpm build --target desktop
|
|
15
|
+
pnpm test
|
|
16
|
+
pnpm typecheck
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The portable entry is `src/game.ts`; React mounting stays in `src/main.ts`. Attackers follow
|
|
20
|
+
the authored route with `PathFollow3D`. This kit deliberately has no navmesh, fog of war,
|
|
21
|
+
marquee selection or tech tree: `@threenative/physics/navigation` carries WASM and would make
|
|
22
|
+
the strategy sample web-only on QuickJS native hosts.
|
|
23
|
+
|
|
24
|
+
`src/placement/Buildable.ts` validates a prospective tower with `directSpaceState.intersectShape`
|
|
25
|
+
before the economy spends anything. `src/towers/Tower.ts` acquires attackers through a jittered
|
|
26
|
+
shape scan and fires on its own reload clock. Change route points in `src/board/Route.ts`, tower
|
|
27
|
+
rules in `src/towers/`, and the wave schedule in `src/waves.ts`.
|
|
28
|
+
|
|
29
|
+
`src/render/` owns the camera, palette, sky, lighting, materials and postprocessing. The HUD is
|
|
30
|
+
`src/ui/Hud.tsx` and there is only one of it: this template used to draw a geometry HUD on top of
|
|
31
|
+
the React one, showing every number twice. A native build has no HUD until you add one. The React
|
|
32
|
+
HUD reads `GameState`; it never reaches into an attacker or tower. Register gameplay
|
|
33
|
+
entities with `ctx.entities` so playtests can observe them and the framework can dispose them.
|
|
34
|
+
|
|
35
|
+
`B` places a tower in the next safe build slot for deterministic playtesting; real games place
|
|
36
|
+
with the primary pointer on the board. `X` attempts the route test slot and `O` repeats the last
|
|
37
|
+
safe slot, making the two placement negative controls reproducible.
|
|
38
|
+
Arrow keys or WASD move the registered command beacon, which is the `player` subject used by the
|
|
39
|
+
durable movement proof.
|
|
40
|
+
|
|
41
|
+
`playtests/survives.playtest.json` is the durable smoke proof. Keep it when replacing the
|
|
42
|
+
defense gameplay; the other `playtests/` scenarios are examples for placement, scanning,
|
|
43
|
+
survival, and leaks.
|
|
44
|
+
|
|
45
|
+
The normal physics API selects the native backend on desktop and Android. Keep source portable:
|
|
46
|
+
do not import React from `src/game.ts`, do not use dynamic `import()`, and do not read a raw
|
|
47
|
+
physics handle. No physical mobile or performance parity claim is made by this template.
|
|
48
|
+
|
|
49
|
+
The asset MCP loop is:
|
|
50
|
+
|
|
51
|
+
1. `asset_search_sources`
|
|
52
|
+
2. `ambientcg_search_assets` / `polyhaven_search_assets` / `audio_search_assets`
|
|
53
|
+
3. `ambientcg_list_files` / `polyhaven_list_files`
|
|
54
|
+
4. `asset_download_file` / `audio_download_asset`
|
|
55
|
+
5. Check returned license and attribution fields before committing an asset.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Defense starter kit
|
|
2
|
+
|
|
3
|
+
This is a portable tower-defense board: attackers follow an authored route, towers scan and fire,
|
|
4
|
+
and income pays for placement. It deliberately does not use `@threenative/physics/navigation`.
|
|
5
|
+
That package carries a WASM navigation dependency, while the native host runs QuickJS, so this kit
|
|
6
|
+
keeps route following in generated game source and remains eligible for desktop, Android, and iOS.
|
|
7
|
+
|
|
8
|
+
Press `B` to place a tower on a safe build slot. `X` tests route rejection, `O` tests overlap
|
|
9
|
+
rejection, and `R` restarts the wave. Survive ten waves to win; twenty leaks lose the game.
|
|
@@ -0,0 +1,13 @@
|
|
|
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.0" />
|
|
6
|
+
<link rel="icon" href="/favicon.svg" />
|
|
7
|
+
<title>__PROJECT_NAME__</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="root"></div>
|
|
11
|
+
<script type="module" src="/src/main.ts"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__PROJECT_NAME__",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "vite",
|
|
7
|
+
"build": "threenative build",
|
|
8
|
+
"build:web": "threenative build --target web",
|
|
9
|
+
"build:desktop": "threenative build --target desktop",
|
|
10
|
+
"build:android": "threenative build --target android",
|
|
11
|
+
"build:ios": "threenative build --target ios",
|
|
12
|
+
"pretest": "playwright install chromium",
|
|
13
|
+
"test": "vite build && pnpm run test:playtest",
|
|
14
|
+
"test:playtest": "threenative-playtest --scenario playtests/survives.playtest.json --url http://127.0.0.1:4173 --server-command \"pnpm dev --host 127.0.0.1 --port 4173 --strictPort\" --browser-recipe webgpu --headed && threenative-playtest --scenario playtests/placement.playtest.json --url http://127.0.0.1:4173 --server-command \"pnpm dev --host 127.0.0.1 --port 4173 --strictPort\" --browser-recipe webgpu --headed && threenative-playtest --scenario playtests/scan.playtest.json --url http://127.0.0.1:4173 --server-command \"pnpm dev --host 127.0.0.1 --port 4173 --strictPort\" --browser-recipe webgpu --headed && threenative-playtest --scenario playtests/survive.playtest.json --url http://127.0.0.1:4173 --server-command \"pnpm dev --host 127.0.0.1 --port 4173 --strictPort\" --browser-recipe webgpu --headed && threenative-playtest --scenario playtests/leak.playtest.json --url http://127.0.0.1:4173 --server-command \"pnpm dev --host 127.0.0.1 --port 4173 --strictPort\" --browser-recipe webgpu --headed",
|
|
15
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@threenative/core": "0.2.0",
|
|
19
|
+
"@threenative/physics": "0.2.0",
|
|
20
|
+
"@threenative/ui": "0.2.0",
|
|
21
|
+
"react": "19.2.0",
|
|
22
|
+
"react-dom": "19.2.0",
|
|
23
|
+
"three": "0.185.1"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@tailwindcss/vite": "4.3.3",
|
|
27
|
+
"@vitejs/plugin-react": "6.0.5",
|
|
28
|
+
"@threenative/playtest": "0.2.0",
|
|
29
|
+
"@types/react": "19.2.0",
|
|
30
|
+
"@types/react-dom": "19.2.0",
|
|
31
|
+
"@types/three": "0.185.3",
|
|
32
|
+
"create-threenative": "0.2.0",
|
|
33
|
+
"playwright": "1.62.1",
|
|
34
|
+
"tailwindcss": "4.3.3",
|
|
35
|
+
"threenative-asset-mcp": "0.4.0",
|
|
36
|
+
"threenative-sculpt-mcp": "0.1.0",
|
|
37
|
+
"typescript": "5.9.3",
|
|
38
|
+
"vite": "8.2.0"
|
|
39
|
+
},
|
|
40
|
+
"optionalDependencies": {
|
|
41
|
+
"@threenative/runtime-native": "0.2.0"
|
|
42
|
+
},
|
|
43
|
+
"pnpm": {
|
|
44
|
+
"onlyBuiltDependencies": ["@threenative/runtime-native"]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "defense-leak-limit",
|
|
3
|
+
"schemaVersion": 1,
|
|
4
|
+
"target": "web",
|
|
5
|
+
"viewport": { "width": 1280, "height": 720 },
|
|
6
|
+
"warmupFrames": 10,
|
|
7
|
+
"subject": "camera.main",
|
|
8
|
+
"steps": [{ "kind": "wait", "label": "deliberate-leaks", "waitTicks": 1000, "release": true }],
|
|
9
|
+
"assert": {
|
|
10
|
+
"diagnostics": { "noConsoleErrors": true, "runtimeReady": true },
|
|
11
|
+
"resources": [
|
|
12
|
+
{ "id": "GameState", "path": "status", "equals": "LOST", "changed": true },
|
|
13
|
+
{ "id": "GameState", "path": "leaks", "gte": 20, "changed": true },
|
|
14
|
+
{ "id": "GameState", "path": "spent", "equals": 0, "allowTrivial": true },
|
|
15
|
+
{ "id": "GameState", "path": "wave", "gte": 10, "changed": true }
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "defense-placement",
|
|
3
|
+
"schemaVersion": 1,
|
|
4
|
+
"target": "web",
|
|
5
|
+
"viewport": { "width": 1280, "height": 720 },
|
|
6
|
+
"warmupFrames": 10,
|
|
7
|
+
"subject": "tower.0",
|
|
8
|
+
"steps": [
|
|
9
|
+
{ "kind": "input", "label": "built", "press": "KeyB", "holdTicks": 1, "release": true },
|
|
10
|
+
{ "kind": "wait", "label": "income-after-build", "waitTicks": 30, "release": true },
|
|
11
|
+
{ "kind": "input", "label": "route-attempt", "press": "KeyX", "holdTicks": 1, "release": true },
|
|
12
|
+
{
|
|
13
|
+
"kind": "input",
|
|
14
|
+
"label": "overlap-attempt",
|
|
15
|
+
"press": "KeyO",
|
|
16
|
+
"holdTicks": 1,
|
|
17
|
+
"release": true
|
|
18
|
+
},
|
|
19
|
+
{ "kind": "wait", "label": "rejections-settled", "waitTicks": 30, "release": true }
|
|
20
|
+
],
|
|
21
|
+
"assert": {
|
|
22
|
+
"diagnostics": { "noConsoleErrors": true, "runtimeReady": true },
|
|
23
|
+
"resources": [
|
|
24
|
+
{
|
|
25
|
+
"id": "GameState",
|
|
26
|
+
"path": "spent",
|
|
27
|
+
"equals": 40,
|
|
28
|
+
"atSteps": [
|
|
29
|
+
{ "label": "built", "equals": 40 },
|
|
30
|
+
{ "label": "route-attempt", "equals": 40 },
|
|
31
|
+
{ "label": "overlap-attempt", "equals": 40 }
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
{ "id": "GameState", "path": "routeRejects", "gte": 1, "changed": true },
|
|
35
|
+
{ "id": "GameState", "path": "overlapRejects", "gte": 1, "changed": true },
|
|
36
|
+
{ "id": "GameState", "path": "placementRejects", "gte": 2, "changed": true },
|
|
37
|
+
{ "id": "GameState", "path": "scanCount", "gte": 1, "changed": true }
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "defense-scan-interval",
|
|
3
|
+
"schemaVersion": 1,
|
|
4
|
+
"target": "web",
|
|
5
|
+
"viewport": { "width": 1280, "height": 720 },
|
|
6
|
+
"warmupFrames": 10,
|
|
7
|
+
"subject": "tower.0",
|
|
8
|
+
"steps": [
|
|
9
|
+
{ "kind": "input", "label": "build", "press": "KeyB", "holdTicks": 1, "release": true },
|
|
10
|
+
{ "kind": "wait", "label": "scan-window", "waitTicks": 300, "release": true }
|
|
11
|
+
],
|
|
12
|
+
"assert": {
|
|
13
|
+
"diagnostics": { "noConsoleErrors": true, "runtimeReady": true },
|
|
14
|
+
"resources": [
|
|
15
|
+
{ "id": "GameState", "path": "scanWindowFrames", "equals": 300, "changed": true },
|
|
16
|
+
{ "id": "GameState", "path": "scanWindowValid", "equals": true, "changed": true },
|
|
17
|
+
{ "id": "GameState", "path": "scanWindowScans", "gte": 10, "changed": true }
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "defense-survive-ten-waves",
|
|
3
|
+
"schemaVersion": 1,
|
|
4
|
+
"target": "web",
|
|
5
|
+
"viewport": { "width": 1280, "height": 720 },
|
|
6
|
+
"warmupFrames": 10,
|
|
7
|
+
"subject": "tower.0",
|
|
8
|
+
"artifacts": { "screenshots": "before-after" },
|
|
9
|
+
"steps": [
|
|
10
|
+
{ "kind": "input", "label": "tower-one", "press": "KeyB", "holdTicks": 1, "release": true },
|
|
11
|
+
{ "kind": "input", "label": "tower-two", "press": "KeyB", "holdTicks": 1, "release": true },
|
|
12
|
+
{ "kind": "input", "label": "tower-three", "press": "KeyB", "holdTicks": 1, "release": true },
|
|
13
|
+
{ "kind": "wait", "label": "ten-waves", "waitTicks": 1200, "release": true }
|
|
14
|
+
],
|
|
15
|
+
"assert": {
|
|
16
|
+
"diagnostics": { "noConsoleErrors": true, "runtimeReady": true },
|
|
17
|
+
"resources": [
|
|
18
|
+
{ "id": "GameState", "path": "status", "equals": "WON", "changed": true },
|
|
19
|
+
{ "id": "GameState", "path": "wave", "equals": 10, "changed": true },
|
|
20
|
+
{ "id": "GameState", "path": "leaks", "equals": 0, "allowTrivial": true },
|
|
21
|
+
{ "id": "GameState", "path": "defeated", "gte": 10, "changed": true },
|
|
22
|
+
{ "id": "GameState", "path": "spent", "equals": 120, "changed": true },
|
|
23
|
+
{ "id": "GameState", "path": "shots", "gte": 1, "changed": true }
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "survives",
|
|
3
|
+
"target": "web",
|
|
4
|
+
"schemaVersion": 1,
|
|
5
|
+
"viewport": { "width": 1280, "height": 720 },
|
|
6
|
+
"warmupFrames": 40,
|
|
7
|
+
"subject": "player",
|
|
8
|
+
"steps": [
|
|
9
|
+
{ "kind": "input", "label": "move", "press": "ArrowUp", "holdTicks": 60, "release": true },
|
|
10
|
+
{ "kind": "wait", "label": "settle", "waitTicks": 10, "release": true }
|
|
11
|
+
],
|
|
12
|
+
"assert": {
|
|
13
|
+
"diagnostics": {
|
|
14
|
+
"noConsoleErrors": true,
|
|
15
|
+
"noNetworkErrors": true,
|
|
16
|
+
"noRuntimeDiagnostics": true,
|
|
17
|
+
"runtimeReady": true
|
|
18
|
+
},
|
|
19
|
+
"movement": {
|
|
20
|
+
"entity": "player",
|
|
21
|
+
"minDistance": 0.5,
|
|
22
|
+
"minAxisDelta": { "axis": "-z", "min": 0.5 }
|
|
23
|
+
},
|
|
24
|
+
"visual": [
|
|
25
|
+
{
|
|
26
|
+
"region": {
|
|
27
|
+
"x": 0,
|
|
28
|
+
"y": 0,
|
|
29
|
+
"width": 1280,
|
|
30
|
+
"height": 720,
|
|
31
|
+
"minNonblankPixelRatio": 0.01
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { PathFollow3D } from "@threenative/core";
|
|
2
|
+
import { CollisionShape3D } from "@threenative/physics";
|
|
3
|
+
import { type Group, Vector3 } from "three";
|
|
4
|
+
import { ATTACKER_LAYER, type DefensePhysics, createEntityBody } from "../physics.js";
|
|
5
|
+
import { emitPlaytestEvent } from "../playtest-events.js";
|
|
6
|
+
import { attacker as attackerMesh } from "../render/shapes.js";
|
|
7
|
+
|
|
8
|
+
export const ATTACKER_SPEED = 7;
|
|
9
|
+
export const ATTACKER_HEALTH = 4;
|
|
10
|
+
|
|
11
|
+
export class Attacker {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly lateralOffset: number;
|
|
14
|
+
readonly mesh: Group;
|
|
15
|
+
readonly tags = ["attacker", "hostile"];
|
|
16
|
+
readonly #body;
|
|
17
|
+
readonly #path: PathFollow3D;
|
|
18
|
+
#health = ATTACKER_HEALTH;
|
|
19
|
+
#dead = false;
|
|
20
|
+
#escaped = false;
|
|
21
|
+
readonly #onDefeated: () => void;
|
|
22
|
+
readonly #onLeak: () => void;
|
|
23
|
+
|
|
24
|
+
constructor(options: {
|
|
25
|
+
readonly id: string;
|
|
26
|
+
readonly lateralOffset: number;
|
|
27
|
+
readonly pathPoints: readonly Vector3[];
|
|
28
|
+
readonly physics: DefensePhysics;
|
|
29
|
+
readonly onDefeated: () => void;
|
|
30
|
+
readonly onLeak: () => void;
|
|
31
|
+
}) {
|
|
32
|
+
this.id = options.id;
|
|
33
|
+
this.lateralOffset = options.lateralOffset;
|
|
34
|
+
this.#onDefeated = options.onDefeated;
|
|
35
|
+
this.#onLeak = options.onLeak;
|
|
36
|
+
this.#path = new PathFollow3D({ points: options.pathPoints, speed: ATTACKER_SPEED });
|
|
37
|
+
this.mesh = attackerMesh();
|
|
38
|
+
this.#place(this.lateralOffset);
|
|
39
|
+
this.#body = createEntityBody({
|
|
40
|
+
collisionLayer: ATTACKER_LAYER,
|
|
41
|
+
collisionMask: 0,
|
|
42
|
+
entity: this.id,
|
|
43
|
+
object: this.mesh,
|
|
44
|
+
physics: options.physics,
|
|
45
|
+
shape: CollisionShape3D.sphere(0.42),
|
|
46
|
+
type: "kinematic",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get dead(): boolean {
|
|
51
|
+
return this.#dead;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get escaped(): boolean {
|
|
55
|
+
return this.#escaped;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
takeDamage(amount: number): void {
|
|
59
|
+
if (this.#dead || this.#escaped) return;
|
|
60
|
+
if (!Number.isFinite(amount) || amount <= 0)
|
|
61
|
+
throw new Error("Attacker damage must be positive.");
|
|
62
|
+
this.#health = Math.max(0, this.#health - amount);
|
|
63
|
+
if (this.#health > 0) return;
|
|
64
|
+
this.#dead = true;
|
|
65
|
+
this.mesh.visible = false;
|
|
66
|
+
this.#onDefeated();
|
|
67
|
+
emitPlaytestEvent({ entity: this.id, name: "defeated" });
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
update(dt: number): void {
|
|
71
|
+
if (this.#dead || this.#escaped) return;
|
|
72
|
+
const sample = this.#path.advance(dt);
|
|
73
|
+
this.#place(this.lateralOffset, sample.point, sample.tangent);
|
|
74
|
+
if (!this.#path.completed) return;
|
|
75
|
+
this.#escaped = true;
|
|
76
|
+
this.mesh.visible = false;
|
|
77
|
+
this.#onLeak();
|
|
78
|
+
emitPlaytestEvent({ entity: this.id, name: "leaked" });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
debug(): Record<string, unknown> {
|
|
82
|
+
return {
|
|
83
|
+
health: this.#health,
|
|
84
|
+
position: this.mesh.position.toArray(),
|
|
85
|
+
progress: this.#path.progress,
|
|
86
|
+
reachedBase: this.#escaped,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
dispose(): void {
|
|
91
|
+
this.#body.dispose();
|
|
92
|
+
this.mesh.removeFromParent();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#place(
|
|
96
|
+
lateralOffset: number,
|
|
97
|
+
point = this.#path.sample().point,
|
|
98
|
+
tangent = this.#path.sample().tangent,
|
|
99
|
+
): void {
|
|
100
|
+
const side = new Vector3(-tangent.z, 0, tangent.x).normalize();
|
|
101
|
+
this.mesh.position.copy(point).addScaledVector(side, lateralOffset).setY(0);
|
|
102
|
+
this.mesh.rotation.y = Math.atan2(tangent.x, tangent.z);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { CollisionShape3D } from "@threenative/physics";
|
|
2
|
+
import { type Object3D, Vector3 } from "three";
|
|
3
|
+
import { type DefensePhysics, GROUND_LAYER, ROUTE_LAYER, createEntityBody } from "../physics.js";
|
|
4
|
+
import { base, board, routeSegment } from "../render/shapes.js";
|
|
5
|
+
|
|
6
|
+
export const ROUTE_POINTS = [
|
|
7
|
+
new Vector3(-11, 0, -6),
|
|
8
|
+
new Vector3(-5, 0, -6),
|
|
9
|
+
new Vector3(-5, 0, 0),
|
|
10
|
+
new Vector3(2, 0, 0),
|
|
11
|
+
new Vector3(2, 0, 6),
|
|
12
|
+
new Vector3(11, 0, 6),
|
|
13
|
+
] as const;
|
|
14
|
+
|
|
15
|
+
export const SAFE_BUILD_SLOTS = [
|
|
16
|
+
new Vector3(-8.3, 0, -3.8),
|
|
17
|
+
new Vector3(-2.3, 0, -3.8),
|
|
18
|
+
new Vector3(-2.3, 0, 3.8),
|
|
19
|
+
new Vector3(6.2, 0, 3.8),
|
|
20
|
+
] as const;
|
|
21
|
+
|
|
22
|
+
export const ROUTE_TEST_SLOT = new Vector3(-8, 0, -6);
|
|
23
|
+
|
|
24
|
+
interface IRouteContext {
|
|
25
|
+
readonly add: (object: Object3D) => Object3D;
|
|
26
|
+
readonly physics: DefensePhysics;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class RouteBoard {
|
|
30
|
+
readonly points = ROUTE_POINTS.map((point) => point.clone());
|
|
31
|
+
readonly surface: Object3D;
|
|
32
|
+
readonly #bodies = [] as ReturnType<typeof createEntityBody>[];
|
|
33
|
+
|
|
34
|
+
constructor(ctx: IRouteContext) {
|
|
35
|
+
this.surface = board();
|
|
36
|
+
ctx.add(this.surface);
|
|
37
|
+
this.#bodies.push(
|
|
38
|
+
createEntityBody({
|
|
39
|
+
collisionLayer: GROUND_LAYER,
|
|
40
|
+
collisionMask: 0xffff,
|
|
41
|
+
entity: "ground",
|
|
42
|
+
object: this.surface,
|
|
43
|
+
physics: ctx.physics,
|
|
44
|
+
shape: CollisionShape3D.box(28, 0.2, 20),
|
|
45
|
+
type: "fixed",
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
for (let index = 0; index < this.points.length - 1; index += 1) {
|
|
49
|
+
const from = this.points[index];
|
|
50
|
+
const to = this.points[index + 1];
|
|
51
|
+
if (from === undefined || to === undefined) continue;
|
|
52
|
+
const midpoint = from.clone().add(to).multiplyScalar(0.5);
|
|
53
|
+
const delta = to.clone().sub(from);
|
|
54
|
+
const length = Math.max(delta.x, delta.z, -delta.x, -delta.z);
|
|
55
|
+
const visual = routeSegment(length, 2.1);
|
|
56
|
+
visual.position.copy(midpoint);
|
|
57
|
+
visual.rotation.y = Math.abs(delta.z) > Math.abs(delta.x) ? Math.PI / 2 : 0;
|
|
58
|
+
ctx.add(visual);
|
|
59
|
+
this.#bodies.push(
|
|
60
|
+
createEntityBody({
|
|
61
|
+
collisionLayer: ROUTE_LAYER,
|
|
62
|
+
collisionMask: 0xffff,
|
|
63
|
+
entity: `route.${index}`,
|
|
64
|
+
object: visual,
|
|
65
|
+
physics: ctx.physics,
|
|
66
|
+
shape: CollisionShape3D.box(length, 0.3, 2.1),
|
|
67
|
+
type: "fixed",
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
const goal = base();
|
|
72
|
+
goal.position.copy(this.points.at(-1) ?? new Vector3());
|
|
73
|
+
ctx.add(goal);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
dispose(): void {
|
|
77
|
+
for (const body of this.#bodies) body.dispose();
|
|
78
|
+
this.surface.removeFromParent();
|
|
79
|
+
}
|
|
80
|
+
}
|