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.
Files changed (320) hide show
  1. package/README.md +16 -0
  2. package/dist/index.d.ts +30 -0
  3. package/dist/index.js +283 -0
  4. package/dist/threenative.d.ts +6 -0
  5. package/dist/threenative.js +757 -0
  6. package/package.json +44 -0
  7. package/templates/action-rpg/.mcp.json +16 -0
  8. package/templates/action-rpg/AGENTS.md +40 -0
  9. package/templates/action-rpg/CLAUDE.md +42 -0
  10. package/templates/action-rpg/index.html +13 -0
  11. package/templates/action-rpg/kit.json +7 -0
  12. package/templates/action-rpg/package.json +47 -0
  13. package/templates/action-rpg/playtests/combat.playtest.json +61 -0
  14. package/templates/action-rpg/playtests/fail.playtest.json +21 -0
  15. package/templates/action-rpg/playtests/inventory.playtest.json +111 -0
  16. package/templates/action-rpg/playtests/progress.playtest.json +99 -0
  17. package/templates/action-rpg/playtests/survives.playtest.json +32 -0
  18. package/templates/action-rpg/playtests/win.playtest.json +30 -0
  19. package/templates/action-rpg/public/favicon.svg +5 -0
  20. package/templates/action-rpg/src/abilities/Ability.ts +45 -0
  21. package/templates/action-rpg/src/entities/Enemy.ts +143 -0
  22. package/templates/action-rpg/src/entities/Player.ts +83 -0
  23. package/templates/action-rpg/src/game.ts +40 -0
  24. package/templates/action-rpg/src/items/Inventory.ts +163 -0
  25. package/templates/action-rpg/src/loot/drops.ts +40 -0
  26. package/templates/action-rpg/src/main.ts +15 -0
  27. package/templates/action-rpg/src/physics.ts +40 -0
  28. package/templates/action-rpg/src/playtest-events.ts +15 -0
  29. package/templates/action-rpg/src/progress.ts +35 -0
  30. package/templates/action-rpg/src/render/camera.ts +26 -0
  31. package/templates/action-rpg/src/render/lighting.ts +30 -0
  32. package/templates/action-rpg/src/render/loading.ts +90 -0
  33. package/templates/action-rpg/src/render/materials.ts +40 -0
  34. package/templates/action-rpg/src/render/palette.ts +9 -0
  35. package/templates/action-rpg/src/render/postprocessing.ts +18 -0
  36. package/templates/action-rpg/src/render/shapes.ts +110 -0
  37. package/templates/action-rpg/src/render/sky.ts +18 -0
  38. package/templates/action-rpg/src/render/types.ts +3 -0
  39. package/templates/action-rpg/src/scenes/Boot.ts +12 -0
  40. package/templates/action-rpg/src/scenes/Play.ts +449 -0
  41. package/templates/action-rpg/src/state.ts +40 -0
  42. package/templates/action-rpg/src/stats/StatBlock.ts +57 -0
  43. package/templates/action-rpg/src/style.css +32 -0
  44. package/templates/action-rpg/src/ui/AbilityBar.tsx +28 -0
  45. package/templates/action-rpg/src/ui/App.tsx +21 -0
  46. package/templates/action-rpg/src/ui/CharacterPanel.tsx +31 -0
  47. package/templates/action-rpg/src/ui/Hud.tsx +29 -0
  48. package/templates/action-rpg/src/ui/InventoryPanel.tsx +37 -0
  49. package/templates/action-rpg/tailwind.config.ts +7 -0
  50. package/templates/action-rpg/threenative.config.ts +29 -0
  51. package/templates/action-rpg/tsconfig.json +17 -0
  52. package/templates/action-rpg/vite.config.ts +8 -0
  53. package/templates/defense/.mcp.json +16 -0
  54. package/templates/defense/AGENTS.md +53 -0
  55. package/templates/defense/CLAUDE.md +55 -0
  56. package/templates/defense/README.md +9 -0
  57. package/templates/defense/index.html +13 -0
  58. package/templates/defense/kit.json +7 -0
  59. package/templates/defense/package.json +46 -0
  60. package/templates/defense/playtests/leak.playtest.json +18 -0
  61. package/templates/defense/playtests/placement.playtest.json +40 -0
  62. package/templates/defense/playtests/scan.playtest.json +20 -0
  63. package/templates/defense/playtests/survive.playtest.json +26 -0
  64. package/templates/defense/playtests/survives.playtest.json +36 -0
  65. package/templates/defense/public/favicon.svg +5 -0
  66. package/templates/defense/src/attackers/Attacker.ts +104 -0
  67. package/templates/defense/src/board/Route.ts +80 -0
  68. package/templates/defense/src/economy.ts +36 -0
  69. package/templates/defense/src/entities/Player.ts +44 -0
  70. package/templates/defense/src/game.ts +30 -0
  71. package/templates/defense/src/main.ts +15 -0
  72. package/templates/defense/src/physics.ts +43 -0
  73. package/templates/defense/src/placement/Buildable.ts +49 -0
  74. package/templates/defense/src/playtest-events.ts +15 -0
  75. package/templates/defense/src/render/camera.ts +10 -0
  76. package/templates/defense/src/render/lighting.ts +32 -0
  77. package/templates/defense/src/render/loading.ts +89 -0
  78. package/templates/defense/src/render/materials.ts +13 -0
  79. package/templates/defense/src/render/palette.ts +21 -0
  80. package/templates/defense/src/render/postprocessing.ts +14 -0
  81. package/templates/defense/src/render/shapes.ts +89 -0
  82. package/templates/defense/src/render/sky.ts +45 -0
  83. package/templates/defense/src/scenes/Boot.ts +12 -0
  84. package/templates/defense/src/scenes/Defense.ts +165 -0
  85. package/templates/defense/src/state.ts +50 -0
  86. package/templates/defense/src/style.css +32 -0
  87. package/templates/defense/src/towers/Tower.ts +96 -0
  88. package/templates/defense/src/towers/targeting.ts +53 -0
  89. package/templates/defense/src/ui/App.tsx +17 -0
  90. package/templates/defense/src/ui/Hud.tsx +61 -0
  91. package/templates/defense/src/ui/Menu.tsx +7 -0
  92. package/templates/defense/src/waves.ts +40 -0
  93. package/templates/defense/tailwind.config.ts +1 -0
  94. package/templates/defense/threenative.config.ts +29 -0
  95. package/templates/defense/tsconfig.json +17 -0
  96. package/templates/defense/vite.config.ts +5 -0
  97. package/templates/minimal/.mcp.json +16 -0
  98. package/templates/minimal/AGENTS.md +400 -0
  99. package/templates/minimal/CLAUDE.md +402 -0
  100. package/templates/minimal/assets/.gitkeep +0 -0
  101. package/templates/minimal/index.html +14 -0
  102. package/templates/minimal/kit.json +7 -0
  103. package/templates/minimal/package.json +40 -0
  104. package/templates/minimal/playtests/play.playtest.json +32 -0
  105. package/templates/minimal/playtests/survives.playtest.json +32 -0
  106. package/templates/minimal/public/.gitkeep +0 -0
  107. package/templates/minimal/public/favicon.svg +4 -0
  108. package/templates/minimal/public/icon.png +0 -0
  109. package/templates/minimal/src/entities/Player.ts +66 -0
  110. package/templates/minimal/src/game.ts +28 -0
  111. package/templates/minimal/src/main.ts +17 -0
  112. package/templates/minimal/src/render/camera.ts +11 -0
  113. package/templates/minimal/src/render/hud.ts +53 -0
  114. package/templates/minimal/src/render/lighting.ts +46 -0
  115. package/templates/minimal/src/render/loading.ts +113 -0
  116. package/templates/minimal/src/render/materials.ts +16 -0
  117. package/templates/minimal/src/render/palette.ts +9 -0
  118. package/templates/minimal/src/render/postprocessing.ts +20 -0
  119. package/templates/minimal/src/render/sky.ts +41 -0
  120. package/templates/minimal/src/scenes/Boot.ts +5 -0
  121. package/templates/minimal/src/scenes/Play.ts +65 -0
  122. package/templates/minimal/src/state.ts +1 -0
  123. package/templates/minimal/src/style.css +41 -0
  124. package/templates/minimal/threenative.config.ts +32 -0
  125. package/templates/minimal/tsconfig.json +16 -0
  126. package/templates/minimal/vite.config.ts +3 -0
  127. package/templates/platformer/.mcp.json +16 -0
  128. package/templates/platformer/AGENTS.md +199 -0
  129. package/templates/platformer/CLAUDE.md +201 -0
  130. package/templates/platformer/assets/.gitkeep +0 -0
  131. package/templates/platformer/index.html +13 -0
  132. package/templates/platformer/kit.json +7 -0
  133. package/templates/platformer/package.json +50 -0
  134. package/templates/platformer/playtests/avoidance.playtest.json +23 -0
  135. package/templates/platformer/playtests/buffer.playtest.json +17 -0
  136. package/templates/platformer/playtests/chase.playtest.json +21 -0
  137. package/templates/platformer/playtests/collect.playtest.json +56 -0
  138. package/templates/platformer/playtests/collision-layers.playtest.json +36 -0
  139. package/templates/platformer/playtests/coyote.playtest.json +21 -0
  140. package/templates/platformer/playtests/damage.playtest.json +31 -0
  141. package/templates/platformer/playtests/dash.playtest.json +21 -0
  142. package/templates/platformer/playtests/jump.playtest.json +21 -0
  143. package/templates/platformer/playtests/oneway.playtest.json +17 -0
  144. package/templates/platformer/playtests/patrol.playtest.json +13 -0
  145. package/templates/platformer/playtests/performance.playtest.json +21 -0
  146. package/templates/platformer/playtests/physics.playtest.json +14 -0
  147. package/templates/platformer/playtests/respawn.playtest.json +31 -0
  148. package/templates/platformer/playtests/stomp-rise.playtest.json +41 -0
  149. package/templates/platformer/playtests/stomp.playtest.json +34 -0
  150. package/templates/platformer/playtests/survives.playtest.json +32 -0
  151. package/templates/platformer/playtests/terminal-loop-fail.playtest.json +29 -0
  152. package/templates/platformer/playtests/terminal-loop-win.playtest.json +52 -0
  153. package/templates/platformer/public/.gitkeep +0 -0
  154. package/templates/platformer/public/favicon.svg +4 -0
  155. package/templates/platformer/public/icon.png +0 -0
  156. package/templates/platformer/src/entities/Character.ts +218 -0
  157. package/templates/platformer/src/entities/Chaser.ts +118 -0
  158. package/templates/platformer/src/entities/Patrol.ts +88 -0
  159. package/templates/platformer/src/entities/Pickup.ts +72 -0
  160. package/templates/platformer/src/game.ts +27 -0
  161. package/templates/platformer/src/level/Checkpoints.ts +66 -0
  162. package/templates/platformer/src/level/Platform.ts +34 -0
  163. package/templates/platformer/src/main.ts +14 -0
  164. package/templates/platformer/src/playtest-events.ts +15 -0
  165. package/templates/platformer/src/render/camera.ts +8 -0
  166. package/templates/platformer/src/render/lighting.ts +38 -0
  167. package/templates/platformer/src/render/loading.ts +113 -0
  168. package/templates/platformer/src/render/materials.ts +11 -0
  169. package/templates/platformer/src/render/palette.ts +54 -0
  170. package/templates/platformer/src/render/postprocessing.ts +18 -0
  171. package/templates/platformer/src/render/rig.ts +60 -0
  172. package/templates/platformer/src/render/sky.ts +47 -0
  173. package/templates/platformer/src/render/terrain.ts +31 -0
  174. package/templates/platformer/src/render/touch-controls.ts +157 -0
  175. package/templates/platformer/src/render/touch-layout.ts +63 -0
  176. package/templates/platformer/src/scenes/Boot.ts +12 -0
  177. package/templates/platformer/src/scenes/Level.ts +176 -0
  178. package/templates/platformer/src/state.ts +23 -0
  179. package/templates/platformer/src/style.css +31 -0
  180. package/templates/platformer/src/ui/App.tsx +17 -0
  181. package/templates/platformer/src/ui/Hud.tsx +41 -0
  182. package/templates/platformer/src/ui/Menu.tsx +7 -0
  183. package/templates/platformer/tailwind.config.ts +2 -0
  184. package/templates/platformer/threenative.config.ts +32 -0
  185. package/templates/platformer/tsconfig.json +17 -0
  186. package/templates/platformer/vite.config.ts +5 -0
  187. package/templates/racing/.mcp.json +16 -0
  188. package/templates/racing/AGENTS.md +48 -0
  189. package/templates/racing/CLAUDE.md +50 -0
  190. package/templates/racing/index.html +13 -0
  191. package/templates/racing/kit.json +7 -0
  192. package/templates/racing/package.json +46 -0
  193. package/templates/racing/playtests/boost.playtest.json +45 -0
  194. package/templates/racing/playtests/outcome.playtest.json +78 -0
  195. package/templates/racing/playtests/ranking.playtest.json +37 -0
  196. package/templates/racing/playtests/rescue.playtest.json +28 -0
  197. package/templates/racing/playtests/reverse.playtest.json +37 -0
  198. package/templates/racing/playtests/shortcut.playtest.json +44 -0
  199. package/templates/racing/playtests/survives.playtest.json +32 -0
  200. package/templates/racing/public/favicon.svg +6 -0
  201. package/templates/racing/src/entities/RacingCar.ts +114 -0
  202. package/templates/racing/src/entities/Rival.ts +46 -0
  203. package/templates/racing/src/game.ts +29 -0
  204. package/templates/racing/src/kart/boost.ts +38 -0
  205. package/templates/racing/src/main.ts +15 -0
  206. package/templates/racing/src/playtest-events.ts +15 -0
  207. package/templates/racing/src/render/camera.ts +28 -0
  208. package/templates/racing/src/render/lighting.ts +32 -0
  209. package/templates/racing/src/render/loading.ts +58 -0
  210. package/templates/racing/src/render/materials.ts +15 -0
  211. package/templates/racing/src/render/palette.ts +30 -0
  212. package/templates/racing/src/render/postprocessing.ts +14 -0
  213. package/templates/racing/src/render/shapes.ts +37 -0
  214. package/templates/racing/src/render/sky.ts +45 -0
  215. package/templates/racing/src/scenes/Boot.ts +12 -0
  216. package/templates/racing/src/scenes/Race.ts +180 -0
  217. package/templates/racing/src/state.ts +35 -0
  218. package/templates/racing/src/style.css +32 -0
  219. package/templates/racing/src/track/Checkline.ts +19 -0
  220. package/templates/racing/src/track/Lap.ts +104 -0
  221. package/templates/racing/src/track/Ranking.ts +35 -0
  222. package/templates/racing/src/track/Track.ts +229 -0
  223. package/templates/racing/src/track/TrackSector.ts +77 -0
  224. package/templates/racing/src/track/rescue.ts +21 -0
  225. package/templates/racing/src/ui/App.tsx +17 -0
  226. package/templates/racing/src/ui/Hud.tsx +71 -0
  227. package/templates/racing/src/ui/Menu.tsx +7 -0
  228. package/templates/racing/tailwind.config.ts +2 -0
  229. package/templates/racing/threenative.config.ts +29 -0
  230. package/templates/racing/tsconfig.json +17 -0
  231. package/templates/racing/vite.config.ts +5 -0
  232. package/templates/shooter/.mcp.json +16 -0
  233. package/templates/shooter/AGENTS.md +69 -0
  234. package/templates/shooter/CLAUDE.md +71 -0
  235. package/templates/shooter/index.html +13 -0
  236. package/templates/shooter/kit.json +7 -0
  237. package/templates/shooter/package.json +46 -0
  238. package/templates/shooter/playtests/fail.playtest.json +30 -0
  239. package/templates/shooter/playtests/shooter.playtest.json +89 -0
  240. package/templates/shooter/playtests/survives.playtest.json +32 -0
  241. package/templates/shooter/public/favicon.svg +4 -0
  242. package/templates/shooter/src/combat/damage.ts +41 -0
  243. package/templates/shooter/src/entities/Pickup.ts +70 -0
  244. package/templates/shooter/src/entities/Player.ts +93 -0
  245. package/templates/shooter/src/entities/Target.ts +103 -0
  246. package/templates/shooter/src/game.ts +36 -0
  247. package/templates/shooter/src/level/SpawnPoints.ts +28 -0
  248. package/templates/shooter/src/main.ts +26 -0
  249. package/templates/shooter/src/physics.ts +49 -0
  250. package/templates/shooter/src/playtest-events.ts +15 -0
  251. package/templates/shooter/src/render/camera.ts +29 -0
  252. package/templates/shooter/src/render/lighting.ts +38 -0
  253. package/templates/shooter/src/render/loading.ts +86 -0
  254. package/templates/shooter/src/render/materials.ts +38 -0
  255. package/templates/shooter/src/render/palette.ts +9 -0
  256. package/templates/shooter/src/render/postprocessing.ts +19 -0
  257. package/templates/shooter/src/render/shapes.ts +194 -0
  258. package/templates/shooter/src/render/sky.ts +37 -0
  259. package/templates/shooter/src/render/types.ts +3 -0
  260. package/templates/shooter/src/render/ui.css +212 -0
  261. package/templates/shooter/src/render/ui.ts +59 -0
  262. package/templates/shooter/src/scenes/Boot.ts +12 -0
  263. package/templates/shooter/src/scenes/Play.ts +428 -0
  264. package/templates/shooter/src/state.ts +29 -0
  265. package/templates/shooter/src/ui/App.tsx +25 -0
  266. package/templates/shooter/src/ui/Hud.tsx +49 -0
  267. package/templates/shooter/src/ui/Menu.tsx +26 -0
  268. package/templates/shooter/src/waves.ts +50 -0
  269. package/templates/shooter/src/weapons/Hitscan.ts +43 -0
  270. package/templates/shooter/src/weapons/Projectile.ts +76 -0
  271. package/templates/shooter/tailwind.config.ts +5 -0
  272. package/templates/shooter/threenative.config.ts +29 -0
  273. package/templates/shooter/tsconfig.json +17 -0
  274. package/templates/shooter/vite.config.ts +8 -0
  275. package/templates/starter/.mcp.json +16 -0
  276. package/templates/starter/AGENTS.md +450 -0
  277. package/templates/starter/CLAUDE.md +452 -0
  278. package/templates/starter/assets/.gitkeep +0 -0
  279. package/templates/starter/index.html +13 -0
  280. package/templates/starter/kit.json +7 -0
  281. package/templates/starter/package.json +49 -0
  282. package/templates/starter/playtests/buffer.playtest.json +29 -0
  283. package/templates/starter/playtests/coyote.playtest.json +35 -0
  284. package/templates/starter/playtests/forward.playtest.json +15 -0
  285. package/templates/starter/playtests/hot-reload.playtest.json +28 -0
  286. package/templates/starter/playtests/look.playtest.json +43 -0
  287. package/templates/starter/playtests/monitoring.playtest.json +41 -0
  288. package/templates/starter/playtests/pause.playtest.json +33 -0
  289. package/templates/starter/playtests/play.playtest.json +16 -0
  290. package/templates/starter/playtests/respawn.playtest.json +28 -0
  291. package/templates/starter/playtests/restart.playtest.json +36 -0
  292. package/templates/starter/playtests/seed.playtest.json +18 -0
  293. package/templates/starter/playtests/survives.playtest.json +32 -0
  294. package/templates/starter/public/.gitkeep +0 -0
  295. package/templates/starter/public/favicon.svg +4 -0
  296. package/templates/starter/public/icon.png +0 -0
  297. package/templates/starter/public/native-proof.glb +0 -0
  298. package/templates/starter/public/native-proof.png +0 -0
  299. package/templates/starter/public/pickup.ogg +0 -0
  300. package/templates/starter/src/entities/Crate.ts +34 -0
  301. package/templates/starter/src/entities/Player.ts +80 -0
  302. package/templates/starter/src/game.ts +30 -0
  303. package/templates/starter/src/main.ts +15 -0
  304. package/templates/starter/src/render/camera.ts +57 -0
  305. package/templates/starter/src/render/lighting.ts +55 -0
  306. package/templates/starter/src/render/materials.ts +12 -0
  307. package/templates/starter/src/render/palette.ts +9 -0
  308. package/templates/starter/src/render/postprocessing.ts +18 -0
  309. package/templates/starter/src/render/shapes.ts +147 -0
  310. package/templates/starter/src/render/sky.ts +56 -0
  311. package/templates/starter/src/scenes/Play.ts +161 -0
  312. package/templates/starter/src/state.ts +10 -0
  313. package/templates/starter/src/style.css +45 -0
  314. package/templates/starter/src/ui/App.tsx +19 -0
  315. package/templates/starter/src/ui/Hud.tsx +37 -0
  316. package/templates/starter/src/ui/Menu.tsx +43 -0
  317. package/templates/starter/tailwind.config.ts +2 -0
  318. package/templates/starter/threenative.config.ts +31 -0
  319. package/templates/starter/tsconfig.json +17 -0
  320. package/templates/starter/vite.config.ts +8 -0
