@origingame/create-game 0.0.0-stage → 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.
Files changed (581) hide show
  1. package/README.md +57 -2
  2. package/archetypes/README.md +99 -0
  3. package/archetypes/idle/.origin/setup +14 -0
  4. package/archetypes/idle/LICENSES.md +12 -0
  5. package/archetypes/idle/README.md +234 -0
  6. package/archetypes/idle/assets/audio/buy.wav +0 -0
  7. package/archetypes/idle/assets/audio/milestone.wav +0 -0
  8. package/archetypes/idle/assets/audio/nova.wav +0 -0
  9. package/archetypes/idle/assets/audio/orbit.wav +0 -0
  10. package/archetypes/idle/assets/audio/tap.wav +0 -0
  11. package/archetypes/idle/assets/audio/ui-close.ogt +9 -0
  12. package/archetypes/idle/assets/audio/ui-error.ogt +9 -0
  13. package/archetypes/idle/assets/audio/ui-open.ogt +9 -0
  14. package/archetypes/idle/assets/audio/ui-press.ogt +9 -0
  15. package/archetypes/idle/assets/audio/ui-success.ogt +9 -0
  16. package/archetypes/idle/assets/fonts/NotoSansSC-subset.ttf +0 -0
  17. package/archetypes/idle/assets/fonts/NotoSansSC-subset.ttf.ogt +10 -0
  18. package/archetypes/idle/assets/fonts/OFL.txt +93 -0
  19. package/archetypes/idle/assets/fx/drift.ogt +21 -0
  20. package/archetypes/idle/assets/fx/milestone.ogt +21 -0
  21. package/archetypes/idle/assets/fx/nova.ogt +22 -0
  22. package/archetypes/idle/assets/fx/stars.ogt +20 -0
  23. package/archetypes/idle/assets/fx/tap.ogt +23 -0
  24. package/archetypes/idle/assets/looks/idle.ogt +17 -0
  25. package/archetypes/idle/assets/skins/sparkorb/ChakraPetch-BoldItalic.ttf +0 -0
  26. package/archetypes/idle/assets/skins/sparkorb/ChakraPetch-BoldItalic.ttf.ogt +9 -0
  27. package/archetypes/idle/assets/skins/sparkorb/LICENSES.md +19 -0
  28. package/archetypes/idle/assets/skins/sparkorb/OFL.txt +95 -0
  29. package/archetypes/idle/assets/skins/sparkorb/Orbitron-Medium.ttf +0 -0
  30. package/archetypes/idle/assets/skins/sparkorb/Orbitron-Medium.ttf.ogt +9 -0
  31. package/archetypes/idle/assets/skins/sparkorb/Rajdhani-Bold.ttf +0 -0
  32. package/archetypes/idle/assets/skins/sparkorb/Rajdhani-Bold.ttf.ogt +9 -0
  33. package/archetypes/idle/assets/skins/sparkorb/atlas.png +0 -0
  34. package/archetypes/idle/assets/skins/sparkorb/atlas.png.ogt +7 -0
  35. package/archetypes/idle/assets/skins/sparkorb/icons.png +0 -0
  36. package/archetypes/idle/assets/skins/sparkorb/icons.png.ogt +7 -0
  37. package/archetypes/idle/assets/skins/sparkorb/skin.ogt +113 -0
  38. package/archetypes/idle/assets/sprites/glow.png +0 -0
  39. package/archetypes/idle/assets/sprites/glow.png.ogt +8 -0
  40. package/archetypes/idle/assets/sprites/mote-crystal.png +0 -0
  41. package/archetypes/idle/assets/sprites/mote-crystal.png.ogt +7 -0
  42. package/archetypes/idle/assets/sprites/mote-ember.png +0 -0
  43. package/archetypes/idle/assets/sprites/mote-ember.png.ogt +7 -0
  44. package/archetypes/idle/assets/sprites/mote-star.png +0 -0
  45. package/archetypes/idle/assets/sprites/mote-star.png.ogt +7 -0
  46. package/archetypes/idle/assets/sprites/mote-storm.png +0 -0
  47. package/archetypes/idle/assets/sprites/mote-storm.png.ogt +7 -0
  48. package/archetypes/idle/assets/sprites/orb.png +0 -0
  49. package/archetypes/idle/assets/sprites/orb.png.ogt +7 -0
  50. package/archetypes/idle/assets/sprites/spark.png +0 -0
  51. package/archetypes/idle/assets/sprites/spark.png.ogt +7 -0
  52. package/archetypes/idle/assets/strings/en.ogt +62 -0
  53. package/archetypes/idle/assets/strings/zh-CN.ogt +62 -0
  54. package/archetypes/idle/gitattributes +22 -0
  55. package/archetypes/idle/host.d.ts +46 -0
  56. package/archetypes/idle/package.json +18 -0
  57. package/archetypes/idle/project.ogt +14 -0
  58. package/archetypes/idle/references/metal/card.png +0 -0
  59. package/archetypes/idle/references/metal/orbit.png +0 -0
  60. package/archetypes/idle/references/metal/title.png +0 -0
  61. package/archetypes/idle/src/components.ts +139 -0
  62. package/archetypes/idle/src/main.ts +247 -0
  63. package/archetypes/idle/src/numbers.ts +126 -0
  64. package/archetypes/idle/src/systems.ts +340 -0
  65. package/archetypes/idle/src/ui.ts +412 -0
  66. package/archetypes/idle/tests/away.og.ts +42 -0
  67. package/archetypes/idle/tests/flow.og.ts +57 -0
  68. package/archetypes/idle/tests/frames.og.ts +33 -0
  69. package/archetypes/idle/tests/frames.ts +134 -0
  70. package/archetypes/idle/tests/lib.ts +74 -0
  71. package/archetypes/idle/tests/milestone.og.ts +32 -0
  72. package/archetypes/idle/tests/nova.og.ts +52 -0
  73. package/archetypes/idle/tests/offline.og.ts +60 -0
  74. package/archetypes/idle/tests/pad.og.ts +55 -0
  75. package/archetypes/idle/tests/pause.og.ts +68 -0
  76. package/archetypes/idle/tests/phone.og.ts +50 -0
  77. package/archetypes/idle/tests/replay.og.ts +28 -0
  78. package/archetypes/idle/tools/make-assets.py +448 -0
  79. package/archetypes/idle/tools/oglite.py +285 -0
  80. package/archetypes/idle/tsconfig.json +17 -0
  81. package/archetypes/match3/.origin/setup +14 -0
  82. package/archetypes/match3/LICENSES.md +7 -0
  83. package/archetypes/match3/README.md +205 -0
  84. package/archetypes/match3/assets/audio/cascade.wav +0 -0
  85. package/archetypes/match3/assets/audio/clear.wav +0 -0
  86. package/archetypes/match3/assets/audio/lost.wav +0 -0
  87. package/archetypes/match3/assets/audio/refused.wav +0 -0
  88. package/archetypes/match3/assets/audio/select.wav +0 -0
  89. package/archetypes/match3/assets/audio/swap.wav +0 -0
  90. package/archetypes/match3/assets/audio/won.wav +0 -0
  91. package/archetypes/match3/assets/fonts/OFL.txt +93 -0
  92. package/archetypes/match3/assets/fonts/ui.ttf +0 -0
  93. package/archetypes/match3/assets/fonts/ui.ttf.ogt +11 -0
  94. package/archetypes/match3/assets/scenes/main.ogt +24 -0
  95. package/archetypes/match3/assets/sprites/backdrop.png +0 -0
  96. package/archetypes/match3/assets/sprites/board.ogt +21 -0
  97. package/archetypes/match3/assets/sprites/cells.ogt +7 -0
  98. package/archetypes/match3/assets/sprites/cells.png +0 -0
  99. package/archetypes/match3/assets/sprites/cells.png.ogt +7 -0
  100. package/archetypes/match3/assets/sprites/gems.ogt +75 -0
  101. package/archetypes/match3/assets/sprites/gems.png +0 -0
  102. package/archetypes/match3/assets/sprites/panel.png +0 -0
  103. package/archetypes/match3/assets/sprites/ring.png +0 -0
  104. package/archetypes/match3/gitattributes +22 -0
  105. package/archetypes/match3/host.d.ts +46 -0
  106. package/archetypes/match3/package.json +18 -0
  107. package/archetypes/match3/project.ogt +18 -0
  108. package/archetypes/match3/references/metal/cascade.png +0 -0
  109. package/archetypes/match3/references/metal/clearing.png +0 -0
  110. package/archetypes/match3/references/metal/dealt.png +0 -0
  111. package/archetypes/match3/src/art.ts +54 -0
  112. package/archetypes/match3/src/board.ts +112 -0
  113. package/archetypes/match3/src/components.ts +95 -0
  114. package/archetypes/match3/src/layout.ts +25 -0
  115. package/archetypes/match3/src/main.ts +199 -0
  116. package/archetypes/match3/src/systems.ts +631 -0
  117. package/archetypes/match3/tests/drag.og.ts +31 -0
  118. package/archetypes/match3/tests/endings.og.ts +40 -0
  119. package/archetypes/match3/tests/frames.og.ts +49 -0
  120. package/archetypes/match3/tests/frames.ts +134 -0
  121. package/archetypes/match3/tests/hidpi.og.ts +41 -0
  122. package/archetypes/match3/tests/lib.ts +64 -0
  123. package/archetypes/match3/tests/replay.og.ts +28 -0
  124. package/archetypes/match3/tests/sounds.og.ts +50 -0
  125. package/archetypes/match3/tests/swap.og.ts +67 -0
  126. package/archetypes/match3/tools/make-assets.py +404 -0
  127. package/archetypes/match3/tools/oglite.py +285 -0
  128. package/archetypes/match3/tsconfig.json +17 -0
  129. package/archetypes/rhythm/.origin/setup +14 -0
  130. package/archetypes/rhythm/LICENSES.md +13 -0
  131. package/archetypes/rhythm/README.md +235 -0
  132. package/archetypes/rhythm/assets/audio/bass0.wav +0 -0
  133. package/archetypes/rhythm/assets/audio/bass1.wav +0 -0
  134. package/archetypes/rhythm/assets/audio/bass2.wav +0 -0
  135. package/archetypes/rhythm/assets/audio/bass3.wav +0 -0
  136. package/archetypes/rhythm/assets/audio/chords0.wav +0 -0
  137. package/archetypes/rhythm/assets/audio/chords1.wav +0 -0
  138. package/archetypes/rhythm/assets/audio/chords2.wav +0 -0
  139. package/archetypes/rhythm/assets/audio/chords3.wav +0 -0
  140. package/archetypes/rhythm/assets/audio/clear.wav +0 -0
  141. package/archetypes/rhythm/assets/audio/click.wav +0 -0
  142. package/archetypes/rhythm/assets/audio/drums.wav +0 -0
  143. package/archetypes/rhythm/assets/audio/fail.wav +0 -0
  144. package/archetypes/rhythm/assets/audio/leadA.wav +0 -0
  145. package/archetypes/rhythm/assets/audio/leadB.wav +0 -0
  146. package/archetypes/rhythm/assets/audio/miss.wav +0 -0
  147. package/archetypes/rhythm/assets/audio/tap0.wav +0 -0
  148. package/archetypes/rhythm/assets/audio/tap1.wav +0 -0
  149. package/archetypes/rhythm/assets/audio/tap2.wav +0 -0
  150. package/archetypes/rhythm/assets/audio/ui-close.ogt +9 -0
  151. package/archetypes/rhythm/assets/audio/ui-error.ogt +9 -0
  152. package/archetypes/rhythm/assets/audio/ui-open.ogt +9 -0
  153. package/archetypes/rhythm/assets/audio/ui-press.ogt +9 -0
  154. package/archetypes/rhythm/assets/audio/ui-success.ogt +9 -0
  155. package/archetypes/rhythm/assets/charts/neon-pulse.ogt +919 -0
  156. package/archetypes/rhythm/assets/fonts/NotoSansSC-subset.ttf +0 -0
  157. package/archetypes/rhythm/assets/fonts/NotoSansSC-subset.ttf.ogt +10 -0
  158. package/archetypes/rhythm/assets/fonts/OFL.txt +93 -0
  159. package/archetypes/rhythm/assets/fx/hit.ogt +22 -0
  160. package/archetypes/rhythm/assets/skins/lanebeat/ChakraPetch-Medium.ttf +0 -0
  161. package/archetypes/rhythm/assets/skins/lanebeat/ChakraPetch-Medium.ttf.ogt +9 -0
  162. package/archetypes/rhythm/assets/skins/lanebeat/JetBrainsMono-Regular.ttf +0 -0
  163. package/archetypes/rhythm/assets/skins/lanebeat/JetBrainsMono-Regular.ttf.ogt +9 -0
  164. package/archetypes/rhythm/assets/skins/lanebeat/LICENSES.md +17 -0
  165. package/archetypes/rhythm/assets/skins/lanebeat/OFL.txt +95 -0
  166. package/archetypes/rhythm/assets/skins/lanebeat/Orbitron-Bold.ttf +0 -0
  167. package/archetypes/rhythm/assets/skins/lanebeat/Orbitron-Bold.ttf.ogt +9 -0
  168. package/archetypes/rhythm/assets/skins/lanebeat/atlas.png +0 -0
  169. package/archetypes/rhythm/assets/skins/lanebeat/atlas.png.ogt +7 -0
  170. package/archetypes/rhythm/assets/skins/lanebeat/icons.png +0 -0
  171. package/archetypes/rhythm/assets/skins/lanebeat/icons.png.ogt +7 -0
  172. package/archetypes/rhythm/assets/skins/lanebeat/skin.ogt +110 -0
  173. package/archetypes/rhythm/assets/sprites/lane.png +0 -0
  174. package/archetypes/rhythm/assets/sprites/lane.png.ogt +7 -0
  175. package/archetypes/rhythm/assets/sprites/note.png +0 -0
  176. package/archetypes/rhythm/assets/sprites/note.png.ogt +7 -0
  177. package/archetypes/rhythm/assets/sprites/ring.png +0 -0
  178. package/archetypes/rhythm/assets/sprites/ring.png.ogt +7 -0
  179. package/archetypes/rhythm/assets/sprites/spark.png +0 -0
  180. package/archetypes/rhythm/assets/sprites/spark.png.ogt +7 -0
  181. package/archetypes/rhythm/assets/strings/en.ogt +61 -0
  182. package/archetypes/rhythm/assets/strings/zh-CN.ogt +61 -0
  183. package/archetypes/rhythm/gitattributes +22 -0
  184. package/archetypes/rhythm/host.d.ts +46 -0
  185. package/archetypes/rhythm/package.json +18 -0
  186. package/archetypes/rhythm/project.ogt +14 -0
  187. package/archetypes/rhythm/references/metal/highway.png +0 -0
  188. package/archetypes/rhythm/references/metal/results.png +0 -0
  189. package/archetypes/rhythm/references/metal/title.png +0 -0
  190. package/archetypes/rhythm/src/components.ts +147 -0
  191. package/archetypes/rhythm/src/main.ts +202 -0
  192. package/archetypes/rhythm/src/systems.ts +490 -0
  193. package/archetypes/rhythm/src/ui.ts +421 -0
  194. package/archetypes/rhythm/tests/band.og.ts +45 -0
  195. package/archetypes/rhythm/tests/calibrate.og.ts +49 -0
  196. package/archetypes/rhythm/tests/clear.og.ts +51 -0
  197. package/archetypes/rhythm/tests/fail.og.ts +40 -0
  198. package/archetypes/rhythm/tests/flow.og.ts +54 -0
  199. package/archetypes/rhythm/tests/frames.og.ts +35 -0
  200. package/archetypes/rhythm/tests/frames.ts +134 -0
  201. package/archetypes/rhythm/tests/lib.ts +123 -0
  202. package/archetypes/rhythm/tests/pad.og.ts +41 -0
  203. package/archetypes/rhythm/tests/pause.og.ts +77 -0
  204. package/archetypes/rhythm/tests/phone.og.ts +44 -0
  205. package/archetypes/rhythm/tests/replay.og.ts +27 -0
  206. package/archetypes/rhythm/tests/timing.og.ts +37 -0
  207. package/archetypes/rhythm/tools/make-assets.py +383 -0
  208. package/archetypes/rhythm/tools/oglite.py +285 -0
  209. package/archetypes/rhythm/tsconfig.json +17 -0
  210. package/archetypes/roguelike/.origin/setup +14 -0
  211. package/archetypes/roguelike/LICENSES.md +14 -0
  212. package/archetypes/roguelike/README.md +256 -0
  213. package/archetypes/roguelike/assets/ai/foe.ogt +28 -0
  214. package/archetypes/roguelike/assets/ai/guardian.ogt +26 -0
  215. package/archetypes/roguelike/assets/audio/bump.wav +0 -0
  216. package/archetypes/roguelike/assets/audio/drink.wav +0 -0
  217. package/archetypes/roguelike/assets/audio/fall.wav +0 -0
  218. package/archetypes/roguelike/assets/audio/hit.wav +0 -0
  219. package/archetypes/roguelike/assets/audio/hurt.wav +0 -0
  220. package/archetypes/roguelike/assets/audio/item.wav +0 -0
  221. package/archetypes/roguelike/assets/audio/kill.wav +0 -0
  222. package/archetypes/roguelike/assets/audio/pickup.wav +0 -0
  223. package/archetypes/roguelike/assets/audio/roar.wav +0 -0
  224. package/archetypes/roguelike/assets/audio/stairs.wav +0 -0
  225. package/archetypes/roguelike/assets/audio/step.ogt +9 -0
  226. package/archetypes/roguelike/assets/audio/telegraph.wav +0 -0
  227. package/archetypes/roguelike/assets/audio/tomb.wav +0 -0
  228. package/archetypes/roguelike/assets/audio/ui-close.ogt +9 -0
  229. package/archetypes/roguelike/assets/audio/ui-error.ogt +9 -0
  230. package/archetypes/roguelike/assets/audio/ui-open.ogt +9 -0
  231. package/archetypes/roguelike/assets/audio/ui-press.ogt +9 -0
  232. package/archetypes/roguelike/assets/audio/ui-success.ogt +9 -0
  233. package/archetypes/roguelike/assets/audio/won.wav +0 -0
  234. package/archetypes/roguelike/assets/fonts/NotoSansSC-subset.ttf +0 -0
  235. package/archetypes/roguelike/assets/fonts/NotoSansSC-subset.ttf.ogt +10 -0
  236. package/archetypes/roguelike/assets/fonts/OFL.txt +93 -0
  237. package/archetypes/roguelike/assets/maps/dive.ogt +106 -0
  238. package/archetypes/roguelike/assets/skins/lampdive/DotGothic16-Regular.ttf +0 -0
  239. package/archetypes/roguelike/assets/skins/lampdive/DotGothic16-Regular.ttf.ogt +9 -0
  240. package/archetypes/roguelike/assets/skins/lampdive/LICENSES.md +16 -0
  241. package/archetypes/roguelike/assets/skins/lampdive/OFL.txt +93 -0
  242. package/archetypes/roguelike/assets/skins/lampdive/atlas.png +0 -0
  243. package/archetypes/roguelike/assets/skins/lampdive/atlas.png.ogt +7 -0
  244. package/archetypes/roguelike/assets/skins/lampdive/icons.png +0 -0
  245. package/archetypes/roguelike/assets/skins/lampdive/icons.png.ogt +7 -0
  246. package/archetypes/roguelike/assets/skins/lampdive/skin.ogt +115 -0
  247. package/archetypes/roguelike/assets/sprites/dive.ogt +50 -0
  248. package/archetypes/roguelike/assets/sprites/dive.png +0 -0
  249. package/archetypes/roguelike/assets/sprites/dive.png.ogt +7 -0
  250. package/archetypes/roguelike/assets/sprites/glow.png +0 -0
  251. package/archetypes/roguelike/assets/sprites/glow.png.ogt +7 -0
  252. package/archetypes/roguelike/assets/strings/en.ogt +57 -0
  253. package/archetypes/roguelike/assets/strings/zh-CN.ogt +57 -0
  254. package/archetypes/roguelike/assets/tiles/tomb.ogt +31 -0
  255. package/archetypes/roguelike/assets/tiles/tomb.png +0 -0
  256. package/archetypes/roguelike/assets/tiles/tomb.png.ogt +7 -0
  257. package/archetypes/roguelike/gitattributes +22 -0
  258. package/archetypes/roguelike/host.d.ts +46 -0
  259. package/archetypes/roguelike/package.json +18 -0
  260. package/archetypes/roguelike/project.ogt +14 -0
  261. package/archetypes/roguelike/references/metal/dive.png +0 -0
  262. package/archetypes/roguelike/references/metal/over.png +0 -0
  263. package/archetypes/roguelike/references/metal/title.png +0 -0
  264. package/archetypes/roguelike/src/art.ts +23 -0
  265. package/archetypes/roguelike/src/components.ts +169 -0
  266. package/archetypes/roguelike/src/dive.ts +144 -0
  267. package/archetypes/roguelike/src/foes.ts +174 -0
  268. package/archetypes/roguelike/src/main.ts +258 -0
  269. package/archetypes/roguelike/src/systems.ts +620 -0
  270. package/archetypes/roguelike/src/ui.ts +350 -0
  271. package/archetypes/roguelike/tests/flow.og.ts +54 -0
  272. package/archetypes/roguelike/tests/foes.og.ts +45 -0
  273. package/archetypes/roguelike/tests/frames.og.ts +32 -0
  274. package/archetypes/roguelike/tests/frames.ts +134 -0
  275. package/archetypes/roguelike/tests/lib.ts +83 -0
  276. package/archetypes/roguelike/tests/lose.og.ts +44 -0
  277. package/archetypes/roguelike/tests/pad.og.ts +54 -0
  278. package/archetypes/roguelike/tests/pause.og.ts +59 -0
  279. package/archetypes/roguelike/tests/phone.og.ts +54 -0
  280. package/archetypes/roguelike/tests/replay.og.ts +24 -0
  281. package/archetypes/roguelike/tests/win.og.ts +60 -0
  282. package/archetypes/roguelike/tools/make-assets.py +518 -0
  283. package/archetypes/roguelike/tools/oglite.py +285 -0
  284. package/archetypes/roguelike/tsconfig.json +17 -0
  285. package/archetypes/runner/.origin/setup +14 -0
  286. package/archetypes/runner/LICENSES.md +10 -0
  287. package/archetypes/runner/README.md +225 -0
  288. package/archetypes/runner/assets/audio/coin.wav +0 -0
  289. package/archetypes/runner/assets/audio/crash.wav +0 -0
  290. package/archetypes/runner/assets/audio/hold.ogt +9 -0
  291. package/archetypes/runner/assets/audio/jump.wav +0 -0
  292. package/archetypes/runner/assets/audio/start.wav +0 -0
  293. package/archetypes/runner/assets/fonts/OFL.txt +93 -0
  294. package/archetypes/runner/assets/fonts/ui.ttf +0 -0
  295. package/archetypes/runner/assets/fonts/ui.ttf.ogt +11 -0
  296. package/archetypes/runner/assets/maps/far.ogt +25 -0
  297. package/archetypes/runner/assets/maps/near.ogt +25 -0
  298. package/archetypes/runner/assets/maps/roofs.ogt +19 -0
  299. package/archetypes/runner/assets/scenes/main.ogt +35 -0
  300. package/archetypes/runner/assets/sprites/coin.ogt +11 -0
  301. package/archetypes/runner/assets/sprites/coin.png +0 -0
  302. package/archetypes/runner/assets/sprites/coin.png.ogt +7 -0
  303. package/archetypes/runner/assets/sprites/courier.ogt +32 -0
  304. package/archetypes/runner/assets/sprites/courier.png +0 -0
  305. package/archetypes/runner/assets/sprites/courier.png.ogt +7 -0
  306. package/archetypes/runner/assets/sprites/props.ogt +21 -0
  307. package/archetypes/runner/assets/sprites/props.png +0 -0
  308. package/archetypes/runner/assets/sprites/props.png.ogt +7 -0
  309. package/archetypes/runner/assets/sprites/sky.png +0 -0
  310. package/archetypes/runner/assets/sprites/sky.png.ogt +7 -0
  311. package/archetypes/runner/assets/tiles/city.ogt +18 -0
  312. package/archetypes/runner/assets/tiles/city.png +0 -0
  313. package/archetypes/runner/assets/tiles/city.png.ogt +7 -0
  314. package/archetypes/runner/gitattributes +22 -0
  315. package/archetypes/runner/host.d.ts +46 -0
  316. package/archetypes/runner/package.json +18 -0
  317. package/archetypes/runner/project.ogt +18 -0
  318. package/archetypes/runner/references/metal/frames-coin.png +0 -0
  319. package/archetypes/runner/references/metal/frames-crash.png +0 -0
  320. package/archetypes/runner/references/metal/frames-title.png +0 -0
  321. package/archetypes/runner/src/art.ts +57 -0
  322. package/archetypes/runner/src/components.ts +94 -0
  323. package/archetypes/runner/src/main.ts +241 -0
  324. package/archetypes/runner/src/systems.ts +553 -0
  325. package/archetypes/runner/tests/coins.og.ts +30 -0
  326. package/archetypes/runner/tests/flow.og.ts +72 -0
  327. package/archetypes/runner/tests/frames.og.ts +37 -0
  328. package/archetypes/runner/tests/frames.ts +134 -0
  329. package/archetypes/runner/tests/jump.og.ts +44 -0
  330. package/archetypes/runner/tests/lib.ts +42 -0
  331. package/archetypes/runner/tests/records.og.ts +43 -0
  332. package/archetypes/runner/tests/replay.og.ts +36 -0
  333. package/archetypes/runner/tests/sounds.og.ts +43 -0
  334. package/archetypes/runner/tests/tune.og.ts +36 -0
  335. package/archetypes/runner/tools/make-assets.py +603 -0
  336. package/archetypes/runner/tools/oglite.py +285 -0
  337. package/archetypes/runner/tsconfig.json +17 -0
  338. package/archetypes/third-person/.origin/setup +14 -0
  339. package/archetypes/third-person/LICENSES.md +23 -0
  340. package/archetypes/third-person/README.md +249 -0
  341. package/archetypes/third-person/assets/ai/sentinel-east.ogt +69 -0
  342. package/archetypes/third-person/assets/ai/sentinel-north.ogt +69 -0
  343. package/archetypes/third-person/assets/ai/sentinel-west.ogt +69 -0
  344. package/archetypes/third-person/assets/anims/humanoid-clips.glb +0 -0
  345. package/archetypes/third-person/assets/audio/alarm.wav +0 -0
  346. package/archetypes/third-person/assets/audio/dawn.wav +0 -0
  347. package/archetypes/third-person/assets/audio/grab.wav +0 -0
  348. package/archetypes/third-person/assets/audio/ignite.wav +0 -0
  349. package/archetypes/third-person/assets/audio/jump.wav +0 -0
  350. package/archetypes/third-person/assets/audio/night.wav +0 -0
  351. package/archetypes/third-person/assets/audio/splash.wav +0 -0
  352. package/archetypes/third-person/assets/audio/step.ogt +9 -0
  353. package/archetypes/third-person/assets/audio/ui-close.ogt +9 -0
  354. package/archetypes/third-person/assets/audio/ui-error.ogt +9 -0
  355. package/archetypes/third-person/assets/audio/ui-open.ogt +9 -0
  356. package/archetypes/third-person/assets/audio/ui-press.ogt +9 -0
  357. package/archetypes/third-person/assets/audio/ui-success.ogt +9 -0
  358. package/archetypes/third-person/assets/audio/vale.wav +0 -0
  359. package/archetypes/third-person/assets/fonts/NotoSansSC-subset.ttf +0 -0
  360. package/archetypes/third-person/assets/fonts/NotoSansSC-subset.ttf.ogt +10 -0
  361. package/archetypes/third-person/assets/fonts/OFL.txt +93 -0
  362. package/archetypes/third-person/assets/fx/burst.ogt +25 -0
  363. package/archetypes/third-person/assets/fx/fire.ogt +24 -0
  364. package/archetypes/third-person/assets/fx/smoke.ogt +24 -0
  365. package/archetypes/third-person/assets/fx/splash.ogt +24 -0
  366. package/archetypes/third-person/assets/luts/teal-orange.cube +4917 -0
  367. package/archetypes/third-person/assets/models/stout.glb +0 -0
  368. package/archetypes/third-person/assets/models/strider.glb +0 -0
  369. package/archetypes/third-person/assets/models/strider.glb.ogt +9 -0
  370. package/archetypes/third-person/assets/nav/vale.ogt +43 -0
  371. package/archetypes/third-person/assets/rigs/strider.ogt +6 -0
  372. package/archetypes/third-person/assets/skins/ember/Cinzel-Bold.ttf +0 -0
  373. package/archetypes/third-person/assets/skins/ember/Cinzel-Bold.ttf.ogt +9 -0
  374. package/archetypes/third-person/assets/skins/ember/LICENSES.md +13 -0
  375. package/archetypes/third-person/assets/skins/ember/Newsreader-Medium.ttf +0 -0
  376. package/archetypes/third-person/assets/skins/ember/Newsreader-Medium.ttf.ogt +9 -0
  377. package/archetypes/third-person/assets/skins/ember/OFL.txt +94 -0
  378. package/archetypes/third-person/assets/skins/ember/atlas.png +0 -0
  379. package/archetypes/third-person/assets/skins/ember/atlas.png.ogt +7 -0
  380. package/archetypes/third-person/assets/skins/ember/icons.png +0 -0
  381. package/archetypes/third-person/assets/skins/ember/icons.png.ogt +7 -0
  382. package/archetypes/third-person/assets/skins/ember/skin.ogt +109 -0
  383. package/archetypes/third-person/assets/strings/en.ogt +47 -0
  384. package/archetypes/third-person/assets/strings/zh-CN.ogt +47 -0
  385. package/archetypes/third-person/assets/terrain/vale-control.png +0 -0
  386. package/archetypes/third-person/assets/terrain/vale.ogt +42 -0
  387. package/archetypes/third-person/assets/terrain/vale.png +0 -0
  388. package/archetypes/third-person/assets/textures/decals.png +0 -0
  389. package/archetypes/third-person/assets/textures/flame.png +0 -0
  390. package/archetypes/third-person/assets/textures/smoke.png +0 -0
  391. package/archetypes/third-person/assets/textures/spark.png +0 -0
  392. package/archetypes/third-person/assets/textures/terrain-grass.png +0 -0
  393. package/archetypes/third-person/assets/textures/terrain-path.png +0 -0
  394. package/archetypes/third-person/assets/textures/terrain-rock.png +0 -0
  395. package/archetypes/third-person/assets/textures/terrain-sand.png +0 -0
  396. package/archetypes/third-person/gitattributes +22 -0
  397. package/archetypes/third-person/host.d.ts +46 -0
  398. package/archetypes/third-person/package.json +18 -0
  399. package/archetypes/third-person/project.ogt +14 -0
  400. package/archetypes/third-person/references/metal/beacon.png +0 -0
  401. package/archetypes/third-person/references/metal/dawn.png +0 -0
  402. package/archetypes/third-person/references/metal/title.png +0 -0
  403. package/archetypes/third-person/references/webgl2/beacon.png +0 -0
  404. package/archetypes/third-person/src/anim.ts +87 -0
  405. package/archetypes/third-person/src/beacons.ts +80 -0
  406. package/archetypes/third-person/src/components.ts +148 -0
  407. package/archetypes/third-person/src/hero.ts +293 -0
  408. package/archetypes/third-person/src/main.ts +164 -0
  409. package/archetypes/third-person/src/sentinels.ts +159 -0
  410. package/archetypes/third-person/src/sound.ts +66 -0
  411. package/archetypes/third-person/src/ui.ts +451 -0
  412. package/archetypes/third-person/src/world.ts +212 -0
  413. package/archetypes/third-person/tests/flow.og.ts +70 -0
  414. package/archetypes/third-person/tests/frames.og.ts +35 -0
  415. package/archetypes/third-person/tests/frames.ts +134 -0
  416. package/archetypes/third-person/tests/hitstop.og.ts +26 -0
  417. package/archetypes/third-person/tests/lib.ts +87 -0
  418. package/archetypes/third-person/tests/lose.og.ts +44 -0
  419. package/archetypes/third-person/tests/pause.og.ts +64 -0
  420. package/archetypes/third-person/tests/phone.og.ts +65 -0
  421. package/archetypes/third-person/tests/replay.og.ts +32 -0
  422. package/archetypes/third-person/tests/restart.og.ts +28 -0
  423. package/archetypes/third-person/tests/sentinels.og.ts +48 -0
  424. package/archetypes/third-person/tests/win.og.ts +62 -0
  425. package/archetypes/third-person/tools/make-assets.py +353 -0
  426. package/archetypes/third-person/tools/oglite.py +285 -0
  427. package/archetypes/third-person/tsconfig.json +17 -0
  428. package/archetypes/topdown/.origin/setup +14 -0
  429. package/archetypes/topdown/LICENSES.md +10 -0
  430. package/archetypes/topdown/README.md +235 -0
  431. package/archetypes/topdown/assets/ai/slime.ogt +49 -0
  432. package/archetypes/topdown/assets/audio/coin.wav +0 -0
  433. package/archetypes/topdown/assets/audio/door.wav +0 -0
  434. package/archetypes/topdown/assets/audio/hit.wav +0 -0
  435. package/archetypes/topdown/assets/audio/hurt.wav +0 -0
  436. package/archetypes/topdown/assets/audio/key.wav +0 -0
  437. package/archetypes/topdown/assets/audio/step.ogt +9 -0
  438. package/archetypes/topdown/assets/fonts/OFL.txt +93 -0
  439. package/archetypes/topdown/assets/fonts/ui.ttf +0 -0
  440. package/archetypes/topdown/assets/fonts/ui.ttf.ogt +9 -0
  441. package/archetypes/topdown/assets/maps/tomb.tmj +2183 -0
  442. package/archetypes/topdown/assets/sprites/hero.ogt +58 -0
  443. package/archetypes/topdown/assets/sprites/hero.png +0 -0
  444. package/archetypes/topdown/assets/sprites/hero.png.ogt +7 -0
  445. package/archetypes/topdown/assets/sprites/items.ogt +15 -0
  446. package/archetypes/topdown/assets/sprites/items.png +0 -0
  447. package/archetypes/topdown/assets/sprites/items.png.ogt +7 -0
  448. package/archetypes/topdown/assets/sprites/slime.ogt +17 -0
  449. package/archetypes/topdown/assets/sprites/slime.png +0 -0
  450. package/archetypes/topdown/assets/sprites/slime.png.ogt +7 -0
  451. package/archetypes/topdown/assets/tiles/dungeon.ogt +65 -0
  452. package/archetypes/topdown/assets/tiles/dungeon.png +0 -0
  453. package/archetypes/topdown/assets/tiles/dungeon.png.ogt +7 -0
  454. package/archetypes/topdown/gitattributes +22 -0
  455. package/archetypes/topdown/host.d.ts +46 -0
  456. package/archetypes/topdown/package.json +18 -0
  457. package/archetypes/topdown/project.ogt +14 -0
  458. package/archetypes/topdown/references/metal/crit.png +0 -0
  459. package/archetypes/topdown/references/metal/dash.png +0 -0
  460. package/archetypes/topdown/references/metal/east.png +0 -0
  461. package/archetypes/topdown/references/metal/start.png +0 -0
  462. package/archetypes/topdown/src/art.ts +48 -0
  463. package/archetypes/topdown/src/components.ts +128 -0
  464. package/archetypes/topdown/src/main.ts +275 -0
  465. package/archetypes/topdown/src/systems.ts +503 -0
  466. package/archetypes/topdown/tests/ai.og.ts +64 -0
  467. package/archetypes/topdown/tests/combat.og.ts +72 -0
  468. package/archetypes/topdown/tests/door.og.ts +62 -0
  469. package/archetypes/topdown/tests/flee.og.ts +49 -0
  470. package/archetypes/topdown/tests/frames.og.ts +45 -0
  471. package/archetypes/topdown/tests/frames.ts +134 -0
  472. package/archetypes/topdown/tests/lib.ts +71 -0
  473. package/archetypes/topdown/tests/replay.og.ts +40 -0
  474. package/archetypes/topdown/tests/walk.og.ts +46 -0
  475. package/archetypes/topdown/tools/make-assets.py +623 -0
  476. package/archetypes/topdown/tools/oglite.py +285 -0
  477. package/archetypes/topdown/tsconfig.json +17 -0
  478. package/archetypes/tower-defense/.origin/setup +14 -0
  479. package/archetypes/tower-defense/LICENSES.md +15 -0
  480. package/archetypes/tower-defense/README.md +240 -0
  481. package/archetypes/tower-defense/assets/ai/plant.ogt +16 -0
  482. package/archetypes/tower-defense/assets/audio/clear.wav +0 -0
  483. package/archetypes/tower-defense/assets/audio/frost.wav +0 -0
  484. package/archetypes/tower-defense/assets/audio/leak.wav +0 -0
  485. package/archetypes/tower-defense/assets/audio/lost.wav +0 -0
  486. package/archetypes/tower-defense/assets/audio/night.wav +0 -0
  487. package/archetypes/tower-defense/assets/audio/plant.wav +0 -0
  488. package/archetypes/tower-defense/assets/audio/pop.wav +0 -0
  489. package/archetypes/tower-defense/assets/audio/thorn.wav +0 -0
  490. package/archetypes/tower-defense/assets/audio/ui-close.ogt +9 -0
  491. package/archetypes/tower-defense/assets/audio/ui-error.ogt +9 -0
  492. package/archetypes/tower-defense/assets/audio/ui-open.ogt +9 -0
  493. package/archetypes/tower-defense/assets/audio/ui-press.ogt +9 -0
  494. package/archetypes/tower-defense/assets/audio/ui-success.ogt +9 -0
  495. package/archetypes/tower-defense/assets/audio/wave.wav +0 -0
  496. package/archetypes/tower-defense/assets/audio/won.wav +0 -0
  497. package/archetypes/tower-defense/assets/fonts/NotoSansSC-subset.ttf +0 -0
  498. package/archetypes/tower-defense/assets/fonts/NotoSansSC-subset.ttf.ogt +10 -0
  499. package/archetypes/tower-defense/assets/fonts/OFL.txt +93 -0
  500. package/archetypes/tower-defense/assets/fx/fireflies.ogt +21 -0
  501. package/archetypes/tower-defense/assets/fx/pop.ogt +21 -0
  502. package/archetypes/tower-defense/assets/maps/garden.ogt +91 -0
  503. package/archetypes/tower-defense/assets/skins/pathguard/Fredoka-SemiBold.ttf +0 -0
  504. package/archetypes/tower-defense/assets/skins/pathguard/Fredoka-SemiBold.ttf.ogt +9 -0
  505. package/archetypes/tower-defense/assets/skins/pathguard/LICENSES.md +13 -0
  506. package/archetypes/tower-defense/assets/skins/pathguard/LilitaOne-Regular.ttf +0 -0
  507. package/archetypes/tower-defense/assets/skins/pathguard/LilitaOne-Regular.ttf.ogt +9 -0
  508. package/archetypes/tower-defense/assets/skins/pathguard/OFL.txt +94 -0
  509. package/archetypes/tower-defense/assets/skins/pathguard/atlas.png +0 -0
  510. package/archetypes/tower-defense/assets/skins/pathguard/atlas.png.ogt +7 -0
  511. package/archetypes/tower-defense/assets/skins/pathguard/icons.png +0 -0
  512. package/archetypes/tower-defense/assets/skins/pathguard/icons.png.ogt +7 -0
  513. package/archetypes/tower-defense/assets/skins/pathguard/skin.ogt +111 -0
  514. package/archetypes/tower-defense/assets/sprites/garden.ogt +66 -0
  515. package/archetypes/tower-defense/assets/sprites/garden.png +0 -0
  516. package/archetypes/tower-defense/assets/sprites/garden.png.ogt +7 -0
  517. package/archetypes/tower-defense/assets/sprites/glow.png +0 -0
  518. package/archetypes/tower-defense/assets/sprites/glow.png.ogt +7 -0
  519. package/archetypes/tower-defense/assets/sprites/ring.png +0 -0
  520. package/archetypes/tower-defense/assets/sprites/ring.png.ogt +7 -0
  521. package/archetypes/tower-defense/assets/sprites/spark.png +0 -0
  522. package/archetypes/tower-defense/assets/sprites/spark.png.ogt +7 -0
  523. package/archetypes/tower-defense/assets/strings/en.ogt +47 -0
  524. package/archetypes/tower-defense/assets/strings/zh-CN.ogt +47 -0
  525. package/archetypes/tower-defense/assets/tiles/garden.ogt +10 -0
  526. package/archetypes/tower-defense/assets/tiles/garden.png +0 -0
  527. package/archetypes/tower-defense/assets/tiles/garden.png.ogt +7 -0
  528. package/archetypes/tower-defense/gitattributes +22 -0
  529. package/archetypes/tower-defense/host.d.ts +46 -0
  530. package/archetypes/tower-defense/package.json +18 -0
  531. package/archetypes/tower-defense/project.ogt +14 -0
  532. package/archetypes/tower-defense/references/metal/end.png +0 -0
  533. package/archetypes/tower-defense/references/metal/title.png +0 -0
  534. package/archetypes/tower-defense/references/metal/wave.png +0 -0
  535. package/archetypes/tower-defense/src/art.ts +24 -0
  536. package/archetypes/tower-defense/src/components.ts +156 -0
  537. package/archetypes/tower-defense/src/main.ts +253 -0
  538. package/archetypes/tower-defense/src/systems.ts +658 -0
  539. package/archetypes/tower-defense/src/ui.ts +382 -0
  540. package/archetypes/tower-defense/tests/flow.og.ts +56 -0
  541. package/archetypes/tower-defense/tests/frames.og.ts +31 -0
  542. package/archetypes/tower-defense/tests/frames.ts +134 -0
  543. package/archetypes/tower-defense/tests/lib.ts +81 -0
  544. package/archetypes/tower-defense/tests/lose.og.ts +40 -0
  545. package/archetypes/tower-defense/tests/maze.og.ts +53 -0
  546. package/archetypes/tower-defense/tests/pad.og.ts +41 -0
  547. package/archetypes/tower-defense/tests/pause.og.ts +59 -0
  548. package/archetypes/tower-defense/tests/phone.og.ts +49 -0
  549. package/archetypes/tower-defense/tests/replay.og.ts +28 -0
  550. package/archetypes/tower-defense/tests/win.og.ts +58 -0
  551. package/archetypes/tower-defense/tools/make-assets.py +640 -0
  552. package/archetypes/tower-defense/tools/oglite.py +285 -0
  553. package/archetypes/tower-defense/tsconfig.json +17 -0
  554. package/bin/create.ts +496 -0
  555. package/looks/catalogue.json +1871 -0
  556. package/package.json +31 -4
  557. package/template/.origin/setup +14 -0
  558. package/template/LICENSES.md +23 -0
  559. package/template/README.md +37 -0
  560. package/template/assets/ai/guard.ogt +48 -0
  561. package/template/assets/audio/blip.wav +0 -0
  562. package/template/assets/audio/click.ogt +9 -0
  563. package/template/assets/fonts/NotoSansSC-Regular-subset.ttf +0 -0
  564. package/template/assets/fonts/NotoSansSC-Regular-subset.ttf.ogt +12 -0
  565. package/template/assets/fonts/OFL.txt +93 -0
  566. package/template/assets/looks/origin-game.ogt +12 -0
  567. package/template/assets/models/dropship.glb +0 -0
  568. package/template/assets/models/walker.glb +0 -0
  569. package/template/assets/nav/yard.ogt +27 -0
  570. package/template/assets/scenes/main.ogt +34 -0
  571. package/template/assets/strings/en.ogt +14 -0
  572. package/template/assets/textures/stone.png +0 -0
  573. package/template/assets/textures/stone_n.png +0 -0
  574. package/template/assets/textures/stone_n.png.ogt +7 -0
  575. package/template/gitattributes +22 -0
  576. package/template/package.json +18 -0
  577. package/template/project.ogt +25 -0
  578. package/template/src/main.ts +246 -0
  579. package/template/tests/guard.og.ts +67 -0
  580. package/template/tests/smoke.og.ts +43 -0
  581. package/template/tsconfig.json +17 -0
