@nayan-ui/games 1.20.0 → 1.21.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 (552) hide show
  1. package/lib/module/games/arrows/Arrows.js +1 -1
  2. package/lib/module/games/arrows/ArrowsScene.js +1 -1
  3. package/lib/module/games/balloon-blaster/BalloonBlaster.js +1 -1
  4. package/lib/module/games/balloon-blaster/BalloonBlasterScene.js +1 -1
  5. package/lib/module/games/bike-racing/BikeMeshes.js +1 -1
  6. package/lib/module/games/bike-racing/BikeRacing.js +1 -1
  7. package/lib/module/games/bike-racing/BikeRacingConstants.js +1 -1
  8. package/lib/module/games/bike-racing/BikeRacingScene.js +1 -1
  9. package/lib/module/games/block-blast/BlockBlast.js +1 -1
  10. package/lib/module/games/block-blast/BlockBlastScene.js +1 -1
  11. package/lib/module/games/block-breaker/BlockBreaker.js +1 -1
  12. package/lib/module/games/block-breaker/BlockBreakerScene.js +1 -1
  13. package/lib/module/games/bluk/Bluk.js +1 -1
  14. package/lib/module/games/bluk/BlukScene.js +1 -1
  15. package/lib/module/games/bubble-shooter/BubbleShooter.js +1 -1
  16. package/lib/module/games/bubble-shooter/BubbleShooterScene.js +1 -1
  17. package/lib/module/games/candy-crush/CandyCrush.js +1 -1
  18. package/lib/module/games/candy-crush/CandyCrushScene.js +1 -1
  19. package/lib/module/games/car-racing/CarMeshes.js +1 -1
  20. package/lib/module/games/car-racing/CarRacing.js +1 -1
  21. package/lib/module/games/car-racing/CarRacingScene.js +1 -1
  22. package/lib/module/games/chameleon-run/ChameleonRun.js +1 -1
  23. package/lib/module/games/chameleon-run/ChameleonRunBackdrop.js +1 -1
  24. package/lib/module/games/chameleon-run/ChameleonRunMeshes.js +1 -1
  25. package/lib/module/games/checkers/Checkers.js +1 -1
  26. package/lib/module/games/checkers/CheckersScene.js +1 -1
  27. package/lib/module/games/color-switch/ColorSwitch.js +1 -1
  28. package/lib/module/games/color-switch/ColorSwitchScene.js +1 -1
  29. package/lib/module/games/colors-sort/ColorsSort.js +1 -1
  30. package/lib/module/games/colors-sort/ColorsSortScene.js +1 -1
  31. package/lib/module/games/connect-em-all/ConnectEmAll.js +1 -1
  32. package/lib/module/games/connect-em-all/ConnectEmAllScene.js +1 -1
  33. package/lib/module/games/crossy-road/CrossyRoad.js +1 -1
  34. package/lib/module/games/crossy-road/CrossyRoadMeshes.js +1 -1
  35. package/lib/module/games/crossy-road/CrossyRoadPerson.js +1 -1
  36. package/lib/module/games/dino-jump/DinoJump.js +1 -1
  37. package/lib/module/games/dino-jump/DinoJumpScene.js +1 -1
  38. package/lib/module/games/dots-and-boxes/DotsAndBoxes.js +1 -1
  39. package/lib/module/games/dots-and-boxes/DotsAndBoxesScene.js +1 -1
  40. package/lib/module/games/falling-sticks/FallingSticks.js +1 -1
  41. package/lib/module/games/falling-sticks/FallingSticksScene.js +1 -1
  42. package/lib/module/games/find-different-number/FindDifferentNumber.js +1 -1
  43. package/lib/module/games/find-different-number/FindDifferentNumberScene.js +1 -1
  44. package/lib/module/games/flappy-bird/FlappyBird.js +1 -1
  45. package/lib/module/games/flappy-bird/FlappyBirdScene.js +1 -1
  46. package/lib/module/games/fruit-merger/FruitMerger.js +1 -1
  47. package/lib/module/games/fruit-merger/FruitMergerScene.js +1 -1
  48. package/lib/module/games/fruit-ninja/FruitNinja.js +1 -1
  49. package/lib/module/games/fruit-ninja/FruitNinjaScene.js +1 -1
  50. package/lib/module/games/fruit-ninja/FruitNinjaWorld.js +1 -1
  51. package/lib/module/games/game-2048/Game2048.js +1 -1
  52. package/lib/module/games/game-2048/Game2048Scene.js +1 -1
  53. package/lib/module/games/knife-hit/KnifeHit.js +1 -1
  54. package/lib/module/games/knife-hit/KnifeHitScene.js +1 -1
  55. package/lib/module/games/ludo-king/LudoKing.js +1 -1
  56. package/lib/module/games/ludo-king/LudoKingScene.js +1 -1
  57. package/lib/module/games/maze-runner/MazeRunner.js +1 -1
  58. package/lib/module/games/maze-runner/MazeRunnerScene.js +1 -1
  59. package/lib/module/games/memory-match/MemoryMatch.js +1 -1
  60. package/lib/module/games/memory-match/MemoryMatchScene.js +1 -1
  61. package/lib/module/games/mine-sweeper/MineSweeper.js +1 -1
  62. package/lib/module/games/mine-sweeper/MineSweeperScene.js +1 -1
  63. package/lib/module/games/mob-control/MobControl.js +1 -1
  64. package/lib/module/games/mob-control/MobControlGame.js +1 -1
  65. package/lib/module/games/mob-control/MobControlMeshes.js +1 -1
  66. package/lib/module/games/mob-control/MobControlRenderer.js +1 -1
  67. package/lib/module/games/mob-control/MobControlRules.js +1 -1
  68. package/lib/module/games/mob-control/MobControlScene.js +1 -1
  69. package/lib/module/games/nuts-and-bolts/NutsAndBolts.js +1 -1
  70. package/lib/module/games/nuts-and-bolts/NutsAndBoltsScene.js +1 -1
  71. package/lib/module/games/pac-man/PacMan.js +1 -1
  72. package/lib/module/games/pac-man/PacManGame.js +1 -1
  73. package/lib/module/games/pac-man/PacManScene.js +1 -1
  74. package/lib/module/games/paper-io/PaperIo.js +1 -1
  75. package/lib/module/games/paper-io/PaperIoMeshes.js +1 -1
  76. package/lib/module/games/paper-io/PaperIoScene.js +1 -1
  77. package/lib/module/games/penguin-run/PenguinMeshes.js +1 -1
  78. package/lib/module/games/penguin-run/PenguinRun.js +1 -1
  79. package/lib/module/games/penguin-run/PenguinRunScene.js +1 -1
  80. package/lib/module/games/perfect-circle/PerfectCircle.js +1 -1
  81. package/lib/module/games/perfect-circle/PerfectCircleScene.js +1 -1
  82. package/lib/module/games/pipe-connect/PipeConnect.js +1 -1
  83. package/lib/module/games/pipe-connect/PipeConnectScene.js +1 -1
  84. package/lib/module/games/play-with-tua/PlayWithTua.js +1 -1
  85. package/lib/module/games/popit-fidget/PopitFidget.js +1 -1
  86. package/lib/module/games/popit-fidget/PopitFidgetScene.js +1 -1
  87. package/lib/module/games/reversi/Reversi.js +1 -1
  88. package/lib/module/games/reversi/ReversiScene.js +1 -1
  89. package/lib/module/games/search-grid/SearchGrid.js +1 -1
  90. package/lib/module/games/search-grid/SearchGridScene.js +1 -1
  91. package/lib/module/games/shared/BackdropCard.js +1 -1
  92. package/lib/module/games/shared/EngineBackdrop.js +1 -1
  93. package/lib/module/games/shared/EngineBlasts.js +1 -1
  94. package/lib/module/games/shared/EngineBlocks.js +1 -1
  95. package/lib/module/games/shared/EngineDice.js +1 -1
  96. package/lib/module/games/shared/EngineFruits.js +1 -1
  97. package/lib/module/games/shared/EngineGameLoader.js +1 -1
  98. package/lib/module/games/shared/EngineGameScreen.js +1 -1
  99. package/lib/module/games/shared/EngineGlyphs.js +1 -1
  100. package/lib/module/games/shared/EngineHud.js +1 -1
  101. package/lib/module/games/shared/EngineMeadow.js +1 -1
  102. package/lib/module/games/shared/EngineTouchSurface.js +1 -1
  103. package/lib/module/games/shared/GameActivity.js +1 -1
  104. package/lib/module/games/shared/GameLoading.js +1 -1
  105. package/lib/module/games/shared/GameLoadingTransition.js +1 -1
  106. package/lib/module/games/sliding-numbers/SlidingNumbers.js +1 -1
  107. package/lib/module/games/sliding-numbers/SlidingNumbersScene.js +1 -1
  108. package/lib/module/games/snake-3d/Snake3D.js +1 -1
  109. package/lib/module/games/snake-3d/Snake3DScene.js +1 -1
  110. package/lib/module/games/snakes-and-ladders/SnakesAndLadders.js +1 -1
  111. package/lib/module/games/snakes-and-ladders/SnakesAndLaddersScene.js +1 -1
  112. package/lib/module/games/space-fighter/SpaceFighter.js +1 -1
  113. package/lib/module/games/space-fighter/SpaceFighterScene.js +1 -1
  114. package/lib/module/games/spider-solitaire/SpiderSolitaire.js +1 -1
  115. package/lib/module/games/spider-solitaire/SpiderSolitaireScene.js +1 -1
  116. package/lib/module/games/stack-tower/StackTower.js +1 -1
  117. package/lib/module/games/stack-tower/StackTowerScene.js +1 -1
  118. package/lib/module/games/sudoku/Sudoku.js +1 -1
  119. package/lib/module/games/sudoku/SudokuScene.js +1 -1
  120. package/lib/module/games/tangram/Tangram.js +1 -1
  121. package/lib/module/games/tangram/TangramScene.js +1 -1
  122. package/lib/module/games/tank-1990/Tank1990.js +1 -1
  123. package/lib/module/games/tank-1990/Tank1990Scene.js +1 -1
  124. package/lib/module/games/tic-tac-toe/TicTacToe.js +1 -1
  125. package/lib/module/games/tic-tac-toe/TicTacToeScene.js +1 -1
  126. package/lib/module/games/tile-home/TileHome.js +1 -1
  127. package/lib/module/games/tile-home/TileHomeScene.js +1 -1
  128. package/lib/module/games/treasure-hunt/TreasureHunt.js +1 -1
  129. package/lib/module/games/treasure-hunt/TreasureHuntConstants.js +1 -1
  130. package/lib/module/games/treasure-hunt/TreasureHuntModel.js +1 -1
  131. package/lib/module/games/treasure-hunt/TreasureHuntScene.js +1 -1
  132. package/lib/module/games/whack-a-mole/WhackAMole.js +1 -1
  133. package/lib/module/games/whack-a-mole/WhackAMoleScene.js +1 -1
  134. package/lib/module/helpers/GameSettingsModal.js +1 -1
  135. package/lib/module/helpers/GameTheme.js +1 -1
  136. package/package.json +1 -2
  137. package/src/assets/fonts/Inter-SemiBold.ttf +0 -0
  138. package/src/assets/models/explorer/explorer.glb +0 -0
  139. package/src/assets/models/explorer/params.json +0 -51
  140. package/src/assets/models/explorer/source.json +0 -222
  141. package/src/assets/models/play-with-tua/play-with-tua.glb +0 -0
  142. package/src/assets/models/play-with-tua/sources.json +0 -141
  143. package/src/assets/sfx/balloon_pop.wav +0 -0
  144. package/src/assets/sfx/blocked.wav +0 -0
  145. package/src/assets/sfx/boing.wav +0 -0
  146. package/src/assets/sfx/bonus.wav +0 -0
  147. package/src/assets/sfx/boom.wav +0 -0
  148. package/src/assets/sfx/bump.wav +0 -0
  149. package/src/assets/sfx/cannon.wav +0 -0
  150. package/src/assets/sfx/capture.wav +0 -0
  151. package/src/assets/sfx/card_flip.wav +0 -0
  152. package/src/assets/sfx/card_place.wav +0 -0
  153. package/src/assets/sfx/catch.wav +0 -0
  154. package/src/assets/sfx/chime.wav +0 -0
  155. package/src/assets/sfx/chomp.wav +0 -0
  156. package/src/assets/sfx/chomp_alt.wav +0 -0
  157. package/src/assets/sfx/clack.wav +0 -0
  158. package/src/assets/sfx/clang.wav +0 -0
  159. package/src/assets/sfx/clash.wav +0 -0
  160. package/src/assets/sfx/click.wav +0 -0
  161. package/src/assets/sfx/coin.wav +0 -0
  162. package/src/assets/sfx/combo.wav +0 -0
  163. package/src/assets/sfx/crash.wav +0 -0
  164. package/src/assets/sfx/crunch.wav +0 -0
  165. package/src/assets/sfx/dance.wav +0 -0
  166. package/src/assets/sfx/deselect.wav +0 -0
  167. package/src/assets/sfx/dice_roll.wav +0 -0
  168. package/src/assets/sfx/die.wav +0 -0
  169. package/src/assets/sfx/draw.wav +0 -0
  170. package/src/assets/sfx/drop.wav +0 -0
  171. package/src/assets/sfx/eat.wav +0 -0
  172. package/src/assets/sfx/engine.wav +0 -0
  173. package/src/assets/sfx/error.wav +0 -0
  174. package/src/assets/sfx/flag.wav +0 -0
  175. package/src/assets/sfx/flap.wav +0 -0
  176. package/src/assets/sfx/flip_disc.wav +0 -0
  177. package/src/assets/sfx/footstep_run.wav +0 -0
  178. package/src/assets/sfx/footstep_walk.wav +0 -0
  179. package/src/assets/sfx/game_over.wav +0 -0
  180. package/src/assets/sfx/gate.wav +0 -0
  181. package/src/assets/sfx/hit.wav +0 -0
  182. package/src/assets/sfx/hop.wav +0 -0
  183. package/src/assets/sfx/hurt.wav +0 -0
  184. package/src/assets/sfx/invalid.wav +0 -0
  185. package/src/assets/sfx/jump.wav +0 -0
  186. package/src/assets/sfx/ladder.wav +0 -0
  187. package/src/assets/sfx/land.wav +0 -0
  188. package/src/assets/sfx/laugh.wav +0 -0
  189. package/src/assets/sfx/lose.wav +0 -0
  190. package/src/assets/sfx/merge.wav +0 -0
  191. package/src/assets/sfx/miss.wav +0 -0
  192. package/src/assets/sfx/nitro.wav +0 -0
  193. package/src/assets/sfx/pew.wav +0 -0
  194. package/src/assets/sfx/place.wav +0 -0
  195. package/src/assets/sfx/pling.wav +0 -0
  196. package/src/assets/sfx/point.wav +0 -0
  197. package/src/assets/sfx/pop.wav +0 -0
  198. package/src/assets/sfx/pop_soft.wav +0 -0
  199. package/src/assets/sfx/power_up.wav +0 -0
  200. package/src/assets/sfx/reveal.wav +0 -0
  201. package/src/assets/sfx/robot.wav +0 -0
  202. package/src/assets/sfx/rotate.wav +0 -0
  203. package/src/assets/sfx/run_steps.wav +0 -0
  204. package/src/assets/sfx/select.wav +0 -0
  205. package/src/assets/sfx/shuffle.wav +0 -0
  206. package/src/assets/sfx/six.wav +0 -0
  207. package/src/assets/sfx/slice.wav +0 -0
  208. package/src/assets/sfx/slide.wav +0 -0
  209. package/src/assets/sfx/snake.wav +0 -0
  210. package/src/assets/sfx/snap.wav +0 -0
  211. package/src/assets/sfx/splash.wav +0 -0
  212. package/src/assets/sfx/star.wav +0 -0
  213. package/src/assets/sfx/start.wav +0 -0
  214. package/src/assets/sfx/swoosh.wav +0 -0
  215. package/src/assets/sfx/tap.wav +0 -0
  216. package/src/assets/sfx/thud.wav +0 -0
  217. package/src/assets/sfx/thunk.wav +0 -0
  218. package/src/assets/sfx/tick.wav +0 -0
  219. package/src/assets/sfx/time_up.wav +0 -0
  220. package/src/assets/sfx/tock.wav +0 -0
  221. package/src/assets/sfx/walk_steps.wav +0 -0
  222. package/src/assets/sfx/warning.wav +0 -0
  223. package/src/assets/sfx/whack.wav +0 -0
  224. package/src/assets/sfx/whoosh.wav +0 -0
  225. package/src/assets/sfx/win.wav +0 -0
  226. package/src/assets/sfx/zap.wav +0 -0
  227. package/src/assets/textures/ad_bolt.png +0 -0
  228. package/src/assets/textures/ad_bubbles.png +0 -0
  229. package/src/assets/textures/ad_chevrons.png +0 -0
  230. package/src/assets/textures/asphalt.png +0 -0
  231. package/src/assets/textures/bark.jpg +0 -0
  232. package/src/assets/textures/explorer-atlas.png +0 -0
  233. package/src/assets/textures/facade.png +0 -0
  234. package/src/assets/textures/grass.png +0 -0
  235. package/src/assets/textures/leaves.png +0 -0
  236. package/src/assets/textures/limestone.jpg +0 -0
  237. package/src/assets/textures/meadow.jpg +0 -0
  238. package/src/assets/textures/nature-sources.json +0 -87
  239. package/src/assets/textures/pine.png +0 -0
  240. package/src/assets/textures/river.jpg +0 -0
  241. package/src/assets/textures/soft_glow.png +0 -0
  242. package/src/games/arrows/Arrows.tsx +0 -69
  243. package/src/games/arrows/ArrowsConstants.ts +0 -107
  244. package/src/games/arrows/ArrowsGame.ts +0 -735
  245. package/src/games/arrows/ArrowsScene.ts +0 -395
  246. package/src/games/balloon-blaster/BalloonBlaster.tsx +0 -75
  247. package/src/games/balloon-blaster/BalloonBlasterConstants.ts +0 -79
  248. package/src/games/balloon-blaster/BalloonBlasterGame.ts +0 -287
  249. package/src/games/balloon-blaster/BalloonBlasterPhysics.ts +0 -95
  250. package/src/games/balloon-blaster/BalloonBlasterScene.ts +0 -225
  251. package/src/games/bike-racing/BikeMeshes.ts +0 -273
  252. package/src/games/bike-racing/BikeRacing.tsx +0 -211
  253. package/src/games/bike-racing/BikeRacingConstants.ts +0 -103
  254. package/src/games/bike-racing/BikeRacingGame.ts +0 -557
  255. package/src/games/bike-racing/BikeRacingScene.ts +0 -119
  256. package/src/games/block-blast/BlockBlast.tsx +0 -73
  257. package/src/games/block-blast/BlockBlastConstants.ts +0 -179
  258. package/src/games/block-blast/BlockBlastGame.ts +0 -471
  259. package/src/games/block-blast/BlockBlastScene.ts +0 -156
  260. package/src/games/block-breaker/BlockBreaker.tsx +0 -79
  261. package/src/games/block-breaker/BlockBreakerConstants.ts +0 -139
  262. package/src/games/block-breaker/BlockBreakerGame.ts +0 -459
  263. package/src/games/block-breaker/BlockBreakerScene.ts +0 -257
  264. package/src/games/bluk/Bluk.tsx +0 -82
  265. package/src/games/bluk/BlukConstants.ts +0 -121
  266. package/src/games/bluk/BlukGame.ts +0 -323
  267. package/src/games/bluk/BlukRules.ts +0 -154
  268. package/src/games/bluk/BlukScene.ts +0 -514
  269. package/src/games/bubble-shooter/BubbleShooter.tsx +0 -76
  270. package/src/games/bubble-shooter/BubbleShooterConstants.ts +0 -103
  271. package/src/games/bubble-shooter/BubbleShooterGame.ts +0 -459
  272. package/src/games/bubble-shooter/BubbleShooterScene.ts +0 -158
  273. package/src/games/candy-crush/CandyCrush.tsx +0 -77
  274. package/src/games/candy-crush/CandyCrushConstants.ts +0 -94
  275. package/src/games/candy-crush/CandyCrushGame.ts +0 -477
  276. package/src/games/candy-crush/CandyCrushScene.ts +0 -209
  277. package/src/games/car-racing/CarMeshes.ts +0 -440
  278. package/src/games/car-racing/CarRacing.tsx +0 -211
  279. package/src/games/car-racing/CarRacingConstants.ts +0 -167
  280. package/src/games/car-racing/CarRacingFacade.ts +0 -40
  281. package/src/games/car-racing/CarRacingGame.ts +0 -539
  282. package/src/games/car-racing/CarRacingScene.ts +0 -1026
  283. package/src/games/car-racing/CarRacingScenery.ts +0 -265
  284. package/src/games/chameleon-run/ChameleonRun.tsx +0 -96
  285. package/src/games/chameleon-run/ChameleonRunBackdrop.ts +0 -186
  286. package/src/games/chameleon-run/ChameleonRunConstants.ts +0 -47
  287. package/src/games/chameleon-run/ChameleonRunGame.ts +0 -309
  288. package/src/games/chameleon-run/ChameleonRunMeshes.ts +0 -305
  289. package/src/games/chameleon-run/ChameleonRunRules.ts +0 -252
  290. package/src/games/chameleon-run/ChameleonRunScene.ts +0 -310
  291. package/src/games/checkers/Checkers.tsx +0 -83
  292. package/src/games/checkers/CheckersAI.ts +0 -255
  293. package/src/games/checkers/CheckersConstants.ts +0 -68
  294. package/src/games/checkers/CheckersGame.ts +0 -322
  295. package/src/games/checkers/CheckersRules.ts +0 -167
  296. package/src/games/checkers/CheckersScene.ts +0 -308
  297. package/src/games/color-switch/ColorSwitch.tsx +0 -75
  298. package/src/games/color-switch/ColorSwitchConstants.ts +0 -61
  299. package/src/games/color-switch/ColorSwitchGame.ts +0 -329
  300. package/src/games/color-switch/ColorSwitchScene.ts +0 -220
  301. package/src/games/colors-sort/ColorsSort.tsx +0 -82
  302. package/src/games/colors-sort/ColorsSortConstants.ts +0 -119
  303. package/src/games/colors-sort/ColorsSortGame.ts +0 -246
  304. package/src/games/colors-sort/ColorsSortScene.ts +0 -315
  305. package/src/games/connect-em-all/ConnectEmAll.tsx +0 -70
  306. package/src/games/connect-em-all/ConnectEmAllConstants.ts +0 -77
  307. package/src/games/connect-em-all/ConnectEmAllGame.ts +0 -401
  308. package/src/games/connect-em-all/ConnectEmAllScene.ts +0 -235
  309. package/src/games/crossy-road/CrossyRoad.tsx +0 -74
  310. package/src/games/crossy-road/CrossyRoadCamera.ts +0 -59
  311. package/src/games/crossy-road/CrossyRoadConstants.ts +0 -132
  312. package/src/games/crossy-road/CrossyRoadGame.ts +0 -293
  313. package/src/games/crossy-road/CrossyRoadMeshes.ts +0 -195
  314. package/src/games/crossy-road/CrossyRoadPerson.ts +0 -198
  315. package/src/games/crossy-road/CrossyRoadRules.ts +0 -99
  316. package/src/games/crossy-road/CrossyRoadScene.ts +0 -355
  317. package/src/games/dino-jump/DinoJump.tsx +0 -77
  318. package/src/games/dino-jump/DinoJumpConstants.ts +0 -80
  319. package/src/games/dino-jump/DinoJumpGame.ts +0 -344
  320. package/src/games/dino-jump/DinoJumpScene.ts +0 -686
  321. package/src/games/dots-and-boxes/DotsAndBoxes.tsx +0 -83
  322. package/src/games/dots-and-boxes/DotsAndBoxesConstants.ts +0 -77
  323. package/src/games/dots-and-boxes/DotsAndBoxesGame.ts +0 -271
  324. package/src/games/dots-and-boxes/DotsAndBoxesScene.ts +0 -249
  325. package/src/games/falling-sticks/FallingSticks.tsx +0 -72
  326. package/src/games/falling-sticks/FallingSticksConstants.ts +0 -62
  327. package/src/games/falling-sticks/FallingSticksGame.ts +0 -220
  328. package/src/games/falling-sticks/FallingSticksRules.ts +0 -145
  329. package/src/games/falling-sticks/FallingSticksScene.ts +0 -245
  330. package/src/games/find-different-number/FindDifferentNumber.tsx +0 -74
  331. package/src/games/find-different-number/FindDifferentNumberConstants.ts +0 -74
  332. package/src/games/find-different-number/FindDifferentNumberGame.ts +0 -174
  333. package/src/games/find-different-number/FindDifferentNumberRules.ts +0 -43
  334. package/src/games/find-different-number/FindDifferentNumberScene.ts +0 -193
  335. package/src/games/flappy-bird/FlappyBird.tsx +0 -73
  336. package/src/games/flappy-bird/FlappyBirdConstants.ts +0 -95
  337. package/src/games/flappy-bird/FlappyBirdGame.ts +0 -375
  338. package/src/games/flappy-bird/FlappyBirdScene.ts +0 -630
  339. package/src/games/fruit-merger/FruitMerger.tsx +0 -73
  340. package/src/games/fruit-merger/FruitMergerConstants.ts +0 -102
  341. package/src/games/fruit-merger/FruitMergerGame.ts +0 -285
  342. package/src/games/fruit-merger/FruitMergerRules.ts +0 -286
  343. package/src/games/fruit-merger/FruitMergerScene.ts +0 -498
  344. package/src/games/fruit-ninja/FruitNinja.tsx +0 -129
  345. package/src/games/fruit-ninja/FruitNinjaConstants.ts +0 -107
  346. package/src/games/fruit-ninja/FruitNinjaGame.ts +0 -391
  347. package/src/games/fruit-ninja/FruitNinjaScene.ts +0 -319
  348. package/src/games/fruit-ninja/FruitNinjaWorld.ts +0 -17
  349. package/src/games/game-2048/Game2048.tsx +0 -84
  350. package/src/games/game-2048/Game2048Constants.ts +0 -68
  351. package/src/games/game-2048/Game2048Game.ts +0 -181
  352. package/src/games/game-2048/Game2048Rules.ts +0 -101
  353. package/src/games/game-2048/Game2048Scene.ts +0 -206
  354. package/src/games/knife-hit/KnifeHit.tsx +0 -78
  355. package/src/games/knife-hit/KnifeHitConstants.ts +0 -89
  356. package/src/games/knife-hit/KnifeHitGame.ts +0 -264
  357. package/src/games/knife-hit/KnifeHitScene.ts +0 -360
  358. package/src/games/ludo-king/LudoKing.tsx +0 -86
  359. package/src/games/ludo-king/LudoKingConstants.ts +0 -212
  360. package/src/games/ludo-king/LudoKingGame.ts +0 -326
  361. package/src/games/ludo-king/LudoKingRules.ts +0 -143
  362. package/src/games/ludo-king/LudoKingScene.ts +0 -397
  363. package/src/games/maze-runner/MazeRunner.tsx +0 -88
  364. package/src/games/maze-runner/MazeRunnerConstants.ts +0 -65
  365. package/src/games/maze-runner/MazeRunnerGame.ts +0 -176
  366. package/src/games/maze-runner/MazeRunnerRules.ts +0 -161
  367. package/src/games/maze-runner/MazeRunnerScene.ts +0 -245
  368. package/src/games/memory-match/MemoryMatch.tsx +0 -77
  369. package/src/games/memory-match/MemoryMatchConstants.ts +0 -105
  370. package/src/games/memory-match/MemoryMatchGame.ts +0 -222
  371. package/src/games/memory-match/MemoryMatchRules.ts +0 -38
  372. package/src/games/memory-match/MemoryMatchScene.ts +0 -268
  373. package/src/games/mine-sweeper/MineSweeper.tsx +0 -77
  374. package/src/games/mine-sweeper/MineSweeperConstants.ts +0 -94
  375. package/src/games/mine-sweeper/MineSweeperGame.ts +0 -234
  376. package/src/games/mine-sweeper/MineSweeperRules.ts +0 -67
  377. package/src/games/mine-sweeper/MineSweeperScene.ts +0 -262
  378. package/src/games/mob-control/MobControl.tsx +0 -73
  379. package/src/games/mob-control/MobControlConstants.ts +0 -106
  380. package/src/games/mob-control/MobControlGame.ts +0 -176
  381. package/src/games/mob-control/MobControlMeshes.ts +0 -85
  382. package/src/games/mob-control/MobControlRenderer.ts +0 -108
  383. package/src/games/mob-control/MobControlRules.ts +0 -522
  384. package/src/games/mob-control/MobControlScene.ts +0 -399
  385. package/src/games/number-search/NumberSearch.tsx +0 -18
  386. package/src/games/number-search/NumberSearchNumbers.ts +0 -623
  387. package/src/games/nuts-and-bolts/NutsAndBolts.tsx +0 -85
  388. package/src/games/nuts-and-bolts/NutsAndBoltsConstants.ts +0 -75
  389. package/src/games/nuts-and-bolts/NutsAndBoltsGame.ts +0 -298
  390. package/src/games/nuts-and-bolts/NutsAndBoltsRules.ts +0 -474
  391. package/src/games/nuts-and-bolts/NutsAndBoltsScene.ts +0 -498
  392. package/src/games/pac-man/PacMan.tsx +0 -86
  393. package/src/games/pac-man/PacManConstants.ts +0 -169
  394. package/src/games/pac-man/PacManGame.ts +0 -406
  395. package/src/games/pac-man/PacManRules.ts +0 -255
  396. package/src/games/pac-man/PacManScene.ts +0 -387
  397. package/src/games/paper-io/PaperIo.tsx +0 -91
  398. package/src/games/paper-io/PaperIoConstants.ts +0 -86
  399. package/src/games/paper-io/PaperIoGame.ts +0 -193
  400. package/src/games/paper-io/PaperIoMeshes.ts +0 -233
  401. package/src/games/paper-io/PaperIoRules.ts +0 -315
  402. package/src/games/paper-io/PaperIoScene.ts +0 -310
  403. package/src/games/penguin-run/PenguinMeshes.ts +0 -269
  404. package/src/games/penguin-run/PenguinModel.ts +0 -712
  405. package/src/games/penguin-run/PenguinRun.tsx +0 -77
  406. package/src/games/penguin-run/PenguinRunConstants.ts +0 -69
  407. package/src/games/penguin-run/PenguinRunGame.ts +0 -406
  408. package/src/games/penguin-run/PenguinRunScene.ts +0 -949
  409. package/src/games/perfect-circle/PerfectCircle.tsx +0 -74
  410. package/src/games/perfect-circle/PerfectCircleConstants.ts +0 -52
  411. package/src/games/perfect-circle/PerfectCircleGame.ts +0 -153
  412. package/src/games/perfect-circle/PerfectCircleRules.ts +0 -111
  413. package/src/games/perfect-circle/PerfectCircleScene.ts +0 -176
  414. package/src/games/pipe-connect/PipeConnect.tsx +0 -69
  415. package/src/games/pipe-connect/PipeConnectConstants.ts +0 -101
  416. package/src/games/pipe-connect/PipeConnectGame.ts +0 -179
  417. package/src/games/pipe-connect/PipeConnectRules.ts +0 -326
  418. package/src/games/pipe-connect/PipeConnectScene.ts +0 -271
  419. package/src/games/play-with-tua/PlayWithTua.tsx +0 -123
  420. package/src/games/play-with-tua/PlayWithTuaConstants.ts +0 -70
  421. package/src/games/play-with-tua/PlayWithTuaGame.ts +0 -167
  422. package/src/games/play-with-tua/PlayWithTuaModel.ts +0 -42
  423. package/src/games/play-with-tua/PlayWithTuaScene.ts +0 -36
  424. package/src/games/popit-fidget/PopitFidget.tsx +0 -72
  425. package/src/games/popit-fidget/PopitFidgetConstants.ts +0 -71
  426. package/src/games/popit-fidget/PopitFidgetGame.ts +0 -148
  427. package/src/games/popit-fidget/PopitFidgetScene.ts +0 -242
  428. package/src/games/reversi/Reversi.tsx +0 -94
  429. package/src/games/reversi/ReversiConstants.ts +0 -67
  430. package/src/games/reversi/ReversiGame.ts +0 -266
  431. package/src/games/reversi/ReversiRules.ts +0 -176
  432. package/src/games/reversi/ReversiScene.ts +0 -240
  433. package/src/games/search-grid/SearchGrid.tsx +0 -92
  434. package/src/games/search-grid/SearchGridConstants.ts +0 -178
  435. package/src/games/search-grid/SearchGridGame.ts +0 -209
  436. package/src/games/search-grid/SearchGridScene.ts +0 -301
  437. package/src/games/shared/BackdropCard.tsx +0 -54
  438. package/src/games/shared/EngineBackdrop.ts +0 -300
  439. package/src/games/shared/EngineBlasts.ts +0 -136
  440. package/src/games/shared/EngineBlocks.ts +0 -91
  441. package/src/games/shared/EngineControlText.ts +0 -17
  442. package/src/games/shared/EngineDice.ts +0 -250
  443. package/src/games/shared/EngineFootprint.ts +0 -35
  444. package/src/games/shared/EngineFruits.ts +0 -1435
  445. package/src/games/shared/EngineGameLoader.tsx +0 -88
  446. package/src/games/shared/EngineGameScreen.tsx +0 -325
  447. package/src/games/shared/EngineGameWidth.ts +0 -3
  448. package/src/games/shared/EngineGameWidth.web.ts +0 -3
  449. package/src/games/shared/EngineGlyphs.ts +0 -178
  450. package/src/games/shared/EngineHud.ts +0 -815
  451. package/src/games/shared/EngineLoading.ts +0 -477
  452. package/src/games/shared/EngineMeadow.ts +0 -725
  453. package/src/games/shared/EngineMeshCache.ts +0 -15
  454. package/src/games/shared/EngineMeshes.ts +0 -10
  455. package/src/games/shared/EngineRacingChase.ts +0 -21
  456. package/src/games/shared/EngineRacingHandling.ts +0 -48
  457. package/src/games/shared/EngineReadyContext.ts +0 -4
  458. package/src/games/shared/EngineTilt.ts +0 -44
  459. package/src/games/shared/EngineTouchSurface.tsx +0 -103
  460. package/src/games/shared/EngineUtils.ts +0 -52
  461. package/src/games/shared/GameActivity.ts +0 -13
  462. package/src/games/shared/GameLoading.tsx +0 -202
  463. package/src/games/shared/GameLoadingTransition.tsx +0 -61
  464. package/src/games/shared/ProceduralCacheVersion.ts +0 -2
  465. package/src/games/shared/useEngineGame.ts +0 -240
  466. package/src/games/shared/useGameResource.ts +0 -21
  467. package/src/games/shared/useLiveState.ts +0 -58
  468. package/src/games/sliding-numbers/SlidingNumbers.tsx +0 -71
  469. package/src/games/sliding-numbers/SlidingNumbersConstants.ts +0 -65
  470. package/src/games/sliding-numbers/SlidingNumbersGame.ts +0 -192
  471. package/src/games/sliding-numbers/SlidingNumbersRules.ts +0 -79
  472. package/src/games/sliding-numbers/SlidingNumbersScene.ts +0 -193
  473. package/src/games/snake-3d/Snake3D.tsx +0 -76
  474. package/src/games/snake-3d/Snake3DConstants.ts +0 -61
  475. package/src/games/snake-3d/Snake3DGame.ts +0 -192
  476. package/src/games/snake-3d/Snake3DMotion.ts +0 -22
  477. package/src/games/snake-3d/Snake3DRules.ts +0 -116
  478. package/src/games/snake-3d/Snake3DScene.ts +0 -322
  479. package/src/games/snakes-and-ladders/SnakesAndLadders.tsx +0 -87
  480. package/src/games/snakes-and-ladders/SnakesAndLaddersConstants.ts +0 -136
  481. package/src/games/snakes-and-ladders/SnakesAndLaddersGame.ts +0 -310
  482. package/src/games/snakes-and-ladders/SnakesAndLaddersScene.ts +0 -515
  483. package/src/games/space-fighter/SpaceFighter.tsx +0 -74
  484. package/src/games/space-fighter/SpaceFighterConstants.ts +0 -86
  485. package/src/games/space-fighter/SpaceFighterGame.ts +0 -292
  486. package/src/games/space-fighter/SpaceFighterScene.ts +0 -550
  487. package/src/games/spider-solitaire/SpiderSolitaire.tsx +0 -80
  488. package/src/games/spider-solitaire/SpiderSolitaireConstants.ts +0 -107
  489. package/src/games/spider-solitaire/SpiderSolitaireGame.ts +0 -387
  490. package/src/games/spider-solitaire/SpiderSolitaireRules.ts +0 -123
  491. package/src/games/spider-solitaire/SpiderSolitaireScene.ts +0 -352
  492. package/src/games/stack-tower/StackTower.tsx +0 -76
  493. package/src/games/stack-tower/StackTowerConstants.ts +0 -74
  494. package/src/games/stack-tower/StackTowerGame.ts +0 -236
  495. package/src/games/stack-tower/StackTowerScene.ts +0 -186
  496. package/src/games/sudoku/Sudoku.tsx +0 -73
  497. package/src/games/sudoku/SudokuConstants.ts +0 -127
  498. package/src/games/sudoku/SudokuGame.ts +0 -250
  499. package/src/games/sudoku/SudokuRules.ts +0 -125
  500. package/src/games/sudoku/SudokuScene.ts +0 -304
  501. package/src/games/tangram/Tangram.tsx +0 -79
  502. package/src/games/tangram/TangramConstants.ts +0 -64
  503. package/src/games/tangram/TangramGame.ts +0 -356
  504. package/src/games/tangram/TangramRules.ts +0 -409
  505. package/src/games/tangram/TangramScene.ts +0 -203
  506. package/src/games/tank-1990/Tank1990.tsx +0 -78
  507. package/src/games/tank-1990/Tank1990Constants.ts +0 -81
  508. package/src/games/tank-1990/Tank1990Game.ts +0 -331
  509. package/src/games/tank-1990/Tank1990Rules.ts +0 -390
  510. package/src/games/tank-1990/Tank1990Scene.ts +0 -434
  511. package/src/games/tic-tac-toe/TicTacToe.tsx +0 -98
  512. package/src/games/tic-tac-toe/TicTacToeConstants.ts +0 -69
  513. package/src/games/tic-tac-toe/TicTacToeGame.ts +0 -200
  514. package/src/games/tic-tac-toe/TicTacToeRules.ts +0 -103
  515. package/src/games/tic-tac-toe/TicTacToeScene.ts +0 -245
  516. package/src/games/tile-home/TileHome.tsx +0 -92
  517. package/src/games/tile-home/TileHomeConstants.ts +0 -139
  518. package/src/games/tile-home/TileHomeGame.ts +0 -435
  519. package/src/games/tile-home/TileHomeScene.ts +0 -154
  520. package/src/games/treasure-hunt/TreasureHunt.tsx +0 -206
  521. package/src/games/treasure-hunt/TreasureHuntConstants.ts +0 -266
  522. package/src/games/treasure-hunt/TreasureHuntControls.ts +0 -280
  523. package/src/games/treasure-hunt/TreasureHuntGame.ts +0 -402
  524. package/src/games/treasure-hunt/TreasureHuntMeshes.ts +0 -422
  525. package/src/games/treasure-hunt/TreasureHuntModel.ts +0 -506
  526. package/src/games/treasure-hunt/TreasureHuntRules.ts +0 -1210
  527. package/src/games/treasure-hunt/TreasureHuntScene.ts +0 -586
  528. package/src/games/whack-a-mole/WhackAMole.tsx +0 -79
  529. package/src/games/whack-a-mole/WhackAMoleConstants.ts +0 -94
  530. package/src/games/whack-a-mole/WhackAMoleGame.ts +0 -233
  531. package/src/games/whack-a-mole/WhackAMoleScene.ts +0 -349
  532. package/src/games/word-search/WordSearch.tsx +0 -18
  533. package/src/games/word-search/WordSearchWords.ts +0 -1642
  534. package/src/helpers/GamePatternData.ts +0 -120
  535. package/src/helpers/GameSettingsModal.tsx +0 -384
  536. package/src/helpers/GameTheme.tsx +0 -37
  537. package/src/helpers/IconPaths.ts +0 -6
  538. package/src/helpers/index.ts +0 -2
  539. package/src/index.tsx +0 -60
  540. package/src/services/GameAssetLoader.ts +0 -111
  541. package/src/services/GameAssets.ts +0 -149
  542. package/src/services/GameLoaders.ts +0 -93
  543. package/src/services/GamesConstants.ts +0 -193
  544. package/src/services/GamesMetadata.ts +0 -711
  545. package/src/services/GamesService.ts +0 -116
  546. package/src/services/HapticsService.ts +0 -48
  547. package/src/services/ScoringService.ts +0 -19
  548. package/src/services/SfxSources.ts +0 -81
  549. package/src/services/SoundsService.ts +0 -582
  550. package/src/services/ThemeService.ts +0 -281
  551. package/src/services/UtilsService.ts +0 -134
  552. package/src/services/index.ts +0 -6