@@ -0,0 +1,165 @@
1
+ import { type ICtx, Scene, type SceneFrame } from "@threenative/core";
2
+ import { type PerspectiveCamera, Vector3 } from "three";
3
+ import { Attacker } from "../attackers/Attacker.js";
4
+ import { ROUTE_TEST_SLOT, RouteBoard, SAFE_BUILD_SLOTS } from "../board/Route.js";
5
+ import { Economy, TOWER_COST } from "../economy.js";
6
+ import { Player } from "../entities/Player.js";
7
+ import { type DefensePhysics, directSpaceState } from "../physics.js";
8
+ import { Buildable, type PlacementReason } from "../placement/Buildable.js";
9
+ import { setupCamera } from "../render/camera.js";
10
+ import { setupLighting } from "../render/lighting.js";
11
+ import { createLoadingScreen } from "../render/loading.js";
12
+ import { setupPost } from "../render/postprocessing.js";
13
+ import { setupSky } from "../render/sky.js";
14
+ import { type GameState, INITIAL_STATE, MAX_LEAKS, registerLeak } from "../state.js";
15
+ import { Tower } from "../towers/Tower.js";
16
+ import { WaveSchedule } from "../waves.js";
17
+
18
+ export type GameCtx = ICtx<GameState, DefensePhysics>;
19
+
20
+ const SAFE_BUILD_HEIGHT = 0;
21
+
22
+ export class Defense extends Scene<GameState, DefensePhysics> {
23
+ static override readonly initialState = INITIAL_STATE;
24
+
25
+ override enter(ctx: GameCtx): SceneFrame<GameState, DefensePhysics> {
26
+ setupSky(ctx.scene);
27
+ setupLighting(ctx.scene, ctx.renderer.raw as Parameters<typeof setupLighting>[1]);
28
+ setupPost(ctx.renderer, ctx.scene, ctx.camera);
29
+ setupCamera(ctx.camera as PerspectiveCamera);
30
+ const loading = createLoadingScreen(ctx);
31
+ ctx.add(ctx.camera);
32
+ const board = new RouteBoard(ctx);
33
+ const player = new Player(ctx);
34
+ ctx.entities.add("player", player);
35
+ const query = directSpaceState(ctx.physics);
36
+ const buildable = new Buildable(query);
37
+ const economy = new Economy();
38
+ const attackers = new Map<string, Attacker>();
39
+ const towers = new Map<string, Tower>();
40
+ const removeAttackers = new Set<string>();
41
+ let safeSlot = 0;
42
+ let lastPlaced: Vector3 | undefined;
43
+ let defeated = 0;
44
+ let leaks = 0;
45
+ let status = INITIAL_STATE.status;
46
+ let routeRejects = 0;
47
+ let overlapRejects = 0;
48
+ let scanWindowFrames = 0;
49
+ let scanWindowScans = 0;
50
+ let scanWindowValid = false;
51
+ const place = (position: Vector3): void => {
52
+ const result = buildable.validate(position);
53
+ if (!result.accepted) {
54
+ recordRejected(result.reason);
55
+ return;
56
+ }
57
+ if (!economy.spend(TOWER_COST)) return;
58
+ buildable.commit(position);
59
+ const id = String(towers.size);
60
+ const tower = new Tower({
61
+ id,
62
+ physics: ctx.physics,
63
+ position,
64
+ query,
65
+ random: ctx.random,
66
+ targets: attackers,
67
+ });
68
+ towers.set(id, tower);
69
+ ctx.entities.add(`tower.${id}`, tower);
70
+ lastPlaced = position.clone();
71
+ };
72
+ const spawn = (wave: number, member: number): void => {
73
+ const id = `attacker.${wave}.${member}`;
74
+ const attacker = new Attacker({
75
+ id,
76
+ lateralOffset: member === 0 ? -0.17 : 0.17,
77
+ onDefeated: () => {
78
+ defeated += 1;
79
+ removeAttackers.add(id);
80
+ },
81
+ onLeak: () => {
82
+ leaks = registerLeak(leaks).leaks;
83
+ removeAttackers.add(id);
84
+ if (leaks >= MAX_LEAKS) status = "LOST";
85
+ },
86
+ pathPoints: board.points,
87
+ physics: ctx.physics,
88
+ });
89
+ attackers.set(id, attacker);
90
+ ctx.entities.add(id, attacker);
91
+ };
92
+ const waves = new WaveSchedule({
93
+ onSpawn: spawn,
94
+ onWin: () => {
95
+ if (leaks < MAX_LEAKS) status = "WON";
96
+ },
97
+ });
98
+ const attemptPointerPlacement = (): void => {
99
+ const hit = ctx.raycast({ targets: board.surface });
100
+ if (hit !== undefined) place(hit.point.clone().setY(SAFE_BUILD_HEIGHT));
101
+ };
102
+ const recordRejected = (reason: PlacementReason): void => {
103
+ if (reason === "route") routeRejects += 1;
104
+ if (reason === "overlap") overlapRejects += 1;
105
+ };
106
+ return (frameCtx, dt) => {
107
+ loading.update();
108
+ if (frameCtx.input.justPressed("restart")) {
109
+ frameCtx.state.set(INITIAL_STATE);
110
+ frameCtx.state.flush();
111
+ void frameCtx.goto("defense");
112
+ return;
113
+ }
114
+ if (status === "PLAYING") {
115
+ player.update(frameCtx, dt);
116
+ economy.update(dt);
117
+ if (frameCtx.input.justPressed("build")) attemptPointerPlacement();
118
+ if (frameCtx.input.justPressed("safeBuild")) {
119
+ const slot = SAFE_BUILD_SLOTS[safeSlot % SAFE_BUILD_SLOTS.length];
120
+ safeSlot += 1;
121
+ if (slot !== undefined) place(slot);
122
+ }
123
+ if (frameCtx.input.justPressed("routeTest")) place(ROUTE_TEST_SLOT);
124
+ if (frameCtx.input.justPressed("overlapTest"))
125
+ place(lastPlaced ?? SAFE_BUILD_SLOTS[0] ?? new Vector3());
126
+ for (const attacker of attackers.values()) attacker.update(dt);
127
+ for (const tower of towers.values()) tower.update(dt);
128
+ waves.update(dt, attackers.size);
129
+ for (const id of removeAttackers) {
130
+ ctx.entities.remove(id);
131
+ attackers.delete(id);
132
+ }
133
+ removeAttackers.clear();
134
+ }
135
+ const scanCount = [...towers.values()].reduce((total, tower) => total + tower.scanCount, 0);
136
+ const shots = [...towers.values()].reduce((total, tower) => total + tower.shots, 0);
137
+ if (scanWindowFrames < 300) {
138
+ scanWindowFrames += 1;
139
+ if (scanWindowFrames === 300) {
140
+ scanWindowScans = scanCount;
141
+ scanWindowValid = towers.size > 0 && scanCount >= 10 && scanCount <= 40 * towers.size;
142
+ }
143
+ }
144
+ const state: GameState = {
145
+ balance: economy.balance,
146
+ defeated,
147
+ income: economy.income,
148
+ leaks,
149
+ overlapRejects,
150
+ placementRejects: routeRejects + overlapRejects,
151
+ routeRejects,
152
+ scanCount,
153
+ scanWindowFrames,
154
+ scanWindowScans,
155
+ scanWindowValid,
156
+ shots,
157
+ spent: economy.spent,
158
+ status,
159
+ towers: towers.size,
160
+ wave: waves.spawned,
161
+ };
162
+ frameCtx.state.set(state);
163
+ };
164
+ }
165
+ }
@@ -0,0 +1,50 @@
1
+ export type DefenseStatus = "LOST" | "PLAYING" | "WON";
2
+ export const MAX_LEAKS = 20;
3
+
4
+ export function registerLeak(leaks: number): {
5
+ readonly leaks: number;
6
+ readonly status: DefenseStatus;
7
+ } {
8
+ if (!Number.isInteger(leaks) || leaks < 0)
9
+ throw new Error("Leak count must be a nonnegative integer.");
10
+ const next = leaks + 1;
11
+ return { leaks: next, status: next >= MAX_LEAKS ? "LOST" : "PLAYING" };
12
+ }
13
+
14
+ export type GameState = {
15
+ balance: number;
16
+ defeated: number;
17
+ income: number;
18
+ leaks: number;
19
+ overlapRejects: number;
20
+ placementRejects: number;
21
+ routeRejects: number;
22
+ scanCount: number;
23
+ scanWindowFrames: number;
24
+ scanWindowScans: number;
25
+ scanWindowValid: boolean;
26
+ shots: number;
27
+ spent: number;
28
+ status: DefenseStatus;
29
+ towers: number;
30
+ wave: number;
31
+ };
32
+
33
+ export const INITIAL_STATE: GameState = {
34
+ balance: 120,
35
+ defeated: 0,
36
+ income: 0,
37
+ leaks: 0,
38
+ overlapRejects: 0,
39
+ placementRejects: 0,
40
+ routeRejects: 0,
41
+ scanCount: 0,
42
+ scanWindowFrames: 0,
43
+ scanWindowScans: 0,
44
+ scanWindowValid: false,
45
+ shots: 0,
46
+ spent: 0,
47
+ status: "PLAYING",
48
+ towers: 0,
49
+ wave: 0,
50
+ };
@@ -0,0 +1,32 @@
1
+ @import "tailwindcss";
2
+
3
+ @source "../index.html";
4
+ @source "./";
5
+
6
+ @theme {
7
+ --color-ink: #07131d;
8
+ --color-panel: #0d2430;
9
+ --color-line: #1d4a58;
10
+ --color-lume: #f5c451;
11
+ --color-win: #79e0b2;
12
+ --color-danger: #ff7182;
13
+ --color-text: #c1dce2;
14
+ --color-muted: #6c9aa5;
15
+ --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
16
+ }
17
+
18
+ html,
19
+ body,
20
+ #root {
21
+ width: 100%;
22
+ height: 100%;
23
+ margin: 0;
24
+ overflow: hidden;
25
+ }
26
+
27
+ body {
28
+ background: var(--color-ink);
29
+ color: var(--color-text);
30
+ font-family: var(--font-mono);
31
+ -webkit-font-smoothing: antialiased;
32
+ }
@@ -0,0 +1,96 @@
1
+ import { CollisionShape3D } from "@threenative/physics";
2
+ import type { Group, Vector3 } from "three";
3
+ import {
4
+ ATTACKER_LAYER,
5
+ type DefensePhysics,
6
+ type IPhysicsDirectSpaceState,
7
+ TOWER_LAYER,
8
+ createEntityBody,
9
+ } from "../physics.js";
10
+ import { emitPlaytestEvent } from "../playtest-events.js";
11
+ import { tower as towerMesh } from "../render/shapes.js";
12
+ import { type ITargetable, JitteredScanClock, nearestFirst } from "./targeting.js";
13
+
14
+ export const TOWER_RANGE = 5.4;
15
+ export const TOWER_DAMAGE = 4;
16
+ export const TOWER_RELOAD = 0.55;
17
+
18
+ export class Tower {
19
+ readonly id: string;
20
+ readonly mesh: Group;
21
+ readonly tags = ["tower", "defense"];
22
+ readonly #body;
23
+ readonly #clock: JitteredScanClock;
24
+ readonly #query: IPhysicsDirectSpaceState;
25
+ readonly #targets: ReadonlyMap<string, ITargetable>;
26
+ #reload = 0;
27
+ #shots = 0;
28
+ #target: ITargetable | undefined;
29
+
30
+ constructor(options: {
31
+ readonly id: string;
32
+ readonly physics: DefensePhysics;
33
+ readonly position: Vector3;
34
+ readonly query: IPhysicsDirectSpaceState;
35
+ readonly random: ConstructorParameters<typeof JitteredScanClock>[0];
36
+ readonly targets: ReadonlyMap<string, ITargetable>;
37
+ }) {
38
+ this.id = options.id;
39
+ this.#query = options.query;
40
+ this.#targets = options.targets;
41
+ this.#clock = new JitteredScanClock(options.random);
42
+ this.mesh = towerMesh();
43
+ this.mesh.position.copy(options.position).setY(0);
44
+ this.#body = createEntityBody({
45
+ collisionLayer: TOWER_LAYER,
46
+ collisionMask: ATTACKER_LAYER,
47
+ entity: `tower.${this.id}`,
48
+ object: this.mesh,
49
+ physics: options.physics,
50
+ shape: CollisionShape3D.box(1.55, 1.2, 1.55),
51
+ type: "fixed",
52
+ });
53
+ }
54
+
55
+ get scanCount(): number {
56
+ return this.#clock.scans;
57
+ }
58
+
59
+ get shots(): number {
60
+ return this.#shots;
61
+ }
62
+
63
+ update(dt: number): void {
64
+ this.#clock.update(dt, () => {
65
+ const origin = this.mesh.position.clone().setY(0.6);
66
+ const hits = this.#query.intersectShape({
67
+ collisionMask: ATTACKER_LAYER,
68
+ maxResults: 16,
69
+ position: origin,
70
+ shape: CollisionShape3D.sphere(TOWER_RANGE),
71
+ });
72
+ this.#target = nearestFirst(hits, origin, this.#targets);
73
+ });
74
+ this.#reload = Math.max(0, this.#reload - dt);
75
+ if (this.#target === undefined || this.#target.dead) return;
76
+ if (this.#reload > 0) return;
77
+ this.#target.takeDamage(TOWER_DAMAGE);
78
+ this.#shots += 1;
79
+ this.#reload = TOWER_RELOAD;
80
+ emitPlaytestEvent({ entity: this.id, name: "fired", shots: this.#shots });
81
+ }
82
+
83
+ debug(): Record<string, unknown> {
84
+ return {
85
+ position: this.mesh.position.toArray(),
86
+ scanCount: this.scanCount,
87
+ shots: this.#shots,
88
+ target: this.#target?.id ?? "",
89
+ };
90
+ }
91
+
92
+ dispose(): void {
93
+ this.#body.dispose();
94
+ this.mesh.removeFromParent();
95
+ }
96
+ }
@@ -0,0 +1,53 @@
1
+ import type { IRandom } from "@threenative/core";
2
+ import type { Vector3 } from "three";
3
+ import type { IShapeHit } from "../physics.js";
4
+
5
+ export interface ITargetable {
6
+ readonly dead: boolean;
7
+ readonly id: string;
8
+ readonly mesh: { readonly position: Vector3 };
9
+ takeDamage(amount: number): void;
10
+ }
11
+
12
+ export class JitteredScanClock {
13
+ #elapsed = 0;
14
+ #next: number;
15
+ readonly #maximum: number;
16
+ readonly #minimum: number;
17
+ readonly #random: IRandom;
18
+ scans = 0;
19
+
20
+ constructor(random: IRandom, minimum = 0.18, maximum = 0.3) {
21
+ if (!(maximum > minimum) || minimum <= 0) throw new Error("Scan interval bounds are invalid.");
22
+ this.#random = random;
23
+ this.#minimum = minimum;
24
+ this.#maximum = maximum;
25
+ this.#next = random.range(minimum, maximum);
26
+ }
27
+
28
+ update(dt: number, scan: () => void): void {
29
+ if (!Number.isFinite(dt) || dt < 0) throw new Error("JitteredScanClock delta must be finite.");
30
+ this.#elapsed += dt;
31
+ while (this.#elapsed >= this.#next) {
32
+ this.#elapsed -= this.#next;
33
+ this.scans += 1;
34
+ scan();
35
+ this.#next = this.#random.range(this.#minimum, this.#maximum);
36
+ }
37
+ }
38
+ }
39
+
40
+ export function nearestFirst(
41
+ hits: readonly IShapeHit[],
42
+ origin: Vector3,
43
+ targets: ReadonlyMap<string, ITargetable>,
44
+ ): ITargetable | undefined {
45
+ return hits
46
+ .flatMap((hit) => (hit.entity === undefined ? [] : [targets.get(hit.entity)]))
47
+ .filter((target): target is ITargetable => target !== undefined && !target.dead)
48
+ .sort(
49
+ (left, right) =>
50
+ left.mesh.position.distanceToSquared(origin) -
51
+ right.mesh.position.distanceToSquared(origin),
52
+ )[0];
53
+ }
@@ -0,0 +1,17 @@
1
+ import type { IGame } from "@threenative/core";
2
+ import { DebugOverlay, GameCanvas } from "@threenative/ui";
3
+ import type { DefensePhysics } from "../physics.js";
4
+ import type { GameState } from "../state.js";
5
+ import { Hud } from "./Hud.js";
6
+ import { Menu } from "./Menu.js";
7
+
8
+ export function App({ game }: { game: IGame<GameState, DefensePhysics> }) {
9
+ return (
10
+ <main className="relative h-screen w-screen overflow-hidden bg-ink">
11
+ <GameCanvas className="absolute inset-0" game={game} />
12
+ <Hud game={game} />
13
+ <Menu />
14
+ <DebugOverlay />
15
+ </main>
16
+ );
17
+ }
@@ -0,0 +1,61 @@
1
+ import type { IGame } from "@threenative/core";
2
+ import { useGameState } from "@threenative/ui";
3
+ import type { DefensePhysics } from "../physics.js";
4
+ import type { GameState } from "../state.js";
5
+
6
+ export function Hud({ game }: { game: IGame<GameState, DefensePhysics> }) {
7
+ const state = useGameState(game, (value) => value);
8
+ const statusClass =
9
+ state.status === "WON" ? "text-win" : state.status === "LOST" ? "text-danger" : "text-lume";
10
+ return (
11
+ <div className="pointer-events-none absolute inset-0 p-6 text-[11px] uppercase tracking-[0.16em] text-text">
12
+ <div className="flex items-start justify-between">
13
+ <div>
14
+ <div className="text-[10px] text-muted">route / north sector</div>
15
+ <div className="mt-2 flex items-baseline gap-5 text-[18px] text-white">
16
+ <span>
17
+ wave <b id="wave">{state.wave}</b>/10
18
+ </span>
19
+ <span className={statusClass} id="status">
20
+ {state.status}
21
+ </span>
22
+ </div>
23
+ </div>
24
+ <div className="text-right">
25
+ <div className="text-[10px] text-muted">leaks</div>
26
+ <div className="mt-2 text-[22px] text-white" id="leaks">
27
+ {state.leaks}/20
28
+ </div>
29
+ </div>
30
+ </div>
31
+ <div className="absolute bottom-6 left-6 flex items-end gap-8">
32
+ <div>
33
+ <div className="text-[10px] text-muted">credits</div>
34
+ <div className="mt-1 text-[26px] leading-none text-white" id="balance">
35
+ {Math.floor(state.balance)}
36
+ </div>
37
+ </div>
38
+ <div>
39
+ <div className="text-[10px] text-muted">towers</div>
40
+ <div className="mt-1 text-[18px] leading-none text-white" id="towers">
41
+ {state.towers}
42
+ </div>
43
+ </div>
44
+ <div>
45
+ <div className="text-[10px] text-muted">income</div>
46
+ <div className="mt-1 text-[18px] leading-none text-white" id="income">
47
+ +{state.income.toFixed(1)}
48
+ </div>
49
+ </div>
50
+ </div>
51
+ {state.status !== "PLAYING" && (
52
+ <div
53
+ className={`absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 border px-8 py-5 text-center ${state.status === "WON" ? "border-win/70 bg-win/10" : "border-danger/70 bg-danger/10"}`}
54
+ >
55
+ <div className={`text-[28px] tracking-[0.28em] ${statusClass}`}>{state.status}</div>
56
+ <div className="mt-2 text-[10px] text-muted">press R to restart</div>
57
+ </div>
58
+ )}
59
+ </div>
60
+ );
61
+ }
@@ -0,0 +1,7 @@
1
+ export function Menu() {
2
+ return (
3
+ <div className="pointer-events-none absolute bottom-6 right-6 border border-line bg-panel/80 px-4 py-3 text-[10px] uppercase tracking-[0.12em] text-muted">
4
+ click board to build · B safe slot · R restart
5
+ </div>
6
+ );
7
+ }
@@ -0,0 +1,40 @@
1
+ export const TOTAL_WAVES = 10;
2
+ export const ATTACKERS_PER_WAVE = 2;
3
+ export const WAVE_INTERVAL = 0.5;
4
+
5
+ export class WaveSchedule {
6
+ #elapsed = WAVE_INTERVAL;
7
+ #spawned = 0;
8
+ #won = false;
9
+ readonly #onSpawn: (wave: number, member: number) => void;
10
+ readonly #onWin: () => void;
11
+
12
+ constructor(options: {
13
+ readonly onSpawn: (wave: number, member: number) => void;
14
+ readonly onWin: () => void;
15
+ }) {
16
+ this.#onSpawn = options.onSpawn;
17
+ this.#onWin = options.onWin;
18
+ }
19
+
20
+ get spawned(): number {
21
+ return this.#spawned;
22
+ }
23
+
24
+ update(dt: number, activeAttackers: number): void {
25
+ if (!Number.isFinite(dt) || dt < 0) throw new Error("WaveSchedule delta must be finite.");
26
+ if (this.#spawned < TOTAL_WAVES) {
27
+ this.#elapsed += dt;
28
+ while (this.#elapsed >= WAVE_INTERVAL && this.#spawned < TOTAL_WAVES) {
29
+ this.#elapsed -= WAVE_INTERVAL;
30
+ this.#spawned += 1;
31
+ for (let member = 0; member < ATTACKERS_PER_WAVE; member += 1) {
32
+ this.#onSpawn(this.#spawned, member);
33
+ }
34
+ }
35
+ } else if (!this.#won && activeAttackers === 0) {
36
+ this.#won = true;
37
+ this.#onWin();
38
+ }
39
+ }
40
+ }
@@ -0,0 +1 @@
1
+ export default {};
@@ -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: "#07131d",
23
+ trackColor: "#193242",
24
+ progressColor: "#f5c451",
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", "*.ts"]
17
+ }
@@ -0,0 +1,5 @@
1
+ import tailwindcss from "@tailwindcss/vite";
2
+ import react from "@vitejs/plugin-react";
3
+ import { defineConfig } from "vite";
4
+
5
+ export default defineConfig({ plugins: [react(), tailwindcss()] });
@@ -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
+ }