@@ -0,0 +1,658 @@
1
+ // Path Guard's systems, in tick order: Control (the cursor, the tray keys,
2
+ // a tap or a key setting a plant), Plants (reloads, sight, the shooting
3
+ // clip), Visitors (the waves, the walk, hits landing, pops and leaks) and
4
+ // Voices (each requested sound once). The UI is src/ui.ts; `fire`, the
5
+ // plants' behaviour command, is here.
6
+ //
7
+ // A plant's mind is data: assets/ai/plant.ogt, run by og.ai before these
8
+ // systems, checks that the plant is set and reloaded and sees a visitor
9
+ // (og.Perception picks the nearest within range), then raises the `fire`
10
+ // command, which sends a shot along a tween. The tween's tag names the
11
+ // visitor's pool slot and the plant's kind, so Visitors applies the hit on
12
+ // the tick it lands. The visitors walk og.nav's flow field to the doorstep;
13
+ // every plant set re-costs the field's grid, and a plant that would close
14
+ // the path (for the gate or any visitor on the field) is refused.
15
+
16
+ import { og, defineSystem, NAV_ARRIVED } from "@origingame/engine";
17
+ import type { Entity, Value, View, World } from "@origingame/engine";
18
+ import { Bed, Cursor, Game, Phase, Plant, PLANTS, Prefs, Refusal, Sfx, Shot, Sound, Tuning, Visitor } from "./components.ts";
19
+ import { clipOf } from "./art.ts";
20
+ import { say } from "./ui.ts";
21
+
22
+ /** The field: 9 × 13 cells of one world unit; the map's top-left corner is at (0, 13). */
23
+ export const COLS = 9;
24
+ export const ROWS = 13;
25
+ /** The gate's cell (the visitors' spawn) and the doorstep's (their goal), map columns and rows. */
26
+ export const GATE = { x: 4, y: 0 } as const;
27
+ export const DOOR = { x: 4, y: 12 } as const;
28
+ /** Pool sizes. */
29
+ export const VISITORS = 24;
30
+ export const SHOTS = 24;
31
+ /** A visitor's pop lasts this long before its row is parked. */
32
+ const POP_TICKS = 36;
33
+ /** Where parked rows wait, far outside every plant's sight. */
34
+ const PARK = { x: -40, y: -40, z: 0 } as const;
35
+
36
+ /** A visitor's base numbers by Kind.*: health, speed (m/s), bounty (coins), light it takes. */
37
+ export const KINDS = [
38
+ { name: "beetle", hp: 34, speed: 1.3, bounty: 6, harm: 1 },
39
+ { name: "moth", hp: 22, speed: 2.1, bounty: 5, harm: 1 },
40
+ { name: "snail", hp: 140, speed: 0.75, bounty: 20, harm: 3 },
41
+ ] as const;
42
+
43
+ /** The waves, one letter per visitor in the order they come: b beetle, m moth, s snail. */
44
+ export const WAVES = ["bbbbbb", "bbmbbmbbmb", "mmbmmbmmbmmb", "bbsbbmbbmbbsbb", "sbbmmbbsmmbbmmbbsm"] as const;
45
+
46
+ const WHITE = { r: 1, g: 1, b: 1 };
47
+ const GOLD = { r: 1, g: 0.78, b: 0.25 };
48
+ const RED = { r: 1, g: 0.32, b: 0.3 };
49
+ const MINT = { r: 0.6, g: 1, b: 0.75 };
50
+ const FROSTED = { r: 0.55, g: 0.8, b: 1 };
51
+
52
+ type GameV = Value<typeof Game>;
53
+ type TuneV = Value<typeof Tuning>;
54
+
55
+ /** The camera feel's scale: 0.3 under reduced motion (og-feel), 1 otherwise. */
56
+ export function feel(world: World): number {
57
+ const p = world.resource(Prefs);
58
+ return p.ok && p.value.reducedMotion ? 0.3 : 1;
59
+ }
60
+
61
+ function must(r: { ok: true } | { ok: false; reason: string }): void {
62
+ if (!r.ok) throw new Error(r.reason);
63
+ }
64
+
65
+ /**
66
+ * Tuning, read on its first use in this call: a resource read is a call into
67
+ * the engine that encodes every field, so a system that needs the knobs only
68
+ * on an event does not pay for them every tick.
69
+ */
70
+ export function lazyTuning(world: World): TuneV {
71
+ let v: TuneV | null = null;
72
+ return new Proxy({} as TuneV, { get: (_, k) => ((v ??= must2(world.resource(Tuning))) as unknown as Record<string | symbol, unknown>)[k] });
73
+ }
74
+
75
+ function must2<T>(r: { ok: true; value: T } | { ok: false; reason: string }): T {
76
+ if (!r.ok) throw new Error(r.reason);
77
+ return r.value;
78
+ }
79
+
80
+ /** A cell's centre in world units (map rows count down from the top). */
81
+ export function cellCenter(x: number, y: number): { x: number; y: number } {
82
+ return { x: x + 0.5, y: ROWS - y - 0.5 };
83
+ }
84
+
85
+ /** The map cell under a world point. */
86
+ export function cellOf(px: number, py: number): { x: number; y: number } {
87
+ return { x: Math.floor(px), y: ROWS - 1 - Math.floor(py) };
88
+ }
89
+
90
+ /** Whether a map cell can take a plant: the lawn inside the hedge, not a stone. */
91
+ export function buildable(world: World, g: GameV, x: number, y: number): boolean {
92
+ if (x < 1 || x > COLS - 2 || y < 1 || y > ROWS - 2) return false;
93
+ return og.tilemap.getTile(world, g.map as unknown as Entity, "walls", x, y) < 0;
94
+ }
95
+
96
+ /** The pads tile of each plant (tiles/garden.ogt): the map remembers what grows where. */
97
+ export const PAD = [6, 8, 9] as const;
98
+
99
+ /** The plant on a cell by its pads tile (Plant.*), or -1. */
100
+ export function padOf(world: World, g: GameV, x: number, y: number): number {
101
+ return (PAD as readonly number[]).indexOf(og.tilemap.getTile(world, g.map as unknown as Entity, "pads", x, y));
102
+ }
103
+
104
+ export function cost(t: TuneV, kind: number): number {
105
+ return kind === Plant.Thorn ? t.thornCost : kind === Plant.Frost ? t.frostCost : t.hedgeCost;
106
+ }
107
+
108
+ export function range(t: TuneV, kind: number): number {
109
+ return kind === Plant.Thorn ? t.thornRange : kind === Plant.Frost ? t.frostRange : 0;
110
+ }
111
+
112
+ function occupied(g: GameV, x: number, y: number): boolean {
113
+ const i = y * COLS + x;
114
+ const word = [g.occ0, g.occ1, g.occ2, g.occ3][i >> 5]!;
115
+ return (word & (1 << (i & 31))) !== 0;
116
+ }
117
+
118
+ function float(world: World, text: string, x: number, y: number, color: { r: number; g: number; b: number }, crit = false, size = 0.42): void {
119
+ must(og.render.floatingText(world, { text, position: { x, y, z: 0 }, size, color, crit, rise: 1, lifetime: 0.8 }));
120
+ }
121
+
122
+ /**
123
+ * Sets the selected plant on a cell, or refuses with the reason: too few
124
+ * coins, the cell taken, a visitor standing there, or a path closed (the
125
+ * gate's to the doorstep or any visitor's). The grid's cost is set first and
126
+ * put back when the path check fails.
127
+ */
128
+ export function place(world: World, g: GameV, t: TuneV, x: number, y: number): boolean {
129
+ const refuse = (why: number, text: string) => {
130
+ g.refused += 1;
131
+ g.refusal = why;
132
+ g.refusedTick = world.tick;
133
+ const c = cellCenter(x, y);
134
+ float(world, text, c.x, c.y + 0.6, RED, false, 0.36);
135
+ return false;
136
+ };
137
+ if (!buildable(world, g, x, y) || padOf(world, g, x, y) >= 0 || occupied(g, x, y)) return refuse(Refusal.Taken, say(world, "float.taken"));
138
+ const price = cost(t, g.selected);
139
+ if (g.gold < price) return refuse(Refusal.Poor, say(world, "float.poor", { n: price - g.gold }));
140
+ const grid = g.grid as unknown as never;
141
+ const navY = ROWS - 1 - y;
142
+ must(og.nav.setCost(world, grid, x, navY, 0));
143
+ if (!pathsOpen(world, g)) {
144
+ must(og.nav.setCost(world, grid, x, navY, 1));
145
+ return refuse(Refusal.Blocked, say(world, "float.blocked"));
146
+ }
147
+ g.gold -= price;
148
+ g.placed += 1;
149
+ // The pads layer holds which plant stands on each cell; the Plants system switches the cell's row on.
150
+ must(og.tilemap.setTile(world, { entity: g.map as unknown as Entity, layer: "pads", x, y, tile: PAD[g.selected]! }));
151
+ g.pendingPlants += 1;
152
+ g.sfx |= Sound.Plant;
153
+ return true;
154
+ }
155
+
156
+ /** Whether the gate and every cell a visitor stands on still reach the doorstep. */
157
+ function pathsOpen(world: World, g: GameV): boolean {
158
+ const grid = g.grid as unknown as never;
159
+ const goal = cellCenter(DOOR.x, DOOR.y);
160
+ const to = { x: goal.x, y: goal.y, z: 0 };
161
+ const reaches = (cx: number, cy: number) => {
162
+ const from = cellCenter(cx, cy);
163
+ const p = og.nav.findPath(world, { nav: grid, from: { x: from.x, y: from.y, z: 0 }, to, smooth: false });
164
+ return p.ok && p.value.complete;
165
+ };
166
+ if (!reaches(GATE.x, GATE.y)) return false;
167
+ for (let i = 0; i < COLS * ROWS; i++) if (occupied(g, i % COLS, Math.floor(i / COLS)) && !reaches(i % COLS, Math.floor(i / COLS))) return false;
168
+ return true;
169
+ }
170
+
171
+ /** The world point under a CSS pixel of the play surface, through the camera Frame wrote. */
172
+ export function screenToWorld(world: World, px: number, py: number): { x: number; y: number } | null {
173
+ const cam = world.resource(og.Camera);
174
+ const vp = og.ui.viewport(world);
175
+ if (!cam.ok || vp.height <= 0) return null;
176
+ const scale = vp.height / cam.value.height;
177
+ return { x: cam.value.position.x + (px - vp.width / 2) / scale, y: cam.value.position.y - (py - vp.height / 2) / scale };
178
+ }
179
+
180
+ /**
181
+ * The player's hands: the cursor (arrows, WASD, the pad's d-pad), the tray
182
+ * (1, 2, 3, the pad's X), setting a plant (Space, Enter, the pad's A, or a
183
+ * tap on the lawn, which also moves the cursor), the next wave (N, the
184
+ * pad's Y) and pause (Escape, P, the pad's Start). Every input is answered
185
+ * on its tick: the cursor moves with a tick of sound, a plant pops up, a
186
+ * refusal says why.
187
+ */
188
+ export const Control = defineSystem(
189
+ "Control",
190
+ { reads: [og.Input, og.Gamepad, og.Camera, Tuning], writes: [Game, Cursor, og.Transform] },
191
+ (q, time, world) => {
192
+ const game = world.resource(Game);
193
+ const input = world.resource(og.Input);
194
+ const pad = world.resource(og.Gamepad);
195
+ if (!game.ok || !input.ok || !pad.ok) return;
196
+ const g = game.value;
197
+ const t = lazyTuning(world);
198
+ const inp = input.value;
199
+ const gp = pad.value;
200
+ const playing = g.phase === Phase.Play && !g.paused && !g.settingsOpen;
201
+ for (const a of q.archetypes()) {
202
+ const cur = a.column(Cursor);
203
+ const p = a.column(og.Transform).position;
204
+ for (let i = 0; i < a.count; i++) {
205
+ if (!playing) {
206
+ p[i * 3] = PARK.x;
207
+ p[i * 3 + 1] = PARK.y;
208
+ // Focus moving over a menu ticks (og-ui plays nothing when keyboard or pad focus moves).
209
+ const nav = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Tab"].some((k) => inp.pressed(k)) || (["up", "down", "left", "right"] as const).some((b) => gp.pressed(b));
210
+ if (nav) g.sfx |= Sound.Move;
211
+ continue;
212
+ }
213
+ let dx = 0;
214
+ let dy = 0;
215
+ if (inp.pressed("ArrowLeft") || inp.pressed("KeyA") || gp.pressed("left")) dx -= 1;
216
+ if (inp.pressed("ArrowRight") || inp.pressed("KeyD") || gp.pressed("right")) dx += 1;
217
+ if (inp.pressed("ArrowUp") || inp.pressed("KeyW") || gp.pressed("up")) dy -= 1;
218
+ if (inp.pressed("ArrowDown") || inp.pressed("KeyS") || gp.pressed("down")) dy += 1;
219
+ if (dx !== 0 || dy !== 0) {
220
+ g.cursorX = Math.max(1, Math.min(COLS - 2, g.cursorX + dx));
221
+ g.cursorY = Math.max(1, Math.min(ROWS - 2, g.cursorY + dy));
222
+ cur.moves[i] = cur.moves[i]! + 1;
223
+ g.sfx |= Sound.Move;
224
+ }
225
+ if (inp.pressed("Digit1")) select(g, Plant.Thorn);
226
+ if (inp.pressed("Digit2")) select(g, Plant.Frost);
227
+ if (inp.pressed("Digit3")) select(g, Plant.Hedge);
228
+ if (gp.pressed("x")) select(g, (g.selected + 1) % PLANTS.length);
229
+ if (inp.pressed("KeyN") || gp.pressed("y")) g.callNext = true;
230
+ if (inp.pressed("Escape") || inp.pressed("KeyP") || gp.pressed("start")) g.paused = true;
231
+ if (inp.pressed("Space") || inp.pressed("Enter") || gp.pressed("a")) place(world, g, t, g.cursorX, g.cursorY);
232
+ // A tap on the lawn moves the cursor there and plants.
233
+ if (inp.buttonPressed("left")) {
234
+ const at = screenToWorld(world, inp.pointer.x, inp.pointer.y);
235
+ if (at !== null && at.x >= 0 && at.x < COLS && at.y >= 0 && at.y < ROWS) {
236
+ const c = cellOf(at.x, at.y);
237
+ g.cursorX = c.x;
238
+ g.cursorY = c.y;
239
+ place(world, g, t, c.x, c.y);
240
+ }
241
+ }
242
+ const c = cellCenter(g.cursorX, g.cursorY);
243
+ p[i * 3] = c.x;
244
+ p[i * 3 + 1] = c.y;
245
+ // The cursor and, for a shooting plant, its range: drawn this tick.
246
+ const ok = buildable(world, g, g.cursorX, g.cursorY) && g.gold >= cost(t, g.selected);
247
+ const frame = ok ? 18 : 19;
248
+ const sheet = g.sheet as unknown as never;
249
+ must(og.render.sprite(world, { texture: sheet, position: { x: c.x, y: c.y, z: 0 }, width: 1, height: 1, uv: [(frame % 8) / 8, Math.floor(frame / 8) / 3, (frame % 8 + 1) / 8, (Math.floor(frame / 8) + 1) / 3], layer: 8 }));
250
+ const r = range(t, g.selected);
251
+ if (ok && r > 0) must(og.render.sprite(world, { texture: g.ring as unknown as never, position: { x: c.x, y: c.y, z: 0 }, width: r * 2, height: r * 2, layer: 7, opacity: 0.85 }));
252
+ }
253
+ }
254
+ void time;
255
+ },
256
+ );
257
+
258
+ function select(g: GameV, kind: number): void {
259
+ if (g.selected !== kind) g.sfx |= Sound.Move;
260
+ g.selected = kind;
261
+ }
262
+
263
+ /** Plants: reload, sight from the tunables, the shooting clip back to the sway. Held by a hit stop. */
264
+ export const Plants = defineSystem(
265
+ "Plants",
266
+ { reads: [Tuning], writes: [Game, Bed, og.Perception, og.Flipbook, og.Sprite, og.AiAgent], after: ["Control"] },
267
+ (q, time, world) => {
268
+ const game = world.resource(Game);
269
+ if (!game.ok) return;
270
+ const t = lazyTuning(world);
271
+ // Sight follows the tunables twice a second (Tune writes them live).
272
+ const refresh = world.tick % 30 === 0;
273
+ const g = game.value;
274
+ const held = time.hitStop > 0 || g.paused || g.phase !== Phase.Play;
275
+ const reset = g.reset;
276
+ const pending = g.pendingPlants > 0;
277
+ if (pending) g.pendingPlants = 0;
278
+ for (const a of q.archetypes()) {
279
+ const b = a.column(Bed);
280
+ const per = a.column(og.Perception);
281
+ const fb = a.column(og.Flipbook);
282
+ const sprite = a.column(og.Sprite);
283
+ const ai = a.column(og.AiAgent);
284
+ for (let i = 0; i < a.count; i++) {
285
+ if (reset) {
286
+ b.planted[i] = 0;
287
+ b.cool[i] = 0;
288
+ b.anim[i] = 0;
289
+ b.shots[i] = 0;
290
+ sprite.visible[i] = 0;
291
+ ai.active[i] = 0;
292
+ per.sight[i] = 0;
293
+ continue;
294
+ }
295
+ if (pending && !b.planted[i]) {
296
+ // A plant set this tick: its cell's pads tile names it.
297
+ const kind = padOf(world, g, b.cellX[i]!, b.cellY[i]!);
298
+ if (kind >= 0) {
299
+ b.planted[i] = 1;
300
+ b.kind[i] = kind;
301
+ b.cool[i] = 20;
302
+ b.anim[i] = 0;
303
+ sprite.visible[i] = 1;
304
+ fb.clip[i] = clipOf(PLANTS[kind]!);
305
+ ai.active[i] = kind === Plant.Hedge ? 0 : 1;
306
+ per.sight[i] = range(t, kind);
307
+ must(og.tween.squash(world, { entity: a.entity(i), impact: { x: 0.6, y: 1.5 }, duration: 0.25 }));
308
+ }
309
+ }
310
+ if (!b.planted[i]) continue;
311
+ if (refresh) per.sight[i] = range(t, b.kind[i]!);
312
+ if (held) continue;
313
+ if (b.cool[i]! > 0) b.cool[i] = b.cool[i]! - 1;
314
+ if (b.anim[i]! > 0) {
315
+ b.anim[i] = b.anim[i]! - 1;
316
+ if (b.anim[i] === 0) fb.clip[i] = clipOf(PLANTS[b.kind[i]!]!);
317
+ }
318
+ }
319
+ }
320
+ },
321
+ );
322
+
323
+ /** Tween tags of shots: (kind + 1) × 1000 + the visitor's slot. */
324
+ const TAG = 1000;
325
+
326
+ /**
327
+ * `fire:<plant>`: the behaviour's shot (og.ai queues it with the plant's
328
+ * handle). It sends a free shot from the plant to where its target will be
329
+ * when the shot lands, on a tween whose tag names the target and the kind.
330
+ */
331
+ export function fire(world: World, args: readonly string[]): void {
332
+ const me = Number(args[0]) as Entity;
333
+ const game = world.resource(Game);
334
+ const tune = world.resource(Tuning);
335
+ const bed = world.get(me, Bed);
336
+ const eyes = world.get(me, og.Perception);
337
+ const at = world.get(me, og.Transform);
338
+ if (!game.ok || !tune.ok || !bed.ok || !eyes.ok || !at.ok) throw new Error(`fire: ${args[0]} is not a plant`);
339
+ const g = game.value;
340
+ const t = tune.value;
341
+ const b = bed.value;
342
+ if (!b.planted || b.cool > 0 || !eyes.value.sees || g.phase !== Phase.Play || g.paused) return;
343
+ const target = eyes.value.target as Entity;
344
+ const v = world.get(target, Visitor);
345
+ const tp = world.get(target, og.Transform);
346
+ const nav = world.get(target, og.NavAgent);
347
+ if (!v.ok || !tp.ok || !nav.ok || !v.value.active || v.value.dying > 0) return;
348
+ let shot: Entity | null = null;
349
+ for (let k = 0; k < SHOTS && shot === null; k++) {
350
+ const e = world.find(`shot-${(g.shots + k) % SHOTS}`);
351
+ if (e !== null) {
352
+ const s = world.get(e, Shot);
353
+ if (s.ok && (s.value.tween === 0 || !og.tween.active(world, s.value.tween as unknown as never))) shot = e;
354
+ }
355
+ }
356
+ if (shot === null) return;
357
+ const from = { x: at.value.position.x, y: at.value.position.y + 0.2 };
358
+ let to = { x: tp.value.position.x, y: tp.value.position.y };
359
+ const flight = Math.min(0.5, Math.hypot(to.x - from.x, to.y - from.y) / t.shotSpeed);
360
+ // Lead the target by where it walks during the flight.
361
+ to = { x: to.x + nav.value.velocity.x * flight, y: to.y + nav.value.velocity.y * flight };
362
+ const kind = b.kind;
363
+ must(world.set(shot, og.Transform, { position: { x: from.x, y: from.y, z: 0 } }));
364
+ must(world.set(shot, og.Sprite, { opacity: 1, visible: true }));
365
+ must(world.set(shot, og.Flipbook, { clip: clipOf(kind === Plant.Frost ? "flake" : "seed") }));
366
+ const flightTween = must2(
367
+ og.tween.sequence(
368
+ world,
369
+ [
370
+ { entity: shot, field: "position", from: [from.x, from.y, 0], to: [to.x, to.y, 0], duration: flight, ease: "linear" },
371
+ { entity: shot, component: og.Sprite, field: "opacity", to: [0], duration: 0.05, ease: "linear" },
372
+ ],
373
+ { tag: (kind + 1) * TAG + v.value.slot },
374
+ ),
375
+ );
376
+ must(world.set(shot, Shot, { tween: flightTween as unknown as number }));
377
+ must(world.set(me, Bed, { cool: kind === Plant.Frost ? t.frostReload : t.thornReload, anim: 12, shots: b.shots + 1 }));
378
+ must(world.set(me, og.Flipbook, { clip: clipOf(`${PLANTS[kind]}_shoot`) }));
379
+ must(og.tween.squash(world, { entity: me, impact: { x: 1.15, y: 0.85 }, duration: 0.15 }));
380
+ g.shots += 1;
381
+ g.sfx |= kind === Plant.Frost ? Sound.Frost : Sound.Thorn;
382
+ }
383
+
384
+ /**
385
+ * The visitors and the waves: a wave starts after the break (or at once,
386
+ * on the player's call, which pays a bonus for the seconds saved), its
387
+ * visitors come through the gate one gap apart and walk the flow field;
388
+ * shots land by their tween's tag; a visitor at 0 health pops (a coin
389
+ * count, a burst of petals, a light hit stop at most every 10 ticks); one
390
+ * that reaches the doorstep takes its light (shake, hit stop, a red
391
+ * number). The last visitor of the last wave gone ends the round as won;
392
+ * the light at 0 ends it lost.
393
+ */
394
+ export const Visitors = defineSystem(
395
+ "Visitors",
396
+ {
397
+ reads: [Tuning, Prefs, og.TweenCompleted],
398
+ writes: [Game, Visitor, og.Transform, og.Sprite, og.NavAgent, og.Flipbook, og.ParticleSystem],
399
+ after: ["Plants"],
400
+ },
401
+ (q, time, world) => {
402
+ const game = world.resource(Game);
403
+ if (!game.ok) return;
404
+ const g = game.value;
405
+ const t = lazyTuning(world);
406
+ // Shots that landed this tick: damage and frost by the visitor's slot.
407
+ const damage = new Array<number>(VISITORS).fill(0);
408
+ const frost = new Array<boolean>(VISITORS).fill(false);
409
+ for (const e of world.events(og.TweenCompleted)) {
410
+ if (e.tag < TAG) continue;
411
+ const kind = Math.floor(e.tag / TAG) - 1;
412
+ const slot = e.tag % TAG;
413
+ if (slot < VISITORS) {
414
+ damage[slot] = damage[slot]! + (kind === Plant.Frost ? t.frostDamage : t.thornDamage);
415
+ if (kind === Plant.Frost) frost[slot] = true;
416
+ }
417
+ }
418
+ const playing = g.phase === Phase.Play && !g.paused;
419
+ const held = time.hitStop > 0 || !playing;
420
+
421
+ // The wave clock.
422
+ let spawnKind = -1;
423
+ if (playing && time.hitStop === 0) {
424
+ if (!g.inWave && g.wave < WAVES.length) {
425
+ if (g.callNext && g.breakTicks > 0) {
426
+ const bonus = Math.ceil(g.breakTicks / 60) * 2;
427
+ g.gold += bonus;
428
+ g.breakTicks = 0;
429
+ }
430
+ if (g.breakTicks > 0) g.breakTicks -= 1;
431
+ if (g.breakTicks === 0) startWave(world, g);
432
+ } else if (g.inWave && g.toSpawn > 0) {
433
+ if (g.spawnTicks > 0) g.spawnTicks -= 1;
434
+ if (g.spawnTicks === 0) {
435
+ const letters = WAVES[g.wave - 1]!;
436
+ spawnKind = "bms".indexOf(letters[g.spawned]!);
437
+ g.spawned += 1;
438
+ g.toSpawn -= 1;
439
+ g.spawnTicks = Math.max(1, Math.round(t.spawnGap * 60));
440
+ }
441
+ }
442
+ }
443
+ if (g.callNext) g.callNext = false;
444
+
445
+ let walking = 0;
446
+ const occ = [0, 0, 0, 0];
447
+ const goal = cellCenter(DOOR.x, DOOR.y);
448
+ const gate = cellCenter(GATE.x, GATE.y);
449
+ for (const a of q.archetypes()) {
450
+ const v = a.column(Visitor);
451
+ const p = a.column(og.Transform).position;
452
+ const sprite = a.column(og.Sprite);
453
+ const nav = a.column(og.NavAgent);
454
+ const fb = a.column(og.Flipbook);
455
+ const fx = a.column(og.ParticleSystem);
456
+ for (let i = 0; i < a.count; i++) {
457
+ const me = a.entity(i);
458
+ if (g.reset) {
459
+ v.active[i] = 0;
460
+ v.dying[i] = 0;
461
+ sprite.visible[i] = 0;
462
+ park(p, nav, fx, i);
463
+ continue;
464
+ }
465
+ if (v.dying[i]! > 0) {
466
+ if (!held) v.dying[i] = v.dying[i]! - 1;
467
+ if (v.dying[i] === 0) park(p, nav, fx, i);
468
+ continue;
469
+ }
470
+ if (!v.active[i]) {
471
+ if (spawnKind >= 0) {
472
+ // Through the gate: this row is the next visitor.
473
+ const k = KINDS[spawnKind]!;
474
+ const hp = Math.round(k.hp * (1 + t.hpGrowth * (g.wave - 1)));
475
+ v.active[i] = 1;
476
+ v.kind[i] = spawnKind;
477
+ v.hp[i] = hp;
478
+ v.maxHp[i] = hp;
479
+ v.speed[i] = k.speed;
480
+ v.slow[i] = 0;
481
+ p[i * 3] = gate.x;
482
+ p[i * 3 + 1] = gate.y + 0.3;
483
+ sprite.visible[i] = 1;
484
+ sprite.opacity[i] = 1;
485
+ sprite.color[i * 3] = 1;
486
+ sprite.color[i * 3 + 1] = 1;
487
+ sprite.color[i * 3 + 2] = 1;
488
+ fb.clip[i] = clipOf(k.name);
489
+ nav.seeking[i] = 1;
490
+ nav.speed[i] = k.speed;
491
+ spawnKind = -1;
492
+ }
493
+ continue;
494
+ }
495
+ if (damage[v.slot[i]!]! > 0 && !held) {
496
+ v.hp[i] = Math.max(0, v.hp[i]! - damage[v.slot[i]!]!);
497
+ if (frost[v.slot[i]!]) v.slow[i] = t.frostTicks;
498
+ must(og.tween.flash(world, { entity: me, duration: 0.08 }));
499
+ }
500
+ const x = p[i * 3]!;
501
+ const y = p[i * 3 + 1]!;
502
+ if (v.hp[i]! <= 0) {
503
+ pop(world, g, t, v, sprite, nav, fx, i, x, y);
504
+ continue;
505
+ }
506
+ if (Math.hypot(x - goal.x, y - goal.y) < 0.45 || nav.status[i] === NAV_ARRIVED) {
507
+ leak(world, g, t, v, i);
508
+ park(p, nav, fx, i);
509
+ sprite.visible[i] = 0;
510
+ continue;
511
+ }
512
+ if (!held && v.slow[i]! > 0) v.slow[i] = v.slow[i]! - 1;
513
+ const slowed = v.slow[i]! > 0;
514
+ nav.speed[i] = v.speed[i]! * (slowed ? t.frostSlow : 1);
515
+ fb.speed[i] = slowed ? t.frostSlow : 1;
516
+ const tint = slowed ? FROSTED : WHITE;
517
+ sprite.color[i * 3] = tint.r;
518
+ sprite.color[i * 3 + 1] = tint.g;
519
+ sprite.color[i * 3 + 2] = tint.b;
520
+ walking += 1;
521
+ const c = cellOf(x, y);
522
+ if (c.x >= 0 && c.x < COLS && c.y >= 0 && c.y < ROWS) {
523
+ const idx = c.y * COLS + c.x;
524
+ occ[idx >> 5] = (occ[idx >> 5]! | (1 << (idx & 31))) >>> 0;
525
+ }
526
+ // A health bar over a hurt visitor.
527
+ if (v.hp[i]! < v.maxHp[i]!) {
528
+ const f = v.hp[i]! / v.maxHp[i]!;
529
+ must(og.render.sprite(world, { position: { x: x - 0.35, y: y + 0.5, z: 0 }, width: 0.7, height: 0.1, anchor: { x: 0, y: 0.5 }, color: { r: 0.05, g: 0.08, b: 0.06 }, layer: 9 }));
530
+ must(og.render.sprite(world, { position: { x: x - 0.35, y: y + 0.5, z: 0 }, width: 0.7 * f, height: 0.1, anchor: { x: 0, y: 0.5 }, color: f > 0.5 ? { r: 0.35, g: 0.9, b: 0.45 } : { r: 1, g: 0.55, b: 0.2 }, layer: 9 }));
531
+ }
532
+ }
533
+ }
534
+ // A resource field written is a call into the engine: write only what changed.
535
+ if (g.reset) g.reset = false;
536
+ if (occ[0] !== g.occ0) g.occ0 = occ[0]!;
537
+ if (occ[1] !== g.occ1) g.occ1 = occ[1]!;
538
+ if (occ[2] !== g.occ2) g.occ2 = occ[2]!;
539
+ if (occ[3] !== g.occ3) g.occ3 = occ[3]!;
540
+ if (walking !== g.walking) g.walking = walking;
541
+
542
+ if (!playing) return;
543
+ if (g.lives === 0) {
544
+ endRound(world, g, false);
545
+ return;
546
+ }
547
+ if (g.inWave && g.toSpawn === 0 && walking === 0 && time.hitStop === 0) {
548
+ g.inWave = false;
549
+ const bonus = 20 + 5 * g.wave;
550
+ g.gold += bonus;
551
+ g.sfx |= Sound.Clear;
552
+ float(world, say(world, "float.clear", { n: bonus }), goal.x, goal.y + 2.2, MINT, true, 0.45);
553
+ if (g.wave >= WAVES.length) endRound(world, g, true);
554
+ else g.breakTicks = Math.max(1, Math.round(t.waveBreak * 60));
555
+ }
556
+ },
557
+ );
558
+
559
+ function startWave(world: World, g: GameV): void {
560
+ g.wave += 1;
561
+ g.inWave = true;
562
+ g.toSpawn = WAVES[g.wave - 1]!.length;
563
+ g.spawned = 0;
564
+ g.spawnTicks = 1;
565
+ g.sfx |= Sound.Wave;
566
+ const gate = cellCenter(GATE.x, GATE.y);
567
+ float(world, say(world, "float.wave", { n: g.wave }), gate.x, gate.y - 1.2, GOLD, true, 0.5);
568
+ }
569
+
570
+ function park(p: Float32Array, nav: View<typeof og.NavAgent>, fx: View<typeof og.ParticleSystem>, i: number): void {
571
+ p[i * 3] = PARK.x;
572
+ p[i * 3 + 1] = PARK.y;
573
+ nav.seeking[i] = 0;
574
+ fx.visible[i] = 0;
575
+ }
576
+
577
+ function pop(world: World, g: GameV, t: TuneV, v: View<typeof Visitor>, sprite: View<typeof og.Sprite>, nav: View<typeof og.NavAgent>, fx: View<typeof og.ParticleSystem>, i: number, x: number, y: number): void {
578
+ const k = KINDS[v.kind[i]!]!;
579
+ v.active[i] = 0;
580
+ v.dying[i] = POP_TICKS;
581
+ sprite.visible[i] = 0;
582
+ nav.seeking[i] = 0;
583
+ fx.visible[i] = 1;
584
+ fx.startTick[i] = world.tick;
585
+ g.kills += 1;
586
+ g.gold += k.bounty;
587
+ g.sfx |= Sound.Pop;
588
+ float(world, say(world, "float.gold", { n: k.bounty }), x, y + 0.4, GOLD);
589
+ // A light hit stop, at most one per 10 ticks so a stream of pops does not stutter (og-feel §3).
590
+ if (world.tick - g.lastStop >= 10 && t.killStop > 0) {
591
+ must(og.time.hitStop(world, t.killStop));
592
+ g.lastStop = world.tick;
593
+ }
594
+ }
595
+
596
+ function leak(world: World, g: GameV, t: TuneV, v: View<typeof Visitor>, i: number): void {
597
+ const k = KINDS[v.kind[i]!]!;
598
+ v.active[i] = 0;
599
+ g.leaks += 1;
600
+ g.lives = Math.max(0, g.lives - k.harm);
601
+ g.sfx |= Sound.Leak;
602
+ const goal = cellCenter(DOOR.x, DOOR.y);
603
+ float(world, say(world, "float.leak", { n: k.harm }), goal.x, goal.y + 0.8, RED, true, 0.5);
604
+ must(og.time.hitStop(world, t.leakStop));
605
+ const feelK = feel(world);
606
+ must(og.camera.shake(world, t.leakShake * feelK));
607
+ must(og.camera.kick(world, { x: 0, y: -1, z: 0 }, 0.15 * feelK));
608
+ const lantern = world.find("lantern");
609
+ if (lantern !== null) {
610
+ must(og.tween.flash(world, { entity: lantern, color: RED, duration: 0.25 }));
611
+ must(og.tween.squash(world, { entity: lantern, impact: { x: 1.25, y: 0.8 }, duration: 0.25 }));
612
+ }
613
+ }
614
+
615
+ /** The round is over: the score, the best (saved with its revision), the board and the telemetry. */
616
+ export function endRound(world: World, g: GameV, won: boolean): void {
617
+ g.phase = Phase.Over;
618
+ g.won = won;
619
+ g.inWave = false;
620
+ g.overTick = world.tick;
621
+ g.score = g.kills * 10 + g.lives * 50 + g.gold;
622
+ g.newBest = g.score > g.best;
623
+ g.sfx |= won ? Sound.Won : Sound.Lost;
624
+ if (g.newBest) {
625
+ g.best = g.score;
626
+ g.bestWrite = must2(og.platform.storeSet(world, { key: "best", value: g.score, revision: g.bestRevision }));
627
+ }
628
+ must(og.platform.leaderboardSubmit(world, { board: "main", score: g.score }));
629
+ must(og.platform.telemetry(world, "round.over", { won, wave: g.wave, kills: g.kills, lives: g.lives, score: g.score }));
630
+ }
631
+
632
+ /** Plays each requested sound once: a voice already playing is stopped this tick and restarted the next. */
633
+ export const Voices = defineSystem("Voices", { writes: [Game, Sfx, og.AudioSource, og.Rng], after: ["Visitors"] }, (q, _time, world) => {
634
+ const game = world.resource(Game);
635
+ if (!game.ok) return;
636
+ const g = game.value;
637
+ if (g.sfx === 0) return;
638
+ const rng = world.resource(og.Rng);
639
+ let left = g.sfx;
640
+ for (const a of q.archetypes()) {
641
+ const sfx = a.column(Sfx);
642
+ const src = a.column(og.AudioSource);
643
+ for (let i = 0; i < a.count; i++) {
644
+ const b = sfx.bit[i]!;
645
+ if ((g.sfx & b) === 0) continue;
646
+ if (src.playing[i]) {
647
+ src.playing[i] = 0;
648
+ } else {
649
+ src.playing[i] = 1;
650
+ sfx.plays[i] = sfx.plays[i]! + 1;
651
+ // Shots and pops vary a little, so a stream of them does not machine-gun (og-audio §1).
652
+ if ((b === Sound.Thorn || b === Sound.Pop || b === Sound.Frost) && rng.ok) src.pitch[i] = rng.value.range(0.92, 1.08);
653
+ left &= ~b;
654
+ }
655
+ }
656
+ }
657
+ g.sfx = left;
658
+ });