@@ -1,1210 +0,0 @@
1
- import { type Quat } from '@nayan-ui/engine';
2
- // Treasure Hunt: Seeded terrain, collision and game rules; independent of the native renderer.
3
- import {
4
- ATTACK_COOLDOWN,
5
- ATTACK_HIT_TIME,
6
- ATTACK_RANGE,
7
- ENEMY_COUNT,
8
- GEM_GOAL,
9
- HUMAN_HEIGHT,
10
- MAX_HEALTH,
11
- MINIMAP_SIZE,
12
- MOVEMENT_START,
13
- MOVEMENT_STOP,
14
- PLAYER_RADIUS,
15
- PLAYER_SPEED,
16
- type Point,
17
- POINTS_GEM,
18
- POINTS_HEALTH_BONUS,
19
- POINTS_ROBOT_DEFEAT,
20
- POINTS_ROBOT_HIT,
21
- TERRAIN_PROFILES,
22
- WORLD_EDGE
23
- } from './TreasureHuntConstants';
24
-
25
- // Scenery collision shapes.
26
-
27
- export const SOLID_CELL = 8;
28
-
29
- const INDEX_MARGIN = 1.5;
30
-
31
- export const ROCK_RINGS = 12;
32
-
33
- export const ROCK_SIDES = 18;
34
-
35
- export const CAVE_INNER_WIDTH = 3.5;
36
-
37
- export const CAVE_INNER_HEIGHT = 4.8;
38
-
39
- export const BRIDGE_RAIL_INSET = 0.15;
40
-
41
- export const BRIDGE_RAIL_DEPTH = 0.09;
42
-
43
- export const BRIDGE_POST_WIDTH = 0.3;
44
-
45
- export const BRIDGE_POST_HEIGHT = 1.12;
46
-
47
- export type SolidTag = 'tree' | 'rock' | 'bridge-rail' | 'bridge-post';
48
-
49
- interface SolidBounds extends Point {
50
- tag: SolidTag;
51
- bottom: number;
52
- top: number;
53
- minX: number;
54
- maxX: number;
55
- minZ: number;
56
- maxZ: number;
57
- }
58
-
59
- export type Solid = SolidBounds & ({ shape: 'circle'; radius: number } | { shape: 'polygon'; points: Point[] });
60
-
61
- export type SolidCells = Map<string, Solid[]>;
62
-
63
- /** Shared surface samples keep rendered boulders and their collision hulls in agreement. */
64
- export function rockSurface(style: number, a: number, b: number) {
65
- const rough = 1 + Math.sin(a * 3 + b * 5 + style) * 0.12 + Math.cos(a * 7 - b * 3) * 0.05;
66
- const normal: [number, number, number] = [Math.sin(b) * Math.cos(a), Math.cos(b), Math.sin(b) * Math.sin(a)];
67
- const position: [number, number, number] = [normal[0] * rough, Math.max(-0.2, normal[1] * rough * 0.8 + 0.45), normal[2] * rough * 0.9];
68
- return { position, normal };
69
- }
70
-
71
- const rockHulls = new Map<number, { points: Point[]; bottom: number; top: number }>();
72
-
73
- function rockHull(style: number) {
74
- const cached = rockHulls.get(style);
75
- if (cached) return cached;
76
- const points: Point[] = [];
77
- let bottom = Infinity,
78
- top = -Infinity;
79
- for (let ring = 0; ring <= ROCK_RINGS; ring++)
80
- for (let side = 0; side < ROCK_SIDES; side++) {
81
- const {
82
- position: [x, y, z]
83
- } = rockSurface(style, (side / ROCK_SIDES) * Math.PI * 2, (ring / ROCK_RINGS) * Math.PI);
84
- points.push({ x, z });
85
- bottom = Math.min(bottom, y);
86
- top = Math.max(top, y);
87
- }
88
- points.sort((a, b) => a.x - b.x || a.z - b.z);
89
- const cross = (a: Point, b: Point, c: Point) => (b.x - a.x) * (c.z - a.z) - (b.z - a.z) * (c.x - a.x);
90
- const half = (input: Point[]) => {
91
- const result: Point[] = [];
92
- for (const p of input) {
93
- while (result.length > 1 && cross(result[result.length - 2]!, result[result.length - 1]!, p) <= 0) result.pop();
94
- result.push(p);
95
- }
96
- result.pop();
97
- return result;
98
- };
99
- const hull = { points: [...half(points), ...half([...points].reverse())], bottom, top };
100
- rockHulls.set(style, hull);
101
- return hull;
102
- }
103
-
104
- export function circleSolid(tag: SolidTag, x: number, z: number, radius: number, bottom: number, top: number): Solid {
105
- return { shape: 'circle', tag, x, z, radius, bottom, top, minX: x - radius, maxX: x + radius, minZ: z - radius, maxZ: z + radius };
106
- }
107
-
108
- function polygonSolid(tag: SolidTag, x: number, z: number, points: Point[], bottom: number, top: number): Solid {
109
- return {
110
- shape: 'polygon',
111
- tag,
112
- x,
113
- z,
114
- points,
115
- bottom,
116
- top,
117
- minX: Math.min(...points.map((p) => p.x)),
118
- maxX: Math.max(...points.map((p) => p.x)),
119
- minZ: Math.min(...points.map((p) => p.z)),
120
- maxZ: Math.max(...points.map((p) => p.z))
121
- };
122
- }
123
-
124
- export function boxSolid(tag: SolidTag, x: number, z: number, halfX: number, halfZ: number, yaw: number, bottom: number, top: number) {
125
- const cos = Math.cos(yaw),
126
- sin = Math.sin(yaw);
127
- const points = [
128
- [-halfX, -halfZ],
129
- [halfX, -halfZ],
130
- [halfX, halfZ],
131
- [-halfX, halfZ]
132
- ].map(([u, v]) => ({ x: x + cos * u! + sin * v!, z: z - sin * u! + cos * v! }));
133
- return polygonSolid(tag, x, z, points, bottom, top);
134
- }
135
-
136
- export function rockSolid(x: number, y: number, z: number, scale: readonly [number, number, number], yaw: number, style: number) {
137
- const hull = rockHull(style),
138
- cos = Math.cos(yaw),
139
- sin = Math.sin(yaw);
140
- const points = hull.points.map((p) => ({ x: x + cos * p.x * scale[0] + sin * p.z * scale[2], z: z - sin * p.x * scale[0] + cos * p.z * scale[2] }));
141
- return polygonSolid('rock', x, z, points, y + hull.bottom * scale[1], y + hull.top * scale[1]);
142
- }
143
-
144
- /** Signed distance to the full visible footprint, including rounded corners around an actor. */
145
- export function solidDistance(solid: Solid, x: number, z: number) {
146
- if (solid.shape === 'circle') return Math.hypot(x - solid.x, z - solid.z) - solid.radius;
147
- let distance2 = Infinity,
148
- inside = true;
149
- for (let i = 0; i < solid.points.length; i++) {
150
- const a = solid.points[i]!,
151
- b = solid.points[(i + 1) % solid.points.length]!;
152
- const dx = b.x - a.x,
153
- dz = b.z - a.z,
154
- length2 = dx * dx + dz * dz;
155
- if (dx * (z - a.z) - dz * (x - a.x) < -1e-10) inside = false;
156
- const t = Math.max(0, Math.min(1, ((x - a.x) * dx + (z - a.z) * dz) / length2));
157
- distance2 = Math.min(distance2, (x - a.x - dx * t) ** 2 + (z - a.z - dz * t) ** 2);
158
- }
159
- return Math.sqrt(distance2) * (inside ? -1 : 1);
160
- }
161
-
162
- export function indexSolid(cells: SolidCells, solid: Solid) {
163
- for (let ix = Math.floor((solid.minX - INDEX_MARGIN) / SOLID_CELL); ix <= Math.floor((solid.maxX + INDEX_MARGIN) / SOLID_CELL); ix++)
164
- for (let iz = Math.floor((solid.minZ - INDEX_MARGIN) / SOLID_CELL); iz <= Math.floor((solid.maxZ + INDEX_MARGIN) / SOLID_CELL); iz++) {
165
- const key = `${ix},${iz}`,
166
- bucket = cells.get(key) ?? [];
167
- bucket.push(solid);
168
- cells.set(key, bucket);
169
- }
170
- }
171
-
172
- export function solidClearance(cells: SolidCells, x: number, z: number, radius: number, bottom: number, top: number) {
173
- let clearance = Infinity;
174
- for (const solid of cells.get(`${Math.floor(x / SOLID_CELL)},${Math.floor(z / SOLID_CELL)}`) ?? []) {
175
- if (solid.top <= bottom + 0.001 || solid.bottom >= top) continue;
176
- clearance = Math.min(clearance, solidDistance(solid, x, z) - radius);
177
- }
178
- return clearance;
179
- }
180
-
181
- export interface BridgeBarrier extends Point {
182
- kind: 'rail' | 'post';
183
- halfX: number;
184
- halfZ: number;
185
- }
186
-
187
- /** The renderer and collision system share every railing and post position. */
188
- export function bridgeBarriers(bridge: { halfLength: number; halfWidth: number }): BridgeBarrier[] {
189
- const result: BridgeBarrier[] = [];
190
- for (const side of [-1, 1]) {
191
- const z = side * (bridge.halfWidth - BRIDGE_RAIL_INSET);
192
- result.push({ kind: 'rail', x: 0, z, halfX: bridge.halfLength, halfZ: BRIDGE_RAIL_DEPTH / 2 });
193
- for (let x = -bridge.halfLength + 0.2; x <= bridge.halfLength; x += 2)
194
- result.push({ kind: 'post', x, z, halfX: BRIDGE_POST_WIDTH / 2, halfZ: BRIDGE_POST_WIDTH / 2 });
195
- }
196
- return result;
197
- }
198
- // Seeded terrain and navigation.
199
-
200
- export interface Hill extends Point {
201
- height: number;
202
- width: number;
203
- depth: number;
204
- yaw: number;
205
- }
206
-
207
- export interface Cave extends Point {
208
- y: number;
209
- length: number;
210
- }
211
-
212
- export interface Bridge extends Point {
213
- halfLength: number;
214
- halfWidth: number;
215
- y: number;
216
- }
217
-
218
- export type TerrainSurface = 'grass' | 'hill' | 'river' | 'shore' | 'cave' | 'bridge';
219
-
220
- export const TERRAIN_STEP = 1.6;
221
-
222
- // A coarse outer apron supports distant scenery while the playable ground keeps its fine grid.
223
- export const TERRAIN_EDGE = WORLD_EDGE + 48;
224
-
225
- const APRON_CELLS = 8;
226
-
227
- const PLAYABLE_CELLS = Math.round((WORLD_EDGE * 2) / TERRAIN_STEP);
228
-
229
- export const TERRAIN_GRID = Float32Array.from([
230
- ...Array.from({ length: APRON_CELLS }, (_, i) => -TERRAIN_EDGE + i * 6),
231
- ...Array.from({ length: PLAYABLE_CELLS + 1 }, (_, i) => -WORLD_EDGE + (i * WORLD_EDGE * 2) / PLAYABLE_CELLS),
232
- ...Array.from({ length: APRON_CELLS }, (_, i) => WORLD_EDGE + (i + 1) * 6)
233
- ]);
234
-
235
- const terrainSamples = new WeakMap<Landscape, Float32Array>();
236
-
237
- export interface NatureProp extends Point {
238
- kind: 'pine' | 'birch' | 'rock';
239
- scale: number;
240
- yaw: number;
241
- style: number;
242
- }
243
-
244
- export interface NatureDecoration extends Point {
245
- kind: 'rock' | 'pine';
246
- area: 'horizon' | 'cave-roof' | 'cave-entrance';
247
- y: number;
248
- scale: [number, number, number];
249
- yaw: number;
250
- style: number;
251
- }
252
-
253
- export interface Landscape {
254
- profile: number;
255
- phase: number;
256
- hills: Hill[];
257
- caves: Cave[];
258
- bridges: Bridge[];
259
- }
260
-
261
- export interface NatureMap {
262
- seed: number;
263
- edge: number;
264
- rotation: number;
265
- landscape: Landscape;
266
- spawn: Point;
267
- props: NatureProp[];
268
- decorations: NatureDecoration[];
269
- obstacleCells: SolidCells;
270
- reachable: Point[];
271
- gems: Point[];
272
- enemies: Point[];
273
- }
274
-
275
- let cursor = (Math.random() * 0xffffffff) >>> 0;
276
-
277
- export function random(seed: number) {
278
- let value = seed >>> 0;
279
- return () => {
280
- value += 0x6d2b79f5;
281
- let t = Math.imul(value ^ (value >>> 15), 1 | value);
282
- t ^= t + Math.imul(t ^ (t >>> 7), 61 | t);
283
- return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
284
- };
285
- }
286
-
287
- const profiles = new Map<number, Landscape>();
288
- const hillAxes = new WeakMap<Landscape, { hill: Hill; cos: number; sin: number }[]>();
289
- const rotations = new WeakMap<object, { angle: number; cos: number; sin: number }>();
290
- // The centre plus the same eight footprint samples used by collision and navigation.
291
- const FOOTPRINT = Array.from({ length: 9 }, (_, i) => {
292
- const angle = ((i - 1) / 8) * Math.PI * 2;
293
- return [i ? Math.cos(angle) : 0, i ? Math.sin(angle) : 0] as const;
294
- });
295
-
296
- const smooth = (n: number) => {
297
- const t = Math.max(0, Math.min(1, n));
298
- return t * t * (3 - 2 * t);
299
- };
300
-
301
- const gap = (a: Point, b: Point) => Math.hypot(a.x - b.x, a.z - b.z);
302
-
303
- /** Bounded geometry library: native mesh IDs live for the app's lifetime. Seeds also rotate the
304
- * landscape and independently scatter vegetation, formations, enemies and treasure each run. */
305
- export function landscapeFor(profile: number): Landscape {
306
- const cached = profiles.get(profile);
307
- if (cached) return cached;
308
- const rng = random(profile * 7919 + 314159);
309
- const landscape: Landscape = {
310
- profile,
311
- phase: rng() * Math.PI * 2,
312
- hills: Array.from({ length: 9 }, (_, i) => ({
313
- x: (i % 2 ? -1 : 1) * (34 + rng() * 65),
314
- z: -95 + rng() * 190,
315
- height: 2 + rng() * 4,
316
- width: 16 + rng() * 22,
317
- depth: 16 + rng() * 22,
318
- yaw: rng() * Math.PI * 2
319
- })),
320
- caves: [],
321
- bridges: []
322
- };
323
- for (const [x, z] of [
324
- [-36 - rng() * 12, 15 + rng() * 13],
325
- [47 + rng() * 12, -45 + rng() * 12]
326
- ]) {
327
- const cave = { x: x!, z: z!, y: waterLevel(landscape, z!) + 1 + meadowRolling(landscape, x!, z!), length: 20 };
328
- landscape.caves.push(cave);
329
- }
330
- for (const z of [-46, -2, 58])
331
- landscape.bridges.push({
332
- x: riverX(landscape, z),
333
- z,
334
- halfLength: riverWidth(landscape, z) + 4.5,
335
- halfWidth: 2.8,
336
- y: waterLevel(landscape, z) + 1.08
337
- });
338
- profiles.set(profile, landscape);
339
- return landscape;
340
- }
341
-
342
- export function riverX(landscape: Landscape, z: number) {
343
- return 10 + Math.sin(z * 0.035 + landscape.phase) * 11 + Math.sin(z * 0.073) * 2;
344
- }
345
-
346
- export function riverWidth(landscape: Landscape, z: number) {
347
- return 4.8 + Math.sin(z * 0.05 + landscape.phase) * 0.6;
348
- }
349
-
350
- export function waterLevel(_landscape: Landscape, z: number) {
351
- return 0.018 * z;
352
- }
353
-
354
- /** Compact rocky hills leave broad, gently rolling grassland between their distinct foothills. */
355
- export function hillRise(landscape: Landscape, x: number, z: number) {
356
- let axes = hillAxes.get(landscape);
357
- if (!axes) {
358
- axes = landscape.hills.map((hill) => ({ hill, cos: Math.cos(hill.yaw), sin: Math.sin(hill.yaw) }));
359
- hillAxes.set(landscape, axes);
360
- }
361
- let height = 0;
362
- for (const { hill, cos, sin } of axes) {
363
- const radius = hill.width * 0.8;
364
- const dx = x - hill.x,
365
- dz = z - hill.z;
366
- const u = (dx * cos + dz * sin) / radius,
367
- v = (-dx * sin + dz * cos) / (hill.depth * 0.8);
368
- const influence = Math.max(0, 1 - u * u - v * v);
369
- height += hill.height * influence ** 2;
370
- }
371
- // Most of the map is open meadow. Fading a zero hill contribution cannot change its height.
372
- const edge = 6 * smooth((Math.hypot(x, z) - 111) / 17);
373
- if (height === 0) return edge;
374
- const bankDistance = Math.abs(x - riverX(landscape, z)) - riverWidth(landscape, z);
375
- for (const bridge of landscape.bridges) {
376
- const end = Math.max(0, Math.abs(x - bridge.x) - bridge.halfLength - 3);
377
- const distance = Math.hypot(end, z - bridge.z);
378
- height *= smooth((distance - bridge.halfWidth - 2) / 6);
379
- }
380
- for (const cave of landscape.caves) height *= smooth((caveDistance(cave, x, z) - 8.5) / 5);
381
- return height * smooth((bankDistance - 3) / 10) + edge;
382
- }
383
-
384
- function meadowRolling(landscape: Landscape, x: number, z: number) {
385
- return 0.08 * Math.sin(x * 0.12 + landscape.phase) * Math.cos(z * 0.11);
386
- }
387
-
388
- function baseHeight(landscape: Landscape, x: number, z: number) {
389
- const distance = Math.abs(x - riverX(landscape, z)),
390
- width = riverWidth(landscape, z);
391
- const level = waterLevel(landscape, z);
392
- if (distance <= width) return level - 1.8 * (1 - (distance / width) ** 4);
393
- const bank = smooth((distance - width) / 1.4);
394
- const rolling = meadowRolling(landscape, x, z);
395
- return level + bank * (1 + rolling + hillRise(landscape, x, z));
396
- }
397
-
398
- export function terrainHeight(landscape: Landscape, x: number, z: number) {
399
- let height = baseHeight(landscape, x, z);
400
- for (const cave of landscape.caves) {
401
- const weight = 1 - smooth((caveDistance(cave, x, z) - 5.8) / 4);
402
- height += (cave.y - height) * weight;
403
- }
404
- return height;
405
- }
406
-
407
- /** Sample the same triangle planes the renderer draws, including clipped material boundaries. */
408
- export function terrainMeshHeight(landscape: Landscape, x: number, z: number): number {
409
- let heights = terrainSamples.get(landscape);
410
- const width = TERRAIN_GRID.length;
411
- if (!heights) {
412
- heights = Float32Array.from({ length: width * width }, (_, i) =>
413
- terrainHeight(landscape, TERRAIN_GRID[i % width]!, TERRAIN_GRID[Math.floor(i / width)]!)
414
- );
415
- terrainSamples.set(landscape, heights);
416
- }
417
- const cell = (value: number) =>
418
- Math.max(
419
- 0,
420
- Math.min(
421
- width - 2,
422
- value < -WORLD_EDGE
423
- ? Math.floor((value + TERRAIN_EDGE) / 6)
424
- : value < WORLD_EDGE
425
- ? APRON_CELLS + Math.floor((value + WORLD_EDGE) / TERRAIN_STEP)
426
- : APRON_CELLS + PLAYABLE_CELLS + Math.floor((value - WORLD_EDGE) / 6)
427
- )
428
- );
429
- const col = cell(x),
430
- row = cell(z),
431
- at = row * width + col;
432
- const u = Math.max(0, Math.min(1, (x - TERRAIN_GRID[col]!) / (TERRAIN_GRID[col + 1]! - TERRAIN_GRID[col]!))),
433
- v = Math.max(0, Math.min(1, (z - TERRAIN_GRID[row]!) / (TERRAIN_GRID[row + 1]! - TERRAIN_GRID[row]!)));
434
- return u + v <= 1
435
- ? heights[at]! + u * (heights[at + 1]! - heights[at]!) + v * (heights[at + width]! - heights[at]!)
436
- : heights[at + width + 1]! +
437
- (1 - u) * (heights[at + width]! - heights[at + width + 1]!) +
438
- (1 - v) * (heights[at + 1]! - heights[at + width + 1]!);
439
- }
440
-
441
- /** Rounded cave surrounds avoid rectangular terrain cutouts at the entrances. */
442
- export function caveDistance(cave: Cave, x: number, z: number) {
443
- return Math.hypot(x - cave.x, Math.max(0, Math.abs(z - cave.z) - cave.length / 2 + 3.5));
444
- }
445
-
446
- export function caveClearance(landscape: Landscape, x: number, z: number) {
447
- return Math.min(...landscape.caves.map((cave) => caveDistance(cave, x, z) - 7), Infinity);
448
- }
449
-
450
- /** Continuous contours are shared by visible terrain, movement and contact normals. */
451
- export function terrainSurface(landscape: Landscape, x: number, z: number): Exclude<TerrainSurface, 'bridge'> {
452
- const distance = Math.abs(x - riverX(landscape, z)),
453
- width = riverWidth(landscape, z);
454
- if (distance <= width) return 'river';
455
- if (distance < width + 1.4) return 'shore';
456
- if (caveClearance(landscape, x, z) < 0) return 'cave';
457
- return hillRise(landscape, x, z) > 0.35 ? 'hill' : 'grass';
458
- }
459
-
460
- export function toWorld(map: Pick<NatureMap, 'rotation'>, x: number, z: number): Point {
461
- const { sin, cos } = rotationAxes(map);
462
- return { x: cos * x + sin * z, z: -sin * x + cos * z };
463
- }
464
-
465
- export function toLocal(map: Pick<NatureMap, 'rotation'>, x: number, z: number): Point {
466
- const { sin, cos } = rotationAxes(map);
467
- return { x: cos * x - sin * z, z: sin * x + cos * z };
468
- }
469
-
470
- function rotationAxes(map: Pick<NatureMap, 'rotation'>) {
471
- let axes = rotations.get(map);
472
- if (!axes || axes.angle !== map.rotation) {
473
- axes = { angle: map.rotation, sin: Math.sin(map.rotation), cos: Math.cos(map.rotation) };
474
- rotations.set(map, axes);
475
- }
476
- return axes;
477
- }
478
-
479
- export function groundHeight(map: NatureMap, x: number, z: number) {
480
- const p = toLocal(map, x, z);
481
- return bridgeAtLocal(map.landscape, p.x, p.z)?.y ?? terrainMeshHeight(map.landscape, p.x, p.z);
482
- }
483
-
484
- /** Surface tilt in a parent's yaw basis, for contact shadows that lie against the ground. */
485
- export function groundTilt(map: NatureMap, x: number, z: number, yaw = 0): Quat {
486
- const c = Math.cos(yaw) * 0.12,
487
- s = Math.sin(yaw) * 0.12;
488
- const dx = (groundHeight(map, x + c, z - s) - groundHeight(map, x - c, z + s)) / 0.24,
489
- dz = (groundHeight(map, x + s, z + c) - groundHeight(map, x - s, z - c)) / 0.24;
490
- const length = Math.hypot(dx, 1, dz);
491
- const q = [-dz / length, 0, dx / length, 1 + 1 / length];
492
- const norm = Math.hypot(...q);
493
- return [q[0]! / norm, 0, q[2]! / norm, q[3]! / norm];
494
- }
495
-
496
- function bridgeAtLocal(landscape: Landscape, x: number, z: number) {
497
- return landscape.bridges.find((bridge) => Math.abs(x - bridge.x) <= bridge.halfLength && Math.abs(z - bridge.z) <= bridge.halfWidth);
498
- }
499
-
500
- export function bridgeAt(map: NatureMap, x: number, z: number) {
501
- const p = toLocal(map, x, z);
502
- return bridgeAtLocal(map.landscape, p.x, p.z);
503
- }
504
-
505
- export function surfaceAt(map: NatureMap, x: number, z: number): TerrainSurface {
506
- const p = toLocal(map, x, z);
507
- return bridgeAtLocal(map.landscape, p.x, p.z) ? 'bridge' : terrainSurface(map.landscape, p.x, p.z);
508
- }
509
-
510
- interface Overview {
511
- row: number;
512
- cells: (TerrainSurface | null)[];
513
- }
514
- const overviews = new WeakMap<NatureMap, Map<number, Overview>>();
515
- function overviewFor(map: NatureMap, size: number): Overview {
516
- let sizes = overviews.get(map);
517
- if (!sizes) {
518
- sizes = new Map();
519
- overviews.set(map, sizes);
520
- }
521
- let overview = sizes.get(size);
522
- if (!overview) {
523
- overview = { row: 0, cells: Array(size * size).fill(null) };
524
- sizes.set(size, overview);
525
- }
526
- return overview;
527
- }
528
- function sampleOverviewRows(map: NatureMap, size: number, overview: Overview, count: number) {
529
- const end = Math.min(size, overview.row + count);
530
- for (; overview.row < end; overview.row++) {
531
- const z = (((overview.row + 0.5) / size) * 2 - 1) * WORLD_EDGE;
532
- for (let col = 0; col < size; col++) {
533
- const x = (((col + 0.5) / size) * 2 - 1) * WORLD_EDGE;
534
- overview.cells[overview.row * size + col] = Math.hypot(x, z) > map.edge - 4 ? null : surfaceAt(map, x, z);
535
- }
536
- }
537
- }
538
-
539
- /** Immutable terrain samples; the screen owns colours, paths and live objective markers. */
540
- export function mapOverview(map: NatureMap, size: number): readonly (TerrainSurface | null)[] {
541
- const overview = overviewFor(map, size);
542
- sampleOverviewRows(map, size, overview, size);
543
- return overview.cells;
544
- }
545
-
546
- export function waterDepth(map: NatureMap, x: number, z: number) {
547
- const p = toLocal(map, x, z);
548
- return Math.abs(p.x - riverX(map.landscape, p.z)) <= riverWidth(map.landscape, p.z)
549
- ? Math.max(0, waterLevel(map.landscape, p.z) - terrainHeight(map.landscape, p.x, p.z))
550
- : 0;
551
- }
552
-
553
- export function caveAt(map: NatureMap, x: number, z: number) {
554
- const p = toLocal(map, x, z);
555
- return map.landscape.caves.find((c) => Math.abs(p.x - c.x) < 5.8 && Math.abs(p.z - c.z) < c.length / 2 + 0.2);
556
- }
557
-
558
- /** Passage width accounts for the explorer's height beneath the actual curved arch. */
559
- export function cavePassageClearance(landscape: Landscape, x: number, z: number) {
560
- const halfWidth = CAVE_INNER_WIDTH * 0.975 * Math.sqrt(1 - ((HUMAN_HEIGHT + 0.12) / (CAVE_INNER_HEIGHT * 0.975)) ** 2);
561
- let clearance = -Infinity;
562
- for (const cave of landscape.caves)
563
- clearance = Math.max(clearance, Math.min(halfWidth - Math.abs(x - cave.x), cave.length / 2 + 5 - Math.abs(z - cave.z)));
564
- return clearance;
565
- }
566
-
567
- function terrainClearance(land: Landscape, x: number, z: number) {
568
- const grass = Math.min(Math.abs(x - riverX(land, z)) - riverWidth(land, z) - 1.4, 0.35 - hillRise(land, x, z), caveClearance(land, x, z));
569
- let clearance = Math.max(grass, cavePassageClearance(land, x, z));
570
- for (const bridge of land.bridges)
571
- clearance = Math.max(clearance, Math.min(bridge.halfLength - Math.abs(x - bridge.x), bridge.halfWidth - Math.abs(z - bridge.z)));
572
- return clearance;
573
- }
574
-
575
- /** Terrain and visible solids supply the same contact normals used by swept movement. */
576
- export function navigationClearance(map: NatureMap, x: number, z: number, radius = PLAYER_RADIUS) {
577
- let clearance = map.edge - 4 - radius - Math.hypot(x, z);
578
- for (const [dx, dz] of FOOTPRINT) {
579
- const p = toLocal(map, x + dx * radius, z + dz * radius);
580
- clearance = Math.min(clearance, terrainClearance(map.landscape, p.x, p.z));
581
- }
582
- const floor = groundHeight(map, x, z);
583
- return Math.min(clearance, solidClearance(map.obstacleCells, x, z, radius, floor + 0.02, floor + HUMAN_HEIGHT));
584
- }
585
-
586
- /** Grass, bridge decks and cave passages are walkable; complete body footprints stay outside solids. */
587
- export function isWalkable(map: NatureMap, x: number, z: number, radius = PLAYER_RADIUS) {
588
- if (!Number.isFinite(x + z) || Math.hypot(x, z) + radius > map.edge - 4) return false;
589
- const y = groundHeight(map, x, z);
590
- for (const [dx, dz] of FOOTPRINT) {
591
- const sx = x + dx * radius,
592
- sz = z + dz * radius;
593
- const p = toLocal(map, sx, sz);
594
- if (terrainClearance(map.landscape, p.x, p.z) < -1e-8) return false;
595
- if (Math.abs(groundHeight(map, sx, sz) - y) > Math.max(0.25, radius * 0.5)) return false;
596
- }
597
- return solidClearance(map.obstacleCells, x, z, radius, y + 0.02, y + HUMAN_HEIGHT) >= -1e-8;
598
- }
599
-
600
- function indexProp(map: NatureMap, prop: NatureProp) {
601
- const y = groundHeight(map, prop.x, prop.z) - 0.07;
602
- indexSolid(
603
- map.obstacleCells,
604
- prop.kind === 'rock'
605
- ? rockSolid(prop.x, y, prop.z, [prop.scale, prop.scale, prop.scale], prop.yaw, prop.style)
606
- : circleSolid('tree', prop.x, prop.z, 0.32 * prop.scale, y - 0.45 * prop.scale, y + (prop.kind === 'pine' ? 9.4 : 8.2) * prop.scale)
607
- );
608
- }
609
-
610
- /** All decorative rocks and trees are generated before navigation, then rendered from this same data. */
611
- function generateScenery(map: NatureMap) {
612
- const rng = random(map.seed ^ 0x679be3);
613
- const add = (decoration: NatureDecoration) => {
614
- map.decorations.push(decoration);
615
- indexSolid(
616
- map.obstacleCells,
617
- decoration.kind === 'rock'
618
- ? rockSolid(decoration.x, decoration.y, decoration.z, decoration.scale, decoration.yaw, decoration.style)
619
- : circleSolid(
620
- 'tree',
621
- decoration.x,
622
- decoration.z,
623
- 0.32 * decoration.scale[0],
624
- decoration.y - 0.45 * decoration.scale[1],
625
- decoration.y + 9.4 * decoration.scale[1]
626
- )
627
- );
628
- };
629
- for (const bridge of map.landscape.bridges)
630
- for (const part of bridgeBarriers(bridge)) {
631
- const p = toWorld(map, bridge.x + part.x, bridge.z + part.z);
632
- indexSolid(
633
- map.obstacleCells,
634
- boxSolid(
635
- part.kind === 'rail' ? 'bridge-rail' : 'bridge-post',
636
- p.x,
637
- p.z,
638
- part.halfX,
639
- part.halfZ,
640
- map.rotation,
641
- bridge.y + (part.kind === 'rail' ? 0.445 : 0),
642
- bridge.y + (part.kind === 'rail' ? 1.025 : BRIDGE_POST_HEIGHT)
643
- )
644
- );
645
- }
646
- for (let i = 0; i < 90; i++) {
647
- const a = (i / 90) * Math.PI * 2,
648
- r = map.edge + 7 + rng() * 18,
649
- x = Math.cos(a) * r,
650
- z = Math.sin(a) * r;
651
- add({
652
- kind: 'rock',
653
- area: 'horizon',
654
- x,
655
- z,
656
- y: groundHeight(map, x, z) - 2,
657
- scale: [5 + rng() * 5, 3 + rng() * 4, 5 + rng() * 5],
658
- yaw: a,
659
- style: i % 4
660
- });
661
- add({
662
- kind: 'pine',
663
- area: 'horizon',
664
- x: x * 0.92,
665
- z: z * 0.92,
666
- y: groundHeight(map, x * 0.92, z * 0.92),
667
- scale: [1.8, 1.8, 1.8],
668
- yaw: a,
669
- style: i % 4
670
- });
671
- }
672
- for (const cave of map.landscape.caves) {
673
- for (let i = 0; i < 14; i++) {
674
- const q = toWorld(map, cave.x + (rng() - 0.5) * 5, cave.z - 8 + (i % 7) * 2.6);
675
- const y = cave.y + 5.5 + rng() * 0.4,
676
- scale: [number, number, number] = [2 + rng(), 1 + rng(), 1.7 + rng()];
677
- add({ kind: 'rock', area: 'cave-roof', ...q, y, scale, yaw: rng() * Math.PI * 2, style: i % 4 });
678
- }
679
- for (const side of [-1, 1])
680
- for (let i = 0; i < 7; i++) {
681
- const q = toWorld(map, cave.x + side * (5.4 + rng() * 1.6), cave.z - 9 + i * 3);
682
- add({ kind: 'rock', area: 'cave-entrance', ...q, y: cave.y - 0.2, scale: [1.5, 1.8 + rng(), 2], yaw: i, style: i % 4 });
683
- }
684
- }
685
- }
686
-
687
- /** A conservative connected navigation grid prevents unreachable treasure behind cliffs or rocks. */
688
- function* reachableFromSpawn(map: NatureMap): Generator<void, Point[]> {
689
- const size = 3,
690
- visited = new Set<string>(['0,0']),
691
- queue: [number, number][] = [[0, 0]],
692
- points: Point[] = [];
693
- // Navigation edges share a half-unit lattice. Cache complete footprint/solid checks only for
694
- // this flood fill; live movement still samples the current map at its exact position.
695
- const minX = Math.floor((-map.edge - map.spawn.x) * 2),
696
- minZ = Math.floor((-map.edge - map.spawn.z) * 2),
697
- width = Math.ceil(map.edge * 4) + 3,
698
- walkable = new Uint8Array(width * width);
699
- const clearAt = (x: number, z: number) => {
700
- const col = x - minX,
701
- row = z - minZ;
702
- if (col < 0 || row < 0 || col >= width || row >= width) return false;
703
- const index = row * width + col;
704
- let value = walkable[index]!;
705
- if (!value) {
706
- value = isWalkable(map, map.spawn.x + x * 0.5, map.spawn.z + z * 0.5, 0.75) ? 1 : 2;
707
- walkable[index] = value;
708
- }
709
- return value === 1;
710
- };
711
- for (let index = 0; index < queue.length; index++) {
712
- if (index && index % 64 === 0) yield;
713
- const [cx, cz] = queue[index]!;
714
- const current = { x: map.spawn.x + cx * size, z: map.spawn.z + cz * size };
715
- points.push(current);
716
- for (const [dx, dz] of [
717
- [1, 0],
718
- [-1, 0],
719
- [0, 1],
720
- [0, -1],
721
- [1, 1],
722
- [-1, 1],
723
- [1, -1],
724
- [-1, -1]
725
- ]) {
726
- const nx = cx + dx!,
727
- nz = cz + dz!,
728
- key = `${nx},${nz}`;
729
- if (visited.has(key)) continue;
730
- if (!clearAt(nx * 6, nz * 6)) {
731
- visited.add(key);
732
- continue;
733
- }
734
- let clear = true;
735
- for (let step = 1; step < 6; step++)
736
- if (!clearAt(cx * 6 + dx! * step, cz * 6 + dz! * step)) {
737
- clear = false;
738
- break;
739
- }
740
- if (clear) {
741
- visited.add(key);
742
- queue.push([nx, nz]);
743
- }
744
- }
745
- }
746
- return points;
747
- }
748
-
749
- function* generateNatureSteps(seed: number): Generator<void, NatureMap> {
750
- const rng = random(seed),
751
- landscape = landscapeFor((seed >>> 0) % TERRAIN_PROFILES);
752
- const map: NatureMap = {
753
- seed,
754
- edge: WORLD_EDGE,
755
- rotation: rng() * Math.PI * 2,
756
- landscape,
757
- spawn: { x: 0, z: 0 },
758
- props: [],
759
- decorations: [],
760
- obstacleCells: new Map(),
761
- reachable: [],
762
- gems: [],
763
- enemies: []
764
- };
765
- // A level grass clearing near the central bridge faces upstream.
766
- const preferred = { x: riverX(landscape, -16) - 13, z: -16 };
767
- let spawn = toWorld(map, preferred.x, preferred.z);
768
- for (let ring = 0; ring < 30 && !isWalkable(map, spawn.x, spawn.z, 1.2); ring++) {
769
- for (let i = 0; i < 24; i++) {
770
- const candidate = toWorld(map, preferred.x + Math.cos((i / 24) * Math.PI * 2) * ring, preferred.z + Math.sin((i / 24) * Math.PI * 2) * ring);
771
- if (surfaceAt(map, candidate.x, candidate.z) === 'grass' && isWalkable(map, candidate.x, candidate.z, 1.2)) {
772
- spawn = candidate;
773
- break;
774
- }
775
- }
776
- }
777
- map.spawn = spawn;
778
- generateScenery(map);
779
- yield;
780
- for (let i = 0; i < 700; i++) {
781
- if (i && i % 100 === 0) yield;
782
- const angle = rng() * Math.PI * 2,
783
- r = Math.sqrt(rng()) * (WORLD_EDGE - 7);
784
- const x = Math.cos(angle) * r,
785
- z = Math.sin(angle) * r,
786
- local = toLocal(map, x, z);
787
- if (gap({ x, z }, map.spawn) < 9 || Math.abs(local.x - riverX(landscape, local.z)) < riverWidth(landscape, local.z) + 2.5) continue;
788
- if (
789
- landscape.bridges.some((bridge) => Math.abs(local.z - bridge.z) < bridge.halfWidth + 3 && Math.abs(local.x - bridge.x) < bridge.halfLength + 5)
790
- )
791
- continue;
792
- if (landscape.caves.some((c) => Math.abs(local.x - c.x) < 10 && Math.abs(local.z - c.z) < 18)) continue;
793
- if (!isWalkable(map, x, z, 1.1)) continue;
794
- const kind = rng() < 0.24 ? 'rock' : rng() < 0.65 ? 'pine' : 'birch';
795
- const scale = kind === 'rock' ? 0.65 + rng() * 2.2 : 0.75 + rng() * 1.05;
796
- const prop: NatureProp = {
797
- x,
798
- z,
799
- kind,
800
- scale,
801
- yaw: rng() * Math.PI * 2,
802
- style: Math.floor(rng() * 4)
803
- };
804
- map.props.push(prop);
805
- indexProp(map, prop);
806
- }
807
- map.reachable = yield* reachableFromSpawn(map);
808
- const candidates = [...map.reachable];
809
- for (let i = candidates.length - 1; i > 0; i--) {
810
- const at = Math.floor(rng() * (i + 1));
811
- [candidates[i], candidates[at]] = [candidates[at]!, candidates[i]!];
812
- }
813
- const place = (target: Point[], count: number, spacing: number, fromSpawn: number) => {
814
- for (const p of candidates) {
815
- if (target.length === count) break;
816
- if (gap(p, map.spawn) >= fromSpawn && target.every((other) => gap(p, other) >= spacing)) target.push({ ...p });
817
- }
818
- if (target.length !== count) throw new Error('The wilderness needs more reachable objective positions');
819
- };
820
- place(map.gems, GEM_GOAL, 12, 6);
821
- place(map.enemies, ENEMY_COUNT, 24, 22);
822
- return map;
823
- }
824
-
825
- function finishMap(builder: Generator<void, NatureMap>): NatureMap {
826
- let next = builder.next();
827
- while (!next.done) next = builder.next();
828
- return next.value;
829
- }
830
-
831
- const nextSeed = () => (cursor = (cursor + 0x9e3779b9) >>> 0);
832
- export function generateNature(seed = nextSeed()): NatureMap {
833
- return finishMap(generateNatureSteps(seed));
834
- }
835
-
836
- interface PendingMap {
837
- seed: number;
838
- builder: Generator<void, NatureMap>;
839
- done: boolean;
840
- map?: NatureMap;
841
- }
842
- let nextMap: PendingMap | undefined;
843
-
844
- /** Prepare one fresh layout in bounded batches, without creating a world, actors or game state. */
845
- export function* warmNextMap(): Iterable<() => void> {
846
- if (!nextMap) {
847
- const seed = nextSeed();
848
- nextMap = { seed, builder: generateNatureSteps(seed), done: false };
849
- }
850
- const pending = nextMap;
851
- while (!pending.done)
852
- yield () => {
853
- if (pending.done) return;
854
- let step: IteratorResult<void, NatureMap>;
855
- try {
856
- step = pending.builder.next();
857
- } catch (error) {
858
- pending.builder = generateNatureSteps(pending.seed);
859
- throw error;
860
- }
861
- if (step.done) {
862
- pending.map = step.value;
863
- pending.done = true;
864
- }
865
- };
866
- if (nextMap !== pending) return;
867
- const map = pending.map!;
868
- const overview = overviewFor(map, MINIMAP_SIZE);
869
- while (nextMap === pending && overview.row < MINIMAP_SIZE) yield () => sampleOverviewRows(map, MINIMAP_SIZE, overview, 4);
870
- }
871
-
872
- export const peekNextMap = (): NatureMap | undefined => nextMap?.map;
873
-
874
- function takeNextMap(): NatureMap {
875
- const pending = nextMap;
876
- nextMap = undefined;
877
- if (!pending) return generateNature();
878
- if (!pending.done) {
879
- pending.map = finishMap(pending.builder);
880
- pending.done = true;
881
- }
882
- return pending.map!;
883
- }
884
- // Movement, combat and objectives.
885
-
886
- export type Phase = 'ready' | 'playing' | 'won' | 'lost';
887
-
888
- export interface Enemy extends Point {
889
- id: number;
890
- home: Point;
891
- health: number;
892
- yaw: number;
893
- windup: number;
894
- recovery: number;
895
- stagger: number;
896
- moving: boolean;
897
- }
898
-
899
- export interface Gem extends Point {
900
- id: number;
901
- taken: boolean;
902
- }
903
-
904
- export interface NatureState {
905
- map: NatureMap;
906
- phase: Phase;
907
- player: Point;
908
- yaw: number;
909
- health: number;
910
- gems: number;
911
- defeated: number;
912
- score: number;
913
- time: number;
914
- attackCooldown: number;
915
- attackPending: number;
916
- invulnerable: number;
917
- moving: boolean;
918
- speed: number;
919
- velocity: Point;
920
- yawVelocity: number;
921
- enemies: Enemy[];
922
- pickups: Gem[];
923
- }
924
-
925
- export interface NatureInput {
926
- x: number;
927
- y: number;
928
- attack: boolean;
929
- }
930
-
931
- export interface NatureEvent {
932
- kind: 'attack' | 'hit' | 'defeated' | 'gem' | 'hurt' | 'won' | 'lost';
933
- x: number;
934
- z: number;
935
- id?: number;
936
- }
937
-
938
- export const distance = (a: Point, b: Point) => Math.hypot(a.x - b.x, a.z - b.z);
939
-
940
- export function createState(seed?: number): NatureState {
941
- const map = seed === undefined ? takeNextMap() : generateNature(seed);
942
- return {
943
- map,
944
- phase: 'ready',
945
- player: { ...map.spawn },
946
- yaw: map.rotation,
947
- health: MAX_HEALTH,
948
- gems: 0,
949
- defeated: 0,
950
- score: 0,
951
- time: 0,
952
- attackCooldown: 0,
953
- attackPending: 0,
954
- invulnerable: 0,
955
- moving: false,
956
- speed: 0,
957
- velocity: { x: 0, z: 0 },
958
- yawVelocity: 0,
959
- enemies: map.enemies.map((p, id) => ({
960
- ...p,
961
- home: { ...p },
962
- id,
963
- health: 2,
964
- yaw: 0,
965
- windup: 0,
966
- recovery: 0,
967
- stagger: 0,
968
- moving: false
969
- })),
970
- pickups: map.gems.map((p, id) => ({ ...p, id, taken: false }))
971
- };
972
- }
973
-
974
- /** Sweep the full direction, settle just before contact, then slide along its continuous normal. */
975
- export interface ActorBody extends Point {
976
- radius: number;
977
- }
978
-
979
- export function moveActor(map: NatureMap, point: Point, dx: number, dz: number, radius = PLAYER_RADIUS, bodies: readonly ActorBody[] = []) {
980
- const clear = (x: number, z: number) =>
981
- isWalkable(map, x, z, radius) &&
982
- bodies.every((body) => {
983
- const next = Math.hypot(x - body.x, z - body.z),
984
- current = Math.hypot(point.x - body.x, point.z - body.z);
985
- return next >= radius + body.radius - 1e-8 || (current < radius + body.radius && next > current + 1e-8);
986
- });
987
- const clearance = (x: number, z: number) =>
988
- Math.min(navigationClearance(map, x, z, radius), ...bodies.map((body) => Math.hypot(x - body.x, z - body.z) - body.radius - radius));
989
- const steps = Math.max(1, Math.ceil(Math.hypot(dx, dz) / 0.2));
990
- const sx = dx / steps,
991
- sz = dz / steps,
992
- length = Math.hypot(sx, sz);
993
- if (length < 1e-8) return;
994
- for (let i = 0; i < steps; i++) {
995
- if (clear(point.x + sx, point.z + sz)) {
996
- point.x += sx;
997
- point.z += sz;
998
- continue;
999
- }
1000
- let low = 0,
1001
- high = 1;
1002
- for (let search = 0; search < 9; search++) {
1003
- const t = (low + high) / 2;
1004
- if (clear(point.x + sx * t, point.z + sz * t)) low = t;
1005
- else high = t;
1006
- }
1007
- const fraction = Math.max(0, low - 0.003 / length);
1008
- point.x += sx * fraction;
1009
- point.z += sz * fraction;
1010
- const probe = 0.08;
1011
- const nx = clearance(point.x + probe, point.z) - clearance(point.x - probe, point.z);
1012
- const nz = clearance(point.x, point.z + probe) - clearance(point.x, point.z - probe);
1013
- const norm = Math.hypot(nx, nz);
1014
- if (norm < 1e-8) continue;
1015
- const normalX = nx / norm,
1016
- normalZ = nz / norm,
1017
- dot = Math.min(0, sx * normalX + sz * normalZ);
1018
- const slideX = (sx - dot * normalX) * (1 - fraction),
1019
- slideZ = (sz - dot * normalZ) * (1 - fraction);
1020
- if (Math.hypot(slideX, slideZ) < 0.002) continue;
1021
- for (const amount of [1, 0.5, 0.25]) {
1022
- if (clear(point.x + slideX * amount, point.z + slideZ * amount)) {
1023
- point.x += slideX * amount;
1024
- point.z += slideZ * amount;
1025
- break;
1026
- }
1027
- }
1028
- }
1029
- }
1030
-
1031
- function actorBodies(state: NatureState, moving: Point): ActorBody[] {
1032
- const bodies = state.enemies.filter((enemy) => enemy !== moving && enemy.health > 0).map((enemy) => ({ x: enemy.x, z: enemy.z, radius: 0.5 }));
1033
- if (moving !== state.player) bodies.push({ ...state.player, radius: PLAYER_RADIUS });
1034
- return bodies;
1035
- }
1036
-
1037
- function canSee(map: NatureMap, a: Point, b: Point) {
1038
- if (Math.abs(groundHeight(map, a.x, a.z) - groundHeight(map, b.x, b.z)) > 1.6) return false;
1039
- const steps = Math.ceil(distance(a, b) / 0.4);
1040
- for (let i = 1; i < steps; i++) {
1041
- const t = i / steps;
1042
- if (!isWalkable(map, a.x + (b.x - a.x) * t, a.z + (b.z - a.z) * t, 0.25)) return false;
1043
- }
1044
- return true;
1045
- }
1046
-
1047
- /** No React or native calls: rules emit events for the engine's effects and HUD. */
1048
- export function step(state: NatureState, input: NatureInput, elapsed: number): NatureEvent[] {
1049
- if (state.phase !== 'playing') return [];
1050
- const dt = Math.min(0.05, Math.max(0, elapsed));
1051
- if (dt === 0) return [];
1052
- const events: NatureEvent[] = [];
1053
- const emit = (kind: NatureEvent['kind'], point: Point, id?: number) => events.push({ kind, ...point, id });
1054
- state.time += dt;
1055
- state.attackCooldown = Math.max(0, state.attackCooldown - dt);
1056
- state.invulnerable = Math.max(0, state.invulnerable - dt);
1057
- const magnitude = Math.hypot(input.x, input.y);
1058
- const moving = magnitude >= (state.moving ? MOVEMENT_STOP : MOVEMENT_START);
1059
- const dx = moving ? input.x / Math.max(1, magnitude) : 0;
1060
- const dz = moving ? -input.y / Math.max(1, magnitude) : 0;
1061
- if (input.attack && state.attackCooldown === 0) {
1062
- const target = state.enemies
1063
- .filter((e) => e.health > 0 && distance(e, state.player) <= ATTACK_RANGE && canSee(state.map, state.player, e))
1064
- .sort((a, b) => distance(a, state.player) - distance(b, state.player))[0];
1065
- if (target) {
1066
- state.yaw = Math.atan2(target.x - state.player.x, target.z - state.player.z);
1067
- state.yawVelocity = 0;
1068
- }
1069
- state.attackCooldown = ATTACK_COOLDOWN;
1070
- state.attackPending = ATTACK_HIT_TIME;
1071
- emit('attack', state.player);
1072
- }
1073
- const previousX = state.player.x;
1074
- const previousZ = state.player.z;
1075
- const speed = PLAYER_SPEED * (state.attackPending > 0 ? 0.3 : 1);
1076
- const blend = 1 - Math.exp(-dt / 0.065);
1077
- if (!moving) {
1078
- state.velocity.x = 0;
1079
- state.velocity.z = 0;
1080
- state.yawVelocity = 0;
1081
- }
1082
- if (moving && state.attackPending <= 0) {
1083
- const targetYaw = Math.atan2(dx, dz);
1084
- const difference = Math.atan2(Math.sin(targetYaw - state.yaw), Math.cos(targetYaw - state.yaw));
1085
- // A critically damped heading spring eases angular acceleration and braking without orbit jitter.
1086
- const omega = 12,
1087
- decay = Math.exp(-omega * dt),
1088
- impulse = (state.yawVelocity - omega * difference) * dt;
1089
- const nextError = (-difference + impulse) * decay;
1090
- let change = Math.max(-5 * dt, Math.min(5 * dt, difference + nextError));
1091
- state.yawVelocity = Math.max(-5, Math.min(5, (state.yawVelocity - omega * impulse) * decay));
1092
- if (change * difference > 0 && Math.abs(change) > Math.abs(difference)) {
1093
- change = difference;
1094
- state.yawVelocity = 0;
1095
- }
1096
- state.yaw += change;
1097
- }
1098
- if (moving) {
1099
- const forwardX = Math.sin(state.yaw),
1100
- forwardZ = Math.cos(state.yaw);
1101
- // Slow into sharp turns and pivot before reversing, rather than playing a forward gait backwards.
1102
- const alignment = Math.max(0, (dx * forwardX + dz * forwardZ) / Math.max(1e-8, Math.hypot(dx, dz)));
1103
- const turnSpeed = speed * alignment * alignment;
1104
- state.velocity.x += (dx * turnSpeed - state.velocity.x) * blend;
1105
- state.velocity.z += (dz * turnSpeed - state.velocity.z) * blend;
1106
- const backward = Math.min(0, state.velocity.x * forwardX + state.velocity.z * forwardZ);
1107
- state.velocity.x -= backward * forwardX;
1108
- state.velocity.z -= backward * forwardZ;
1109
- }
1110
- moveActor(state.map, state.player, state.velocity.x * dt, state.velocity.z * dt, PLAYER_RADIUS, actorBodies(state, state.player));
1111
- state.velocity.x = (state.player.x - previousX) / dt;
1112
- state.velocity.z = (state.player.z - previousZ) / dt;
1113
- state.speed = Math.hypot(state.player.x - previousX, state.player.z - previousZ) / dt;
1114
- state.moving = state.speed > 0.001;
1115
-
1116
- if (state.attackPending > 0) {
1117
- state.attackPending = Math.max(0, state.attackPending - dt);
1118
- if (state.attackPending === 0) {
1119
- for (const enemy of state.enemies) {
1120
- const d = distance(enemy, state.player);
1121
- if (enemy.health <= 0 || d > ATTACK_RANGE || !canSee(state.map, state.player, enemy)) continue;
1122
- const facing = ((enemy.x - state.player.x) * Math.sin(state.yaw) + (enemy.z - state.player.z) * Math.cos(state.yaw)) / (d || 1);
1123
- if (facing < 0.15 && d > 0.8) continue;
1124
- enemy.health--;
1125
- enemy.stagger = 0.35;
1126
- enemy.windup = 0;
1127
- moveActor(state.map, enemy, Math.sin(state.yaw) * 0.65, Math.cos(state.yaw) * 0.65, 0.65, actorBodies(state, enemy));
1128
- emit(enemy.health === 0 ? 'defeated' : 'hit', enemy, enemy.id);
1129
- state.score += enemy.health === 0 ? POINTS_ROBOT_DEFEAT : POINTS_ROBOT_HIT;
1130
- if (enemy.health === 0) {
1131
- state.defeated++;
1132
- // Enemies leave a bonus gem; collecting 24 of the available 32 completes the gem objective.
1133
- state.pickups.push({
1134
- x: enemy.x,
1135
- z: enemy.z,
1136
- id: state.pickups.length,
1137
- taken: false
1138
- });
1139
- }
1140
- }
1141
- }
1142
- }
1143
-
1144
- for (const enemy of state.enemies) {
1145
- enemy.moving = false;
1146
- if (enemy.health <= 0) continue;
1147
- enemy.recovery = Math.max(0, enemy.recovery - dt);
1148
- enemy.stagger = Math.max(0, enemy.stagger - dt);
1149
- if (enemy.stagger > 0) continue;
1150
- const d = distance(enemy, state.player);
1151
- if (enemy.windup > 0) {
1152
- enemy.windup = Math.max(0, enemy.windup - dt);
1153
- if (enemy.windup === 0) {
1154
- enemy.recovery = 1.2;
1155
- if (d < 2.1 && state.invulnerable === 0 && canSee(state.map, enemy, state.player)) {
1156
- state.health--;
1157
- state.invulnerable = 1.2;
1158
- emit('hurt', state.player);
1159
- if (state.health === 0) {
1160
- state.phase = 'lost';
1161
- emit('lost', state.player);
1162
- return events;
1163
- }
1164
- }
1165
- }
1166
- continue;
1167
- }
1168
- const visible = d < 13 && canSee(state.map, enemy, state.player);
1169
- if (visible && d < 1.25 && enemy.recovery === 0) {
1170
- enemy.windup = 0.6;
1171
- enemy.yaw = Math.atan2(state.player.x - enemy.x, state.player.z - enemy.z);
1172
- } else {
1173
- const patrol = {
1174
- x: enemy.home.x + Math.sin(state.time * 0.45 + enemy.id) * 1.8,
1175
- z: enemy.home.z + Math.cos(state.time * 0.45 + enemy.id) * 1.8
1176
- };
1177
- const target = visible ? state.player : patrol;
1178
- const tx = target.x - enemy.x;
1179
- const tz = target.z - enemy.z;
1180
- const length = Math.hypot(tx, tz);
1181
- if (length > (visible ? 1.05 : 0.2)) {
1182
- const speed = visible ? 2.7 : 1.1;
1183
- const previous = { x: enemy.x, z: enemy.z };
1184
- moveActor(state.map, enemy, (tx / length) * speed * dt, (tz / length) * speed * dt, 0.65, actorBodies(state, enemy));
1185
- enemy.yaw = Math.atan2(tx, tz);
1186
- enemy.moving = distance(previous, enemy) / dt > 0.05;
1187
- }
1188
- }
1189
- }
1190
-
1191
- for (const gem of state.pickups) {
1192
- if (
1193
- !gem.taken &&
1194
- distance(gem, state.player) < 1.2 &&
1195
- Math.abs(groundHeight(state.map, gem.x, gem.z) - groundHeight(state.map, state.player.x, state.player.z)) < 1.2 &&
1196
- canSee(state.map, state.player, gem)
1197
- ) {
1198
- gem.taken = true;
1199
- state.gems++;
1200
- state.score += POINTS_GEM;
1201
- emit('gem', gem, gem.id);
1202
- }
1203
- }
1204
- if (state.gems >= GEM_GOAL && state.defeated === state.enemies.length) {
1205
- state.phase = 'won';
1206
- state.score += state.health * POINTS_HEALTH_BONUS;
1207
- emit('won', state.player);
1208
- }
1209
- return events;
1210
- }