kiwiengine 0.0.1-alpha → 0.5.2

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 (438) hide show
  1. package/README.ko.md +550 -0
  2. package/README.md +575 -4
  3. package/examples/collision-test/assets/cat.png +0 -0
  4. package/examples/collision-test/dist/game.js +2 -0
  5. package/examples/collision-test/dist/game.js.LICENSE.txt +35 -0
  6. package/examples/collision-test/index.ts +30 -0
  7. package/examples/dom-particle-test/assets/bird.png +0 -0
  8. package/examples/dom-particle-test/dist/game.js +2 -0
  9. package/examples/dom-particle-test/dist/game.js.LICENSE.txt +35 -0
  10. package/examples/dom-particle-test/index.html +24 -0
  11. package/examples/dom-particle-test/index.ts +27 -0
  12. package/examples/dom-sprite-test/assets/bird.png +0 -0
  13. package/examples/dom-sprite-test/assets/fire.png +0 -0
  14. package/examples/dom-sprite-test/assets/run.png +0 -0
  15. package/examples/dom-sprite-test/dist/game.js +2 -0
  16. package/examples/dom-sprite-test/dist/game.js.LICENSE.txt +35 -0
  17. package/examples/dom-sprite-test/index.html +24 -0
  18. package/examples/dom-sprite-test/index.ts +38 -0
  19. package/examples/dom-test/dist/game.js +2 -0
  20. package/examples/dom-test/dist/game.js.LICENSE.txt +35 -0
  21. package/examples/dom-test/index.html +24 -0
  22. package/examples/dom-test/index.ts +22 -0
  23. package/examples/flappy-cat/assets/bgm/bgm.ogg +0 -0
  24. package/examples/flappy-cat/assets/images/base.png +0 -0
  25. package/examples/flappy-cat/assets/images/bg.png +0 -0
  26. package/examples/flappy-cat/assets/images/cat.png +0 -0
  27. package/examples/flappy-cat/assets/images/pipe-green.png +0 -0
  28. package/examples/flappy-cat/assets/images/pipe-red.png +0 -0
  29. package/examples/flappy-cat/assets/sfx/die.wav +0 -0
  30. package/examples/flappy-cat/assets/sfx/hit.wav +0 -0
  31. package/examples/flappy-cat/assets/sfx/point.wav +0 -0
  32. package/examples/flappy-cat/assets/sfx/wing.wav +0 -0
  33. package/examples/flappy-cat/dist/game.js +0 -0
  34. package/examples/flappy-cat/index.html +24 -0
  35. package/examples/flappy-cat/index.ts +0 -0
  36. package/examples/particle-test/assets/bird.png +0 -0
  37. package/examples/particle-test/dist/game.js +2 -0
  38. package/examples/particle-test/dist/game.js.LICENSE.txt +35 -0
  39. package/examples/particle-test/index.html +24 -0
  40. package/examples/particle-test/index.ts +30 -0
  41. package/examples/renderer-test/dist/game.js +2 -0
  42. package/examples/renderer-test/dist/game.js.LICENSE.txt +35 -0
  43. package/examples/renderer-test/index.html +24 -0
  44. package/examples/renderer-test/index.ts +9 -0
  45. package/examples/simple-battle/assets/bgm/battle.mp3 +0 -0
  46. package/examples/simple-battle/assets/bitmap-fonts/white-peaberry.fnt +107 -0
  47. package/examples/simple-battle/assets/bitmap-fonts/white-peaberry.png +0 -0
  48. package/examples/simple-battle/assets/joystick/joystick.png +0 -0
  49. package/examples/simple-battle/assets/joystick/knob.png +0 -0
  50. package/examples/simple-battle/assets/sfx/hero/die/die.wav +0 -0
  51. package/examples/simple-battle/assets/sfx/hero/heal/heal.wav +0 -0
  52. package/examples/simple-battle/assets/sfx/hero/hit/hit1.wav +0 -0
  53. package/examples/simple-battle/assets/sfx/hero/hit/hit2.wav +0 -0
  54. package/examples/simple-battle/assets/sfx/hero/hit/hit3.wav +0 -0
  55. package/examples/simple-battle/assets/sfx/hero/miss/miss1.wav +0 -0
  56. package/examples/simple-battle/assets/sfx/hero/miss/miss2.wav +0 -0
  57. package/examples/simple-battle/assets/sfx/hero/miss/miss3.wav +0 -0
  58. package/examples/simple-battle/assets/sfx/orc/die/die.wav +0 -0
  59. package/examples/simple-battle/assets/sfx/orc/hit/hit1.wav +0 -0
  60. package/examples/simple-battle/assets/sfx/orc/hit/hit2.wav +0 -0
  61. package/examples/simple-battle/assets/sfx/orc/hit/hit3.wav +0 -0
  62. package/examples/simple-battle/assets/sfx/orc/miss/miss1.wav +0 -0
  63. package/examples/simple-battle/assets/sfx/orc/miss/miss2.wav +0 -0
  64. package/examples/simple-battle/assets/sfx/orc/miss/miss3.wav +0 -0
  65. package/examples/simple-battle/assets/spritesheets/hero-atlas.json +289 -0
  66. package/examples/simple-battle/assets/spritesheets/hero.png +0 -0
  67. package/examples/simple-battle/assets/spritesheets/orc-atlas.json +289 -0
  68. package/examples/simple-battle/assets/spritesheets/orc.png +0 -0
  69. package/examples/simple-battle/assets/spritesheets/potion-atlas.json +83 -0
  70. package/examples/simple-battle/assets/spritesheets/potion.png +0 -0
  71. package/examples/simple-battle/dist/game.js +2 -0
  72. package/examples/simple-battle/dist/game.js.LICENSE.txt +35 -0
  73. package/examples/simple-battle/hud/damage-text.ts +45 -0
  74. package/examples/simple-battle/hud/heal-text.ts +45 -0
  75. package/examples/simple-battle/hud/hp-bar.ts +38 -0
  76. package/examples/simple-battle/index.html +24 -0
  77. package/examples/simple-battle/index.ts +41 -0
  78. package/examples/simple-battle/objects/character.ts +95 -0
  79. package/examples/simple-battle/objects/hero.ts +113 -0
  80. package/examples/simple-battle/objects/orc.ts +109 -0
  81. package/examples/simple-battle/objects/potion.ts +29 -0
  82. package/examples/simple-battle/stage.ts +176 -0
  83. package/examples/spine-test/assets/spine/spineboy.atlas +95 -0
  84. package/examples/spine-test/assets/spine/spineboy.png +0 -0
  85. package/examples/spine-test/assets/spine/spineboy.skel +0 -0
  86. package/examples/spine-test/dist/game.js +2 -0
  87. package/examples/spine-test/dist/game.js.LICENSE.txt +35 -0
  88. package/examples/spine-test/index.html +24 -0
  89. package/examples/spine-test/index.ts +29 -0
  90. package/examples/sprite-test/assets/bird.png +0 -0
  91. package/examples/sprite-test/assets/fire.png +0 -0
  92. package/examples/sprite-test/dist/game.js +2 -0
  93. package/examples/sprite-test/dist/game.js.LICENSE.txt +35 -0
  94. package/examples/sprite-test/index.html +24 -0
  95. package/examples/sprite-test/index.ts +41 -0
  96. package/examples/tsconfig.json +2 -1
  97. package/examples/webpack.config.js +14 -3
  98. package/jest.config.ts +10 -0
  99. package/lib/asset/audio.js +47 -11
  100. package/lib/asset/audio.js.map +1 -1
  101. package/lib/asset/loaders/audio.js +3 -3
  102. package/lib/asset/loaders/audio.js.map +1 -1
  103. package/lib/asset/loaders/binary.js +3 -3
  104. package/lib/asset/loaders/binary.js.map +1 -1
  105. package/lib/asset/loaders/bitmap-font.js +71 -0
  106. package/lib/asset/loaders/bitmap-font.js.map +1 -0
  107. package/lib/asset/loaders/font.js +1 -1
  108. package/lib/asset/loaders/font.js.map +1 -1
  109. package/lib/asset/loaders/loader.js +17 -12
  110. package/lib/asset/loaders/loader.js.map +1 -1
  111. package/lib/asset/loaders/spritesheet.js +6 -7
  112. package/lib/asset/loaders/spritesheet.js.map +1 -1
  113. package/lib/asset/loaders/text.js +3 -3
  114. package/lib/asset/loaders/text.js.map +1 -1
  115. package/lib/asset/loaders/texture.js +5 -4
  116. package/lib/asset/loaders/texture.js.map +1 -1
  117. package/lib/asset/preload.js +60 -56
  118. package/lib/asset/preload.js.map +1 -1
  119. package/lib/collision/check-collision.js +804 -0
  120. package/lib/collision/check-collision.js.map +1 -0
  121. package/lib/collision/check-collision.test.js +300 -0
  122. package/lib/collision/check-collision.test.js.map +1 -0
  123. package/lib/collision/colliders.js +8 -0
  124. package/lib/collision/colliders.js.map +1 -0
  125. package/lib/debug.js.map +1 -0
  126. package/lib/dom/dom-animated-sprite.js +121 -0
  127. package/lib/dom/dom-animated-sprite.js.map +1 -0
  128. package/lib/dom/dom-game-object.js +106 -0
  129. package/lib/dom/dom-game-object.js.map +1 -0
  130. package/lib/dom/dom-particle.js +105 -0
  131. package/lib/dom/dom-particle.js.map +1 -0
  132. package/lib/dom/dom-preload.js +43 -0
  133. package/lib/dom/dom-preload.js.map +1 -0
  134. package/lib/dom/dom-sprite.js +40 -0
  135. package/lib/dom/dom-sprite.js.map +1 -0
  136. package/lib/dom/dom-texture-loader.js +36 -0
  137. package/lib/dom/dom-texture-loader.js.map +1 -0
  138. package/lib/dom/dom-utils.js +20 -0
  139. package/lib/dom/dom-utils.js.map +1 -0
  140. package/lib/index copy.js +16 -0
  141. package/lib/index copy.js.map +1 -0
  142. package/lib/index.js +35 -10
  143. package/lib/index.js.map +1 -1
  144. package/lib/input/joystick.js +262 -0
  145. package/lib/input/joystick.js.map +1 -0
  146. package/lib/node/core/dirty-number.js +38 -0
  147. package/lib/node/core/dirty-number.js.map +1 -0
  148. package/lib/node/core/game-node.js +63 -0
  149. package/lib/node/core/game-node.js.map +1 -0
  150. package/lib/node/core/game-object.js +8 -0
  151. package/lib/node/core/game-object.js.map +1 -0
  152. package/lib/node/core/renderable.js +52 -0
  153. package/lib/node/core/renderable.js.map +1 -0
  154. package/lib/node/core/transform.js +59 -0
  155. package/lib/node/core/transform.js.map +1 -0
  156. package/lib/node/core/transformable.js +85 -0
  157. package/lib/node/core/transformable.js.map +1 -0
  158. package/lib/node/ext/animated-sprite.js +96 -0
  159. package/lib/node/ext/animated-sprite.js.map +1 -0
  160. package/lib/node/ext/bitmap-text.js +89 -0
  161. package/lib/node/ext/bitmap-text.js.map +1 -0
  162. package/lib/node/ext/circle.js +28 -0
  163. package/lib/node/ext/circle.js.map +1 -0
  164. package/lib/node/ext/deplay.js +20 -0
  165. package/lib/node/ext/deplay.js.map +1 -0
  166. package/lib/node/ext/dom-container.js +51 -0
  167. package/lib/node/ext/dom-container.js.map +1 -0
  168. package/lib/node/ext/interval.js +20 -0
  169. package/lib/node/ext/interval.js.map +1 -0
  170. package/lib/node/ext/particle.js +98 -0
  171. package/lib/node/ext/particle.js.map +1 -0
  172. package/lib/node/ext/rectangle.js +32 -0
  173. package/lib/node/ext/rectangle.js.map +1 -0
  174. package/lib/node/ext/spine.js +272 -0
  175. package/lib/node/ext/spine.js.map +1 -0
  176. package/lib/node/ext/sprite.js +42 -0
  177. package/lib/node/ext/sprite.js.map +1 -0
  178. package/lib/node/physics/physics-object.js +112 -0
  179. package/lib/node/physics/physics-object.js.map +1 -0
  180. package/lib/node/physics/physics-world.js +27 -0
  181. package/lib/node/physics/physics-world.js.map +1 -0
  182. package/lib/renderer/camera.js +19 -0
  183. package/lib/renderer/camera.js.map +1 -0
  184. package/lib/renderer/container-manager.js +29 -0
  185. package/lib/renderer/container-manager.js.map +1 -0
  186. package/lib/renderer/fps-display.js +18 -0
  187. package/lib/renderer/fps-display.js.map +1 -0
  188. package/lib/renderer/layer.js +12 -0
  189. package/lib/renderer/layer.js.map +1 -0
  190. package/lib/renderer/renderer.js +145 -0
  191. package/lib/renderer/renderer.js.map +1 -0
  192. package/lib/renderer/ticker.js +56 -0
  193. package/lib/renderer/ticker.js.map +1 -0
  194. package/lib/renderer/ticker.test.js +241 -0
  195. package/lib/renderer/ticker.test.js.map +1 -0
  196. package/lib/types/asset/audio.d.ts +5 -4
  197. package/lib/types/asset/audio.d.ts.map +1 -1
  198. package/lib/types/asset/loaders/audio.d.ts +1 -1
  199. package/lib/types/asset/loaders/audio.d.ts.map +1 -1
  200. package/lib/types/asset/loaders/binary.d.ts +1 -1
  201. package/lib/types/asset/loaders/binary.d.ts.map +1 -1
  202. package/lib/types/asset/loaders/bitmap-font.d.ts +16 -0
  203. package/lib/types/asset/loaders/bitmap-font.d.ts.map +1 -0
  204. package/lib/types/asset/loaders/font.d.ts +1 -1
  205. package/lib/types/asset/loaders/font.d.ts.map +1 -1
  206. package/lib/types/asset/loaders/loader.d.ts +6 -6
  207. package/lib/types/asset/loaders/loader.d.ts.map +1 -1
  208. package/lib/types/asset/loaders/spritesheet.d.ts +5 -5
  209. package/lib/types/asset/loaders/spritesheet.d.ts.map +1 -1
  210. package/lib/types/asset/loaders/text.d.ts +1 -1
  211. package/lib/types/asset/loaders/text.d.ts.map +1 -1
  212. package/lib/types/asset/loaders/texture.d.ts +2 -2
  213. package/lib/types/asset/loaders/texture.d.ts.map +1 -1
  214. package/lib/types/asset/preload.d.ts +5 -3
  215. package/lib/types/asset/preload.d.ts.map +1 -1
  216. package/lib/types/bitmap-font.js +2 -0
  217. package/lib/types/bitmap-font.js.map +1 -0
  218. package/lib/types/collision/check-collision.d.ts +4 -0
  219. package/lib/types/collision/check-collision.d.ts.map +1 -0
  220. package/lib/types/collision/check-collision.test.d.ts +2 -0
  221. package/lib/types/collision/check-collision.test.d.ts.map +1 -0
  222. package/lib/types/collision/colliders.d.ts +34 -0
  223. package/lib/types/collision/colliders.d.ts.map +1 -0
  224. package/lib/types/debug.d.ts.map +1 -0
  225. package/lib/types/dom/dom-animated-sprite.d.ts +29 -0
  226. package/lib/types/dom/dom-animated-sprite.d.ts.map +1 -0
  227. package/lib/types/dom/dom-game-object.d.ts +44 -0
  228. package/lib/types/dom/dom-game-object.d.ts.map +1 -0
  229. package/lib/types/dom/dom-particle.d.ts +30 -0
  230. package/lib/types/dom/dom-particle.d.ts.map +1 -0
  231. package/lib/types/dom/dom-preload.d.ts +2 -0
  232. package/lib/types/dom/dom-preload.d.ts.map +1 -0
  233. package/lib/types/dom/dom-sprite.d.ts +13 -0
  234. package/lib/types/dom/dom-sprite.d.ts.map +1 -0
  235. package/lib/types/dom/dom-texture-loader.d.ts +8 -0
  236. package/lib/types/dom/dom-texture-loader.d.ts.map +1 -0
  237. package/lib/types/dom/dom-utils.d.ts +3 -0
  238. package/lib/types/dom/dom-utils.d.ts.map +1 -0
  239. package/lib/types/index copy.d.ts +16 -0
  240. package/lib/types/index copy.d.ts.map +1 -0
  241. package/lib/types/index.d.ts +25 -11
  242. package/lib/types/index.d.ts.map +1 -1
  243. package/lib/types/input/joystick.d.ts +28 -0
  244. package/lib/types/input/joystick.d.ts.map +1 -0
  245. package/lib/types/node/core/dirty-number.d.ts +17 -0
  246. package/lib/types/node/core/dirty-number.d.ts.map +1 -0
  247. package/lib/types/node/core/game-node.d.ts +16 -0
  248. package/lib/types/node/core/game-node.d.ts.map +1 -0
  249. package/lib/types/node/core/game-object.d.ts +8 -0
  250. package/lib/types/node/core/game-object.d.ts.map +1 -0
  251. package/lib/types/node/core/renderable.d.ts +22 -0
  252. package/lib/types/node/core/renderable.d.ts.map +1 -0
  253. package/lib/types/node/core/transform.d.ts +25 -0
  254. package/lib/types/node/core/transform.d.ts.map +1 -0
  255. package/lib/types/node/core/transformable.d.ts +44 -0
  256. package/lib/types/node/core/transformable.d.ts.map +1 -0
  257. package/lib/types/node/ext/animated-sprite.d.ts +28 -0
  258. package/lib/types/node/ext/animated-sprite.d.ts.map +1 -0
  259. package/lib/types/node/ext/bitmap-text.d.ts +14 -0
  260. package/lib/types/node/ext/bitmap-text.d.ts.map +1 -0
  261. package/lib/types/node/ext/circle.d.ts +19 -0
  262. package/lib/types/node/ext/circle.d.ts.map +1 -0
  263. package/lib/types/node/ext/deplay.d.ts +8 -0
  264. package/lib/types/node/ext/deplay.d.ts.map +1 -0
  265. package/lib/types/node/ext/dom-container.d.ts +12 -0
  266. package/lib/types/node/ext/dom-container.d.ts.map +1 -0
  267. package/lib/types/node/ext/interval.d.ts +9 -0
  268. package/lib/types/node/ext/interval.d.ts.map +1 -0
  269. package/lib/types/node/ext/particle.d.ts +30 -0
  270. package/lib/types/node/ext/particle.d.ts.map +1 -0
  271. package/lib/types/node/ext/rectangle.d.ts +22 -0
  272. package/lib/types/node/ext/rectangle.d.ts.map +1 -0
  273. package/lib/types/node/ext/spine.d.ts +36 -0
  274. package/lib/types/node/ext/spine.d.ts.map +1 -0
  275. package/lib/types/node/ext/sprite.d.ts +13 -0
  276. package/lib/types/node/ext/sprite.d.ts.map +1 -0
  277. package/lib/types/node/physics/physics-object.d.ts +38 -0
  278. package/lib/types/node/physics/physics-object.d.ts.map +1 -0
  279. package/lib/types/node/physics/physics-world.d.ts +18 -0
  280. package/lib/types/node/physics/physics-world.d.ts.map +1 -0
  281. package/lib/types/renderer/camera.d.ts +13 -0
  282. package/lib/types/renderer/camera.d.ts.map +1 -0
  283. package/lib/types/renderer/container-manager.d.ts +9 -0
  284. package/lib/types/renderer/container-manager.d.ts.map +1 -0
  285. package/lib/types/renderer/fps-display.d.ts +7 -0
  286. package/lib/types/renderer/fps-display.d.ts.map +1 -0
  287. package/lib/types/renderer/layer.d.ts +7 -0
  288. package/lib/types/renderer/layer.d.ts.map +1 -0
  289. package/lib/types/renderer/renderer.d.ts +40 -0
  290. package/lib/types/renderer/renderer.d.ts.map +1 -0
  291. package/lib/types/renderer/ticker.d.ts +6 -0
  292. package/lib/types/renderer/ticker.d.ts.map +1 -0
  293. package/lib/types/renderer/ticker.test.d.ts +40 -0
  294. package/lib/types/renderer/ticker.test.d.ts.map +1 -0
  295. package/lib/types/types/bitmap-font.d.ts +18 -0
  296. package/lib/types/types/bitmap-font.d.ts.map +1 -0
  297. package/lib/types/utils/device.d.ts +2 -0
  298. package/lib/types/utils/device.d.ts.map +1 -0
  299. package/lib/utils/device.js +2 -0
  300. package/lib/utils/device.js.map +1 -0
  301. package/package.json +8 -7
  302. package/src/asset/audio.ts +134 -90
  303. package/src/asset/loaders/audio.ts +19 -19
  304. package/src/asset/loaders/binary.ts +16 -16
  305. package/src/asset/loaders/bitmap-font.ts +85 -0
  306. package/src/asset/loaders/font.ts +14 -14
  307. package/src/asset/loaders/loader.ts +27 -23
  308. package/src/asset/loaders/spritesheet.ts +34 -36
  309. package/src/asset/loaders/text.ts +15 -15
  310. package/src/asset/loaders/texture.ts +29 -28
  311. package/src/asset/preload.ts +75 -64
  312. package/src/collision/check-collision.test.ts +349 -0
  313. package/src/collision/check-collision.ts +821 -0
  314. package/src/collision/colliders.ts +19 -0
  315. package/src/debug.ts +5 -0
  316. package/src/dom/dom-animated-sprite.ts +153 -0
  317. package/src/dom/dom-game-object.ts +131 -0
  318. package/src/dom/dom-particle.ts +151 -0
  319. package/src/dom/dom-preload.ts +54 -0
  320. package/src/dom/dom-sprite.ts +50 -0
  321. package/src/dom/dom-texture-loader.ts +44 -0
  322. package/src/dom/dom-utils.ts +19 -0
  323. package/src/index.ts +46 -13
  324. package/src/input/joystick.ts +316 -0
  325. package/src/node/core/dirty-number.ts +45 -0
  326. package/src/node/core/game-node.ts +74 -0
  327. package/src/node/core/game-object.ts +11 -0
  328. package/src/node/core/renderable.ts +65 -0
  329. package/src/node/core/transform.ts +70 -0
  330. package/src/node/core/transformable.ts +111 -0
  331. package/src/node/ext/animated-sprite.ts +123 -0
  332. package/src/node/ext/bitmap-text.ts +109 -0
  333. package/src/node/ext/circle.ts +40 -0
  334. package/src/node/ext/deplay.ts +24 -0
  335. package/src/node/ext/dom-container.ts +62 -0
  336. package/src/node/ext/interval.ts +24 -0
  337. package/src/node/ext/particle.ts +142 -0
  338. package/src/node/ext/rectangle.ts +51 -0
  339. package/src/node/ext/spine.ts +323 -0
  340. package/src/node/ext/sprite.ts +53 -0
  341. package/src/node/physics/physics-object.ts +156 -0
  342. package/src/node/physics/physics-world.ts +40 -0
  343. package/src/renderer/camera.ts +25 -0
  344. package/src/renderer/container-manager.ts +36 -0
  345. package/src/renderer/fps-display.ts +21 -0
  346. package/src/renderer/layer.ts +15 -0
  347. package/src/renderer/renderer.ts +180 -0
  348. package/src/renderer/ticker.test.ts +325 -0
  349. package/src/renderer/ticker.ts +54 -0
  350. package/src/types/bitmap-font.ts +19 -0
  351. package/src/utils/device.ts +1 -0
  352. package/examples/test-dom/index.ts +0 -21
  353. package/lib/game-object/game-object-physics.js +0 -188
  354. package/lib/game-object/game-object-physics.js.map +0 -1
  355. package/lib/game-object/game-object-rendering.js +0 -35
  356. package/lib/game-object/game-object-rendering.js.map +0 -1
  357. package/lib/game-object/game-object.js +0 -162
  358. package/lib/game-object/game-object.js.map +0 -1
  359. package/lib/game-object/transform.js +0 -118
  360. package/lib/game-object/transform.js.map +0 -1
  361. package/lib/game-object-ext/animated-sprite.js +0 -117
  362. package/lib/game-object-ext/animated-sprite.js.map +0 -1
  363. package/lib/game-object-ext/dom-container.js +0 -56
  364. package/lib/game-object-ext/dom-container.js.map +0 -1
  365. package/lib/game-object-ext/rect.js +0 -30
  366. package/lib/game-object-ext/rect.js.map +0 -1
  367. package/lib/game-object-ext/spine.js +0 -206
  368. package/lib/game-object-ext/spine.js.map +0 -1
  369. package/lib/game-object-ext/sprite.js +0 -46
  370. package/lib/game-object-ext/sprite.js.map +0 -1
  371. package/lib/game-object-ext/text.js +0 -68
  372. package/lib/game-object-ext/text.js.map +0 -1
  373. package/lib/game-object-ext/tiling-sprite.js +0 -64
  374. package/lib/game-object-ext/tiling-sprite.js.map +0 -1
  375. package/lib/types/game-object/game-object-physics.d.ts +0 -42
  376. package/lib/types/game-object/game-object-physics.d.ts.map +0 -1
  377. package/lib/types/game-object/game-object-rendering.d.ts +0 -15
  378. package/lib/types/game-object/game-object-rendering.d.ts.map +0 -1
  379. package/lib/types/game-object/game-object.d.ts +0 -81
  380. package/lib/types/game-object/game-object.d.ts.map +0 -1
  381. package/lib/types/game-object/transform.d.ts +0 -43
  382. package/lib/types/game-object/transform.d.ts.map +0 -1
  383. package/lib/types/game-object-ext/animated-sprite.d.ts +0 -29
  384. package/lib/types/game-object-ext/animated-sprite.d.ts.map +0 -1
  385. package/lib/types/game-object-ext/dom-container.d.ts +0 -16
  386. package/lib/types/game-object-ext/dom-container.d.ts.map +0 -1
  387. package/lib/types/game-object-ext/rect.d.ts +0 -17
  388. package/lib/types/game-object-ext/rect.d.ts.map +0 -1
  389. package/lib/types/game-object-ext/spine.d.ts +0 -35
  390. package/lib/types/game-object-ext/spine.d.ts.map +0 -1
  391. package/lib/types/game-object-ext/sprite.d.ts +0 -14
  392. package/lib/types/game-object-ext/sprite.d.ts.map +0 -1
  393. package/lib/types/game-object-ext/text.d.ts +0 -26
  394. package/lib/types/game-object-ext/text.d.ts.map +0 -1
  395. package/lib/types/game-object-ext/tiling-sprite.d.ts +0 -20
  396. package/lib/types/game-object-ext/tiling-sprite.d.ts.map +0 -1
  397. package/lib/types/utils/debug.d.ts.map +0 -1
  398. package/lib/types/utils/go.d.ts +0 -26
  399. package/lib/types/utils/go.d.ts.map +0 -1
  400. package/lib/types/world/world-debug.d.ts +0 -11
  401. package/lib/types/world/world-debug.d.ts.map +0 -1
  402. package/lib/types/world/world-physics.d.ts +0 -16
  403. package/lib/types/world/world-physics.d.ts.map +0 -1
  404. package/lib/types/world/world-rendering.d.ts +0 -28
  405. package/lib/types/world/world-rendering.d.ts.map +0 -1
  406. package/lib/types/world/world.d.ts +0 -38
  407. package/lib/types/world/world.d.ts.map +0 -1
  408. package/lib/utils/debug.js.map +0 -1
  409. package/lib/utils/go.js +0 -33
  410. package/lib/utils/go.js.map +0 -1
  411. package/lib/world/world-debug.js +0 -89
  412. package/lib/world/world-debug.js.map +0 -1
  413. package/lib/world/world-physics.js +0 -45
  414. package/lib/world/world-physics.js.map +0 -1
  415. package/lib/world/world-rendering.js +0 -123
  416. package/lib/world/world-rendering.js.map +0 -1
  417. package/lib/world/world.js +0 -147
  418. package/lib/world/world.js.map +0 -1
  419. package/src/game-object/game-object-physics.ts +0 -191
  420. package/src/game-object/game-object-rendering.ts +0 -27
  421. package/src/game-object/game-object.ts +0 -190
  422. package/src/game-object/transform.ts +0 -164
  423. package/src/game-object-ext/animated-sprite.ts +0 -140
  424. package/src/game-object-ext/dom-container.ts +0 -67
  425. package/src/game-object-ext/rect.ts +0 -40
  426. package/src/game-object-ext/spine.ts +0 -235
  427. package/src/game-object-ext/sprite.ts +0 -55
  428. package/src/game-object-ext/text.ts +0 -83
  429. package/src/game-object-ext/tiling-sprite.ts +0 -73
  430. package/src/utils/debug.ts +0 -5
  431. package/src/utils/go.ts +0 -53
  432. package/src/world/world-debug.ts +0 -114
  433. package/src/world/world-physics.ts +0 -52
  434. package/src/world/world-rendering.ts +0 -145
  435. package/src/world/world.ts +0 -171
  436. /package/examples/{test-dom → collision-test}/index.html +0 -0
  437. /package/lib/{utils/debug.js → debug.js} +0 -0
  438. /package/lib/types/{utils/debug.d.ts → debug.d.ts} +0 -0
@@ -0,0 +1,804 @@
1
+ import { ColliderType } from './colliders';
2
+ // =====================================================================================
3
+ // Utilities (scalar-only, no allocations at runtime)
4
+ // =====================================================================================
5
+ const abs = (v) => (v < 0 ? -v : v);
6
+ // =====================================================================================
7
+ // OBB helpers (scalar-only)
8
+ // =====================================================================================
9
+ function obbRadiusOnAxis(Lx, Ly, ux, uy, vx, vy, hx, hy) {
10
+ // hx, hy must be >= 0; project axis onto OBB's local axes and scale by half extents.
11
+ const Lu = Lx * ux + Ly * uy;
12
+ const Lv = Lx * vx + Ly * vy;
13
+ const a = hx * (Lu < 0 ? -Lu : Lu);
14
+ const b = hy * (Lv < 0 ? -Lv : Lv);
15
+ return a + b;
16
+ }
17
+ function axisSeparates(Lx, Ly, dx, dy, aux, auy, avx, avy, ahx, ahy, bux, buy, bvx, bvy, bhx, bhy) {
18
+ const dist = dx * Lx + dy * Ly;
19
+ const ad = dist < 0 ? -dist : dist;
20
+ const rA = obbRadiusOnAxis(Lx, Ly, aux, auy, avx, avy, ahx, ahy);
21
+ const rB = obbRadiusOnAxis(Lx, Ly, bux, buy, bvx, bvy, bhx, bhy);
22
+ return ad > (rA + rB);
23
+ }
24
+ // =====================================================================================
25
+ // Rectangle–Rectangle (OBB–OBB) — SAT with 4 axes (no allocations)
26
+ // =====================================================================================
27
+ function checkRectRectCollision(ca, ta, cb, tb) {
28
+ // A frame (half extents must be non-negative)
29
+ const asx = ta.scaleX.v, asy = ta.scaleY.v;
30
+ const ahx = abs(ca.width * asx) * 0.5;
31
+ const ahy = abs(ca.height * asy) * 0.5;
32
+ const cA = ta.rotation.cos, sA = ta.rotation.sin;
33
+ const aux = cA, auy = sA;
34
+ const avx = -sA, avy = cA;
35
+ // apply rotated local offset for center
36
+ const aox = (ca.x || 0) * asx;
37
+ const aoy = (ca.y || 0) * asy;
38
+ const ax = ta.x.v + aux * aox + avx * aoy;
39
+ const ay = ta.y.v + auy * aox + avy * aoy;
40
+ // B frame
41
+ const bsx = tb.scaleX.v, bsy = tb.scaleY.v;
42
+ const bhx = abs(cb.width * bsx) * 0.5;
43
+ const bhy = abs(cb.height * bsy) * 0.5;
44
+ const cB = tb.rotation.cos, sB = tb.rotation.sin;
45
+ const bux = cB, buy = sB;
46
+ const bvx = -sB, bvy = cB;
47
+ const box = (cb.x || 0) * bsx;
48
+ const boy = (cb.y || 0) * bsy;
49
+ const bx = tb.x.v + bux * box + bvx * boy;
50
+ const by = tb.y.v + buy * box + bvy * boy;
51
+ // Fast axis-aligned branch if both rotations are zero
52
+ const rotA = ta.rotation.v, rotB = tb.rotation.v;
53
+ if ((rotA === 0 || rotA === 0.0) && (rotB === 0 || rotB === 0.0)) {
54
+ const dx0 = bx - ax;
55
+ const adx0 = dx0 < 0 ? -dx0 : dx0;
56
+ const dy0 = by - ay;
57
+ const ady0 = dy0 < 0 ? -dy0 : dy0;
58
+ return (adx0 <= ahx + bhx) && (ady0 <= ahy + bhy);
59
+ }
60
+ const dx = bx - ax;
61
+ const dy = by - ay;
62
+ if (axisSeparates(aux, auy, dx, dy, aux, auy, avx, avy, ahx, ahy, bux, buy, bvx, bvy, bhx, bhy))
63
+ return false;
64
+ if (axisSeparates(avx, avy, dx, dy, aux, auy, avx, avy, ahx, ahy, bux, buy, bvx, bvy, bhx, bhy))
65
+ return false;
66
+ if (axisSeparates(bux, buy, dx, dy, aux, auy, avx, avy, ahx, ahy, bux, buy, bvx, bvy, bhx, bhy))
67
+ return false;
68
+ if (axisSeparates(bvx, bvy, dx, dy, aux, auy, avx, avy, ahx, ahy, bux, buy, bvx, bvy, bhx, bhy))
69
+ return false;
70
+ return true;
71
+ }
72
+ // =====================================================================================
73
+ // Circle tools (no allocations)
74
+ // =====================================================================================
75
+ // scratch for circle center computations (reused everywhere; no runtime object creation)
76
+ let _ccx = 0, _ccy = 0;
77
+ // Writes the world-space center into (_ccx, _ccy).
78
+ function circleCenterScratch(c, t) {
79
+ // No object/array allocation; scalar math only
80
+ const sx = t.scaleX.v, sy = t.scaleY.v;
81
+ const cos = t.rotation.cos, sin = t.rotation.sin;
82
+ // local axes
83
+ const ux = cos, uy = sin;
84
+ const vx = -sin, vy = cos;
85
+ // scaled local offset
86
+ const ox = (c.x || 0) * sx;
87
+ const oy = (c.y || 0) * sy;
88
+ _ccx = t.x.v + ux * ox + vx * oy;
89
+ _ccy = t.y.v + uy * ox + vy * oy;
90
+ }
91
+ function circleScaledRadius(c, t) {
92
+ const sx = abs(t.scaleX.v), sy = abs(t.scaleY.v);
93
+ return c.radius * (sx > sy ? sx : sy); // conservative
94
+ }
95
+ function checkCircleCircleCollision(ca, ta, cb, tb) {
96
+ circleCenterScratch(ca, ta);
97
+ const ax = _ccx, ay = _ccy;
98
+ circleCenterScratch(cb, tb);
99
+ const bx = _ccx, by = _ccy;
100
+ const ra = circleScaledRadius(ca, ta);
101
+ const rb = circleScaledRadius(cb, tb);
102
+ const dx = bx - ax, dy = by - ay;
103
+ const r = ra + rb;
104
+ return (dx * dx + dy * dy) <= r * r;
105
+ }
106
+ // =====================================================================================
107
+ // Rect–Circle (no allocations)
108
+ // =====================================================================================
109
+ function checkRectCircleCollision(r, tr, c, tc) {
110
+ // Rect frame
111
+ const rsx = tr.scaleX.v, rsy = tr.scaleY.v;
112
+ const rhx = abs(r.width * rsx) * 0.5;
113
+ const rhy = abs(r.height * rsy) * 0.5;
114
+ const rc = tr.rotation.cos, rs = tr.rotation.sin;
115
+ const rux = rc, ruy = rs;
116
+ const rvx = -rs, rvy = rc;
117
+ const rox = (r.x || 0) * rsx;
118
+ const roy = (r.y || 0) * rsy;
119
+ const rcx = tr.x.v + rux * rox + rvx * roy;
120
+ const rcy = tr.y.v + ruy * rox + rvy * roy;
121
+ // Circle center + radius (into scratch scalars)
122
+ circleCenterScratch(c, tc);
123
+ const rr = circleScaledRadius(c, tc);
124
+ // Project center delta onto rect local axes and clamp
125
+ const dx = _ccx - rcx, dy = _ccy - rcy;
126
+ const qx = dx * rux + dy * ruy;
127
+ const qy = dx * rvx + dy * rvy;
128
+ const clx = qx < -rhx ? -rhx : (qx > rhx ? rhx : qx);
129
+ const cly = qy < -rhy ? -rhy : (qy > rhy ? rhy : qy);
130
+ const ddx = qx - clx;
131
+ const ddy = qy - cly;
132
+ return (ddx * ddx + ddy * ddy) <= rr * rr;
133
+ }
134
+ // =====================================================================================
135
+ // Polygon helpers — SAT (no allocations; polygons are in LOCAL space + Transform)
136
+ // =====================================================================================
137
+ /*
138
+ Notes:
139
+ - Polygons are stored in LOCAL space. We never allocate world-space copies.
140
+ - For any world axis N = (nx, ny), projection of a local vertex (vx, vy) is:
141
+ dot(N, C) + dot(N, U)*sx*vx + dot(N, V)*sy*vy
142
+ where C is world center, U/V are world unit axes of the polygon frame,
143
+ and sx/sy are scale on those local axes.
144
+ - No objects/arrays are created at runtime. Only scalar computations and loops.
145
+ */
146
+ // Poly–Poly (LOCAL + Transform)
147
+ function checkPolyPolyCollision(a, ta, b, tb) {
148
+ const av = a.vertices, bv = b.vertices;
149
+ const na = av.length, nb = bv.length;
150
+ if (na === 0 || nb === 0)
151
+ return false;
152
+ // Frame A
153
+ const asx = ta.scaleX.v, asy = ta.scaleY.v;
154
+ const acs = ta.rotation.cos, asn = ta.rotation.sin;
155
+ const aux = acs, auy = asn;
156
+ const avx = -asn, avy = acs;
157
+ const aox = (a.x || 0) * asx;
158
+ const aoy = (a.y || 0) * asy;
159
+ const acx = ta.x.v + aux * aox + avx * aoy;
160
+ const acy = ta.y.v + auy * aox + avy * aoy;
161
+ // Frame B
162
+ const bsx = tb.scaleX.v, bsy = tb.scaleY.v;
163
+ const bcs = tb.rotation.cos, bsn = tb.rotation.sin;
164
+ const bux = bcs, buy = bsn;
165
+ const bvx = -bsn, bvy = bcs;
166
+ const box = (b.x || 0) * bsx;
167
+ const boy = (b.y || 0) * bsy;
168
+ const bcx = tb.x.v + bux * box + bvx * boy;
169
+ const bcy = tb.y.v + buy * box + bvy * boy;
170
+ let i = 0, j = 0, k = 0;
171
+ // A's edge axes
172
+ for (i = 0; i < na; i++) {
173
+ j = (i + 1) % na;
174
+ const adx = av[j].x - av[i].x;
175
+ const ady = av[j].y - av[i].y;
176
+ // edge in world: Ew = U*(sx*dx) + V*(sy*dy)
177
+ const ewx = aux * (asx * adx) + avx * (asy * ady);
178
+ const ewy = auy * (asx * adx) + avy * (asy * ady);
179
+ const nx = -ewy, ny = ewx; // world normal (no normalization)
180
+ // project A on (nx,ny)
181
+ const kUa = (nx * aux + ny * auy) * asx;
182
+ const kVa = (nx * avx + ny * avy) * asy;
183
+ const baseA = nx * acx + ny * acy;
184
+ let minA = Infinity, maxA = -Infinity;
185
+ for (k = 0; k < na; k++) {
186
+ const s = baseA + kUa * av[k].x + kVa * av[k].y;
187
+ if (s < minA)
188
+ minA = s;
189
+ if (s > maxA)
190
+ maxA = s;
191
+ }
192
+ // project B on (nx,ny)
193
+ const kUb = (nx * bux + ny * buy) * bsx;
194
+ const kVb = (nx * bvx + ny * bvy) * bsy;
195
+ const baseB = nx * bcx + ny * bcy;
196
+ let minB = Infinity, maxB = -Infinity;
197
+ for (k = 0; k < nb; k++) {
198
+ const s = baseB + kUb * bv[k].x + kVb * bv[k].y;
199
+ if (s < minB)
200
+ minB = s;
201
+ if (s > maxB)
202
+ maxB = s;
203
+ }
204
+ if (maxA < minB || maxB < minA)
205
+ return false;
206
+ }
207
+ // B's edge axes
208
+ for (i = 0; i < nb; i++) {
209
+ j = (i + 1) % nb;
210
+ const bdx = bv[j].x - bv[i].x;
211
+ const bdy = bv[j].y - bv[i].y;
212
+ const ewx = bux * (bsx * bdx) + bvx * (bsy * bdy);
213
+ const ewy = buy * (bsx * bdx) + bvy * (bsy * bdy);
214
+ const nx = -ewy, ny = ewx;
215
+ // project A
216
+ const kUa = (nx * aux + ny * auy) * asx;
217
+ const kVa = (nx * avx + ny * avy) * asy;
218
+ const baseA = nx * acx + ny * acy;
219
+ let minA = Infinity, maxA = -Infinity;
220
+ for (k = 0; k < na; k++) {
221
+ const s = baseA + kUa * av[k].x + kVa * av[k].y;
222
+ if (s < minA)
223
+ minA = s;
224
+ if (s > maxA)
225
+ maxA = s;
226
+ }
227
+ // project B
228
+ const kUb = (nx * bux + ny * buy) * bsx;
229
+ const kVb = (nx * bvx + ny * bvy) * bsy;
230
+ const baseB = nx * bcx + ny * bcy;
231
+ let minB = Infinity, maxB = -Infinity;
232
+ for (k = 0; k < nb; k++) {
233
+ const s = baseB + kUb * bv[k].x + kVb * bv[k].y;
234
+ if (s < minB)
235
+ minB = s;
236
+ if (s > maxB)
237
+ maxB = s;
238
+ }
239
+ if (maxA < minB || maxB < minA)
240
+ return false;
241
+ }
242
+ return true;
243
+ }
244
+ // Poly–Circle (LOCAL + Transform)
245
+ function checkPolyCircleCollision(poly, tp, c, tc) {
246
+ const v = poly.vertices;
247
+ const n = v.length;
248
+ if (n === 0)
249
+ return false;
250
+ // Poly frame
251
+ const psx = tp.scaleX.v, psy = tp.scaleY.v;
252
+ const pcs = tp.rotation.cos, psn = tp.rotation.sin;
253
+ const pux = pcs, puy = psn;
254
+ const pvx = -psn, pvy = pcs;
255
+ const pox = (poly.x || 0) * psx;
256
+ const poy = (poly.y || 0) * psy;
257
+ const pcx = tp.x.v + pux * pox + pvx * poy;
258
+ const pcy = tp.y.v + puy * pox + pvy * poy;
259
+ // Circle center + radius
260
+ circleCenterScratch(c, tc);
261
+ const CCx = _ccx, CCy = _ccy;
262
+ const rr = circleScaledRadius(c, tc);
263
+ let i = 0, j = 0, k = 0;
264
+ // (A) Polygon edge axes
265
+ for (i = 0; i < n; i++) {
266
+ j = (i + 1) % n;
267
+ const dx = v[j].x - v[i].x;
268
+ const dy = v[j].y - v[i].y;
269
+ const ewx = pux * (psx * dx) + pvx * (psy * dy);
270
+ const ewy = puy * (psx * dx) + pvy * (psy * dy);
271
+ const nx = -ewy, ny = ewx;
272
+ const kUp = (nx * pux + ny * puy) * psx;
273
+ const kVp = (nx * pvx + ny * pvy) * psy;
274
+ const baseP = nx * pcx + ny * pcy;
275
+ let minP = Infinity, maxP = -Infinity;
276
+ for (k = 0; k < n; k++) {
277
+ const s = baseP + kUp * v[k].x + kVp * v[k].y;
278
+ if (s < minP)
279
+ minP = s;
280
+ if (s > maxP)
281
+ maxP = s;
282
+ }
283
+ const nlen = Math.hypot(nx, ny);
284
+ const cProj = nx * CCx + ny * CCy;
285
+ const minC = cProj - rr * nlen;
286
+ const maxC = cProj + rr * nlen;
287
+ if (maxP < minC || maxC < minP)
288
+ return false;
289
+ }
290
+ // (B) Closest-vertex axis
291
+ let bestDx = 0, bestDy = 0, bestD2 = Infinity;
292
+ for (i = 0; i < n; i++) {
293
+ const wx = pcx + pux * (psx * v[i].x) + pvx * (psy * v[i].y);
294
+ const wy = pcy + puy * (psx * v[i].x) + pvy * (psy * v[i].y);
295
+ const dx = CCx - wx;
296
+ const dy = CCy - wy;
297
+ const d2 = dx * dx + dy * dy;
298
+ if (d2 < bestD2) {
299
+ bestD2 = d2;
300
+ bestDx = dx;
301
+ bestDy = dy;
302
+ }
303
+ }
304
+ if (bestD2 === 0)
305
+ return true;
306
+ {
307
+ const nx = bestDx, ny = bestDy;
308
+ const kUp = (nx * pux + ny * puy) * psx;
309
+ const kVp = (nx * pvx + ny * pvy) * psy;
310
+ const baseP = nx * pcx + ny * pcy;
311
+ let minP = Infinity, maxP = -Infinity;
312
+ for (i = 0; i < n; i++) {
313
+ const s = baseP + kUp * v[i].x + kVp * v[i].y;
314
+ if (s < minP)
315
+ minP = s;
316
+ if (s > maxP)
317
+ maxP = s;
318
+ }
319
+ const nlen = Math.hypot(nx, ny);
320
+ const cProj = nx * CCx + ny * CCy;
321
+ const minC = cProj - rr * nlen;
322
+ const maxC = cProj + rr * nlen;
323
+ if (maxP < minC || maxC < minP)
324
+ return false;
325
+ }
326
+ return true;
327
+ }
328
+ // Poly–Rect (LOCAL + Transform)
329
+ function checkPolyRectCollision(poly, tp, r, tr) {
330
+ const v = poly.vertices;
331
+ const n = v.length;
332
+ if (n === 0)
333
+ return false;
334
+ // Poly frame
335
+ const psx = tp.scaleX.v, psy = tp.scaleY.v;
336
+ const pcs = tp.rotation.cos, psn = tp.rotation.sin;
337
+ const pux = pcs, puy = psn;
338
+ const pvx = -psn, pvy = pcs;
339
+ const pox = (poly.x || 0) * psx;
340
+ const poy = (poly.y || 0) * psy;
341
+ const pcx = tp.x.v + pux * pox + pvx * poy;
342
+ const pcy = tp.y.v + puy * pox + pvy * poy;
343
+ // Rect frame
344
+ const rsx = tr.scaleX.v, rsy = tr.scaleY.v;
345
+ const rhx = abs(r.width * rsx) * 0.5;
346
+ const rhy = abs(r.height * rsy) * 0.5;
347
+ const rc = tr.rotation.cos, rs = tr.rotation.sin;
348
+ const rux = rc, ruy = rs;
349
+ const rvx = -rs, rvy = rc;
350
+ const rox = (r.x || 0) * rsx, roy = (r.y || 0) * rsy;
351
+ const rcx = tr.x.v + rux * rox + rvx * roy;
352
+ const rcy = tr.y.v + ruy * rox + rvy * roy;
353
+ let i = 0, j = 0, k = 0;
354
+ // (A) polygon edge axes
355
+ for (i = 0; i < n; i++) {
356
+ j = (i + 1) % n;
357
+ const dx = v[j].x - v[i].x;
358
+ const dy = v[j].y - v[i].y;
359
+ const ewx = pux * (psx * dx) + pvx * (psy * dy);
360
+ const ewy = puy * (psx * dx) + pvy * (psy * dy);
361
+ const nx = -ewy, ny = ewx;
362
+ // poly projection
363
+ const kUp = (nx * pux + ny * puy) * psx;
364
+ const kVp = (nx * pvx + ny * pvy) * psy;
365
+ const baseP = nx * pcx + ny * pcy;
366
+ let minP = Infinity, maxP = -Infinity;
367
+ for (k = 0; k < n; k++) {
368
+ const s = baseP + kUp * v[k].x + kVp * v[k].y;
369
+ if (s < minP)
370
+ minP = s;
371
+ if (s > maxP)
372
+ maxP = s;
373
+ }
374
+ // rect projection radius on axis
375
+ const nu = nx * rux + ny * ruy;
376
+ const nv = nx * rvx + ny * rvy;
377
+ const rRad = rhx * (nu < 0 ? -nu : nu) + rhy * (nv < 0 ? -nv : nv);
378
+ const cProj = nx * rcx + ny * rcy;
379
+ const minR = cProj - rRad;
380
+ const maxR = cProj + rRad;
381
+ if (maxP < minR || maxR < minP)
382
+ return false;
383
+ }
384
+ // (B) rect axis u
385
+ {
386
+ const nx = rux, ny = ruy;
387
+ const kUp = (nx * pux + ny * puy) * psx;
388
+ const kVp = (nx * pvx + ny * pvy) * psy;
389
+ const baseP = nx * pcx + ny * pcy;
390
+ let minP = Infinity, maxP = -Infinity;
391
+ for (i = 0; i < n; i++) {
392
+ const s = baseP + kUp * v[i].x + kVp * v[i].y;
393
+ if (s < minP)
394
+ minP = s;
395
+ if (s > maxP)
396
+ maxP = s;
397
+ }
398
+ const cProj = nx * rcx + ny * rcy;
399
+ const minR = cProj - rhx;
400
+ const maxR = cProj + rhx;
401
+ if (maxP < minR || maxR < minP)
402
+ return false;
403
+ }
404
+ // (C) rect axis v
405
+ {
406
+ const nx = rvx, ny = rvy;
407
+ const kUp = (nx * pux + ny * puy) * psx;
408
+ const kVp = (nx * pvx + ny * pvy) * psy;
409
+ const baseP = nx * pcx + ny * pcy;
410
+ let minP = Infinity, maxP = -Infinity;
411
+ for (i = 0; i < n; i++) {
412
+ const s = baseP + kUp * v[i].x + kVp * v[i].y;
413
+ if (s < minP)
414
+ minP = s;
415
+ if (s > maxP)
416
+ maxP = s;
417
+ }
418
+ const cProj = nx * rcx + ny * rcy;
419
+ const minR = cProj - rhy;
420
+ const maxR = cProj + rhy;
421
+ if (maxP < minR || maxR < minP)
422
+ return false;
423
+ }
424
+ return true;
425
+ }
426
+ // =====================================================================================
427
+ // GJK (no allocations: global scratch + selectable supports) — FIXED/ROBUST
428
+ // =====================================================================================
429
+ // Global scratch for support result
430
+ let _sx = 0, _sy = 0;
431
+ // Support selectors
432
+ var SupportType;
433
+ (function (SupportType) {
434
+ SupportType[SupportType["None"] = 0] = "None";
435
+ SupportType[SupportType["Ellipse"] = 1] = "Ellipse";
436
+ SupportType[SupportType["OBB"] = 2] = "OBB";
437
+ SupportType[SupportType["Circle"] = 3] = "Circle";
438
+ SupportType[SupportType["Poly"] = 4] = "Poly";
439
+ SupportType[SupportType["PolyLocal"] = 5] = "PolyLocal";
440
+ })(SupportType || (SupportType = {}));
441
+ let _supportAType = 0 /* SupportType.None */;
442
+ let _supportBType = 0 /* SupportType.None */;
443
+ // A-shape params
444
+ let _Acx = 0, _Acy = 0, _Aux = 0, _Auy = 0, _Avx = 0, _Avy = 0, _Arx = 0, _Ary = 0, _Ahx = 0, _Ahy = 0, _Arr = 0;
445
+ let _Apoly = null;
446
+ // B-shape params
447
+ let _Bcx = 0, _Bcy = 0, _Bux = 0, _Buy = 0, _Bvx = 0, _Bvy = 0, _Brx = 0, _Bry = 0, _Bhx = 0, _Bhy = 0, _Brr = 0;
448
+ let _Bpoly = null;
449
+ function setSupportCircle(dx, dy, cx, cy, r) {
450
+ const len = Math.hypot(dx, dy);
451
+ if (len === 0) {
452
+ _sx = cx;
453
+ _sy = cy;
454
+ return;
455
+ }
456
+ const inv = 1 / len;
457
+ _sx = cx + dx * inv * r;
458
+ _sy = cy + dy * inv * r;
459
+ }
460
+ function setSupportOBB(dx, dy, cx, cy, ux, uy, vx, vy, hx, hy) {
461
+ const du = dx * ux + dy * uy;
462
+ const dv = dx * vx + dy * vy;
463
+ const sx = du >= 0 ? 1 : -1;
464
+ const sy = dv >= 0 ? 1 : -1;
465
+ _sx = cx + ux * hx * sx + vx * hy * sy;
466
+ _sy = cy + uy * hx * sx + vy * hy * sy;
467
+ }
468
+ function dvDy(dy, a) { return dy * a; } // tiny inline helper (prevents temp vars)
469
+ function setSupportEllipse(dx, dy, cx, cy, ux, uy, vx, vy, rx, ry) {
470
+ const du = dx * ux + dvDy(dy, uy);
471
+ const dv = dx * vx + dvDy(dy, vy);
472
+ const denom = Math.hypot(rx * du, ry * dv);
473
+ if (denom === 0) {
474
+ _sx = cx;
475
+ _sy = cy;
476
+ return;
477
+ }
478
+ const kU = (rx * rx * du) / denom;
479
+ const kV = (ry * ry * dv) / denom;
480
+ _sx = cx + kU * ux + kV * vx;
481
+ _sy = cy + kU * uy + kV * vy;
482
+ }
483
+ function setSupportPoly(dx, dy, verts) {
484
+ let best = 0, bestDot = -Infinity;
485
+ for (let i = 0, n = verts.length; i < n; i++) {
486
+ const vx = verts[i].x, vy = verts[i].y;
487
+ const d = dx * vx + dy * vy;
488
+ if (d > bestDot) {
489
+ bestDot = d;
490
+ best = i;
491
+ }
492
+ }
493
+ _sx = verts[best].x;
494
+ _sy = verts[best].y;
495
+ }
496
+ // PolyLocal support: verts in LOCAL, with frame (cx,cy, U/V, sx/sy)
497
+ function setSupportPolyLocal(dx, dy, verts, cx, cy, ux, uy, vx, vy, sx, sy) {
498
+ const kU = (dx * ux + dy * uy) * sx;
499
+ const kV = (dx * vx + dy * vy) * sy;
500
+ let best = 0, bestDot = -Infinity;
501
+ for (let i = 0, n = verts.length; i < n; i++) {
502
+ const s = kU * verts[i].x + kV * verts[i].y;
503
+ if (s > bestDot) {
504
+ bestDot = s;
505
+ best = i;
506
+ }
507
+ }
508
+ const lx = verts[best].x, ly = verts[best].y;
509
+ _sx = cx + ux * (sx * lx) + vx * (sy * ly);
510
+ _sy = cy + uy * (sx * lx) + vy * (sy * ly);
511
+ }
512
+ function supportA(dx, dy) {
513
+ if (_supportAType === 1 /* SupportType.Ellipse */)
514
+ setSupportEllipse(dx, dy, _Acx, _Acy, _Aux, _Auy, _Avx, _Avy, _Arx, _Ary);
515
+ else if (_supportAType === 2 /* SupportType.OBB */)
516
+ setSupportOBB(dx, dy, _Acx, _Acy, _Aux, _Auy, _Avx, _Avy, _Ahx, _Ahy);
517
+ else if (_supportAType === 3 /* SupportType.Circle */)
518
+ setSupportCircle(dx, dy, _Acx, _Acy, _Arr);
519
+ else if (_supportAType === 4 /* SupportType.Poly */)
520
+ setSupportPoly(dx, dy, _Apoly);
521
+ else if (_supportAType === 5 /* SupportType.PolyLocal */)
522
+ setSupportPolyLocal(dx, dy, _Apoly, _Acx, _Acy, _Aux, _Auy, _Avx, _Avy, _Arx, _Ary);
523
+ else {
524
+ _sx = 0;
525
+ _sy = 0;
526
+ }
527
+ }
528
+ function supportB(dx, dy) {
529
+ if (_supportBType === 1 /* SupportType.Ellipse */)
530
+ setSupportEllipse(dx, dy, _Bcx, _Bcy, _Bux, _Buy, _Bvx, _Bvy, _Brx, _Bry);
531
+ else if (_supportBType === 2 /* SupportType.OBB */)
532
+ setSupportOBB(dx, dy, _Bcx, _Bcy, _Bux, _Buy, _Bvx, _Bvy, _Bhx, _Bhy);
533
+ else if (_supportBType === 3 /* SupportType.Circle */)
534
+ setSupportCircle(dx, dy, _Bcx, _Bcy, _Brr);
535
+ else if (_supportBType === 4 /* SupportType.Poly */)
536
+ setSupportPoly(dx, dy, _Bpoly);
537
+ else if (_supportBType === 5 /* SupportType.PolyLocal */)
538
+ setSupportPolyLocal(dx, dy, _Bpoly, _Bcx, _Bcy, _Bux, _Buy, _Bvx, _Bvy, _Brx, _Bry);
539
+ else {
540
+ _sx = 0;
541
+ _sy = 0;
542
+ }
543
+ }
544
+ // GJK core — returns true if intersection (robust; no allocations)
545
+ function gjkIntersectsNoAlloc() {
546
+ // EPS guards degenerate directions/points
547
+ const EPS = 1e-9;
548
+ const EPS2 = EPS * EPS;
549
+ // simplex points (A = most recently added)
550
+ let ax = 0, ay = 0, bx = 0, by = 0, cx = 0, cy = 0;
551
+ let n = 0;
552
+ // search direction
553
+ let dx = 1, dy = 0;
554
+ // Adds a new support point as A and shifts previous (C<-B, B<-A)
555
+ function addPointAsA() {
556
+ supportA(dx, dy);
557
+ const pax = _sx, pay = _sy;
558
+ supportB(-dx, -dy);
559
+ const pbx = _sx, pby = _sy;
560
+ const px = pax - pbx, py = pay - pby;
561
+ cx = bx;
562
+ cy = by;
563
+ bx = ax;
564
+ by = ay;
565
+ ax = px;
566
+ ay = py;
567
+ if (n < 3)
568
+ n++;
569
+ }
570
+ addPointAsA();
571
+ if (ax * ax + ay * ay <= EPS2)
572
+ return true; // origin exactly (or ~) hit
573
+ dx = -ax;
574
+ dy = -ay;
575
+ for (let iter = 0; iter < 32; iter++) {
576
+ const dLen2 = dx * dx + dy * dy;
577
+ if (dLen2 <= EPS2)
578
+ return true; // direction collapsed → enclosed
579
+ addPointAsA();
580
+ // If new point A does not pass beyond origin along d, shapes are separated
581
+ const Ad = ax * dx + ay * dy;
582
+ if (Ad <= 0)
583
+ return false;
584
+ if (ax * ax + ay * ay <= EPS2)
585
+ return true;
586
+ if (n === 2) {
587
+ // Segment (B-A). Use triple product to get perpendicular toward origin: d = triple(AB, AO, AB)
588
+ const abx = bx - ax, aby = by - ay;
589
+ const aox = -ax, aoy = -ay;
590
+ const ac = abx * abx + aby * aby; // (AB·AB)
591
+ const bc = aox * abx + aoy * aby; // (AO·AB)
592
+ dx = aox * ac - abx * bc; // AO*(AB·AB) - AB*(AO·AB)
593
+ dy = aoy * ac - aby * bc;
594
+ continue;
595
+ }
596
+ // Triangle (C-B-A), A is the latest point
597
+ const abx = bx - ax, aby = by - ay;
598
+ const acx = cx - ax, acy = cy - ay;
599
+ const aox = -ax, aoy = -ay;
600
+ // abPerp = triple(AC, AO, AB)
601
+ const ac_ab = acx * abx + acy * aby; // (AC·AB)
602
+ const ao_ab = aox * abx + aoy * aby; // (AO·AB)
603
+ let t1x = aox * ac_ab - acx * ao_ab;
604
+ let t1y = aoy * ac_ab - acy * ao_ab;
605
+ if (t1x * aox + t1y * aoy > 0) {
606
+ // Origin is in the AB region: drop C -> segment(B-A)
607
+ cx = bx;
608
+ cy = by;
609
+ n = 2;
610
+ dx = t1x;
611
+ dy = t1y;
612
+ continue;
613
+ }
614
+ // acPerp = triple(AB, AO, AC)
615
+ const ab_ac = abx * acx + aby * acy; // (AB·AC)
616
+ const ao_ac = aox * acx + aoy * acy; // (AO·AC)
617
+ let t2x = aox * ab_ac - abx * ao_ac;
618
+ let t2y = aoy * ab_ac - aby * ao_ac;
619
+ if (t2x * aox + t2y * aoy > 0) {
620
+ // Origin is in the AC region: drop B -> segment(C-A)
621
+ bx = cx;
622
+ by = cy;
623
+ n = 2;
624
+ dx = t2x;
625
+ dy = t2y;
626
+ continue;
627
+ }
628
+ // Origin is inside triangle
629
+ return true;
630
+ }
631
+ // Conservative fallback
632
+ return false;
633
+ }
634
+ // =====================================================================================
635
+ // Ellipse interactions via GJK (no allocations)
636
+ // =====================================================================================
637
+ function checkEllipseRectCollision(e, te, r, tr) {
638
+ // A = Ellipse
639
+ const esx = te.scaleX.v, esy = te.scaleY.v;
640
+ _Arx = abs(e.width * esx) * 0.5;
641
+ _Ary = abs(e.height * esy) * 0.5;
642
+ const ecs = te.rotation.cos, esn = te.rotation.sin;
643
+ _Aux = ecs;
644
+ _Auy = esn;
645
+ _Avx = -esn;
646
+ _Avy = ecs;
647
+ const eox = (e.x || 0) * esx, eoy = (e.y || 0) * esy;
648
+ _Acx = te.x.v + _Aux * eox + _Avx * eoy;
649
+ _Acy = te.y.v + _Auy * eox + _Avy * eoy;
650
+ _supportAType = 1 /* SupportType.Ellipse */;
651
+ _Apoly = null;
652
+ // B = OBB (rect)
653
+ const rsx = tr.scaleX.v, rsy = tr.scaleY.v;
654
+ _Bhx = abs(r.width * rsx) * 0.5;
655
+ _Bhy = abs(r.height * rsy) * 0.5;
656
+ const rcs = tr.rotation.cos, rsn = tr.rotation.sin;
657
+ _Bux = rcs;
658
+ _Buy = rsn;
659
+ _Bvx = -rsn;
660
+ _Bvy = rcs;
661
+ const rox = (r.x || 0) * rsx, roy = (r.y || 0) * rsy;
662
+ _Bcx = tr.x.v + _Bux * rox + _Bvx * roy;
663
+ _Bcy = tr.y.v + _Buy * rox + _Bvy * roy;
664
+ _supportBType = 2 /* SupportType.OBB */;
665
+ _Bpoly = null;
666
+ return gjkIntersectsNoAlloc();
667
+ }
668
+ function checkEllipseCircleCollision(e, te, c, tc) {
669
+ // A = Ellipse
670
+ const esx = te.scaleX.v, esy = te.scaleY.v;
671
+ _Arx = abs(e.width * esx) * 0.5;
672
+ _Ary = abs(e.height * esy) * 0.5;
673
+ const ecs = te.rotation.cos, esn = te.rotation.sin;
674
+ _Aux = ecs;
675
+ _Auy = esn;
676
+ _Avx = -esn;
677
+ _Avy = ecs;
678
+ const eox = (e.x || 0) * esx, eoy = (e.y || 0) * esy;
679
+ _Acx = te.x.v + _Aux * eox + _Avx * eoy;
680
+ _Acy = te.y.v + _Auy * eox + _Avy * eoy;
681
+ _supportAType = 1 /* SupportType.Ellipse */;
682
+ _Apoly = null;
683
+ // B = Circle
684
+ circleCenterScratch(c, tc);
685
+ _Bcx = _ccx;
686
+ _Bcy = _ccy;
687
+ _Brr = circleScaledRadius(c, tc);
688
+ _supportBType = 3 /* SupportType.Circle */;
689
+ _Bpoly = null;
690
+ return gjkIntersectsNoAlloc();
691
+ }
692
+ function checkEllipseEllipseCollision(a, ta, b, tb) {
693
+ // A
694
+ const asx = ta.scaleX.v, asy = ta.scaleY.v;
695
+ _Arx = abs(a.width * asx) * 0.5;
696
+ _Ary = abs(a.height * asy) * 0.5;
697
+ const acs = ta.rotation.cos, asn = ta.rotation.sin;
698
+ _Aux = acs;
699
+ _Auy = asn;
700
+ _Avx = -asn;
701
+ _Avy = acs;
702
+ const aox = (a.x || 0) * asx, aoy = (a.y || 0) * asy;
703
+ _Acx = ta.x.v + _Aux * aox + _Avx * aoy;
704
+ _Acy = ta.y.v + _Auy * aox + _Avy * aoy;
705
+ _supportAType = 1 /* SupportType.Ellipse */;
706
+ _Apoly = null;
707
+ // B
708
+ const bsx = tb.scaleX.v, bsy = tb.scaleY.v;
709
+ _Brx = abs(b.width * bsx) * 0.5;
710
+ _Bry = abs(b.height * bsy) * 0.5;
711
+ const bcs = tb.rotation.cos, bsn = tb.rotation.sin;
712
+ _Bux = bcs;
713
+ _Buy = bsn;
714
+ _Bvx = -bsn;
715
+ _Bvy = bcs;
716
+ const box = (b.x || 0) * bsx, boy = (b.y || 0) * bsy;
717
+ _Bcx = tb.x.v + _Bux * box + _Bvx * boy;
718
+ _Bcy = tb.y.v + _Buy * box + _Bvy * boy;
719
+ _supportBType = 1 /* SupportType.Ellipse */;
720
+ _Bpoly = null;
721
+ return gjkIntersectsNoAlloc();
722
+ }
723
+ // Poly–Ellipse via GJK (Poly in LOCAL + Transform, Ellipse in LOCAL + Transform)
724
+ function checkPolyEllipseCollision(poly, tp, e, te) {
725
+ // A = Poly (LOCAL + Transform) → use PolyLocal support; reuse A scratch slots
726
+ const psx = tp.scaleX.v, psy = tp.scaleY.v;
727
+ const pcs = tp.rotation.cos, psn = tp.rotation.sin;
728
+ const pux = pcs, puy = psn;
729
+ const pvx = -psn, pvy = pcs;
730
+ const pox = (poly.x || 0) * psx;
731
+ const poy = (poly.y || 0) * psy;
732
+ _Acx = tp.x.v + pux * pox + pvx * poy;
733
+ _Acy = tp.y.v + puy * pox + pvy * poy;
734
+ _Aux = pux;
735
+ _Auy = puy;
736
+ _Avx = pvx;
737
+ _Avy = pvy;
738
+ _Arx = psx;
739
+ _Ary = psy;
740
+ _Apoly = poly.vertices;
741
+ _supportAType = 5 /* SupportType.PolyLocal */;
742
+ // B = Ellipse
743
+ const esx = te.scaleX.v, esy = te.scaleY.v;
744
+ _Brx = abs(e.width * esx) * 0.5;
745
+ _Bry = abs(e.height * esy) * 0.5;
746
+ const ecs = te.rotation.cos, esn = te.rotation.sin;
747
+ _Bux = ecs;
748
+ _Buy = esn;
749
+ _Bvx = -esn;
750
+ _Bvy = ecs;
751
+ const eox = (e.x || 0) * esx, eoy = (e.y || 0) * esy;
752
+ _Bcx = te.x.v + _Bux * eox + _Bvx * eoy;
753
+ _Bcy = te.y.v + _Buy * eox + _Bvy * eoy;
754
+ _Bpoly = null;
755
+ _supportBType = 1 /* SupportType.Ellipse */;
756
+ return gjkIntersectsNoAlloc();
757
+ }
758
+ // =====================================================================================
759
+ // Dispatcher (no allocations)
760
+ // =====================================================================================
761
+ export function checkCollision(ca, ta, cb, tb) {
762
+ // Rectangle–Rectangle
763
+ if (ca.type === ColliderType.Rectangle && cb.type === ColliderType.Rectangle)
764
+ return checkRectRectCollision(ca, ta, cb, tb);
765
+ // Circle–Circle
766
+ if (ca.type === ColliderType.Circle && cb.type === ColliderType.Circle)
767
+ return checkCircleCircleCollision(ca, ta, cb, tb);
768
+ // Rect–Circle (both orders)
769
+ if (ca.type === ColliderType.Rectangle && cb.type === ColliderType.Circle)
770
+ return checkRectCircleCollision(ca, ta, cb, tb);
771
+ if (ca.type === ColliderType.Circle && cb.type === ColliderType.Rectangle)
772
+ return checkRectCircleCollision(cb, tb, ca, ta);
773
+ // Polygon–Polygon (LOCAL + Transform)
774
+ if (ca.type === ColliderType.Polygon && cb.type === ColliderType.Polygon)
775
+ return checkPolyPolyCollision(ca, ta, cb, tb);
776
+ // Polygon–Circle (both orders; LOCAL + Transform for polygon)
777
+ if (ca.type === ColliderType.Polygon && cb.type === ColliderType.Circle)
778
+ return checkPolyCircleCollision(ca, ta, cb, tb);
779
+ if (ca.type === ColliderType.Circle && cb.type === ColliderType.Polygon)
780
+ return checkPolyCircleCollision(cb, tb, ca, ta);
781
+ // Polygon–Rect (both orders; LOCAL + Transform for polygon)
782
+ if (ca.type === ColliderType.Polygon && cb.type === ColliderType.Rectangle)
783
+ return checkPolyRectCollision(ca, ta, cb, tb);
784
+ if (ca.type === ColliderType.Rectangle && cb.type === ColliderType.Polygon)
785
+ return checkPolyRectCollision(cb, tb, ca, ta);
786
+ // Ellipse interactions via GJK
787
+ if (ca.type === ColliderType.Ellipse && cb.type === ColliderType.Rectangle)
788
+ return checkEllipseRectCollision(ca, ta, cb, tb);
789
+ if (ca.type === ColliderType.Rectangle && cb.type === ColliderType.Ellipse)
790
+ return checkEllipseRectCollision(cb, tb, ca, ta);
791
+ if (ca.type === ColliderType.Ellipse && cb.type === ColliderType.Circle)
792
+ return checkEllipseCircleCollision(ca, ta, cb, tb);
793
+ if (ca.type === ColliderType.Circle && cb.type === ColliderType.Ellipse)
794
+ return checkEllipseCircleCollision(cb, tb, ca, ta);
795
+ if (ca.type === ColliderType.Ellipse && cb.type === ColliderType.Ellipse)
796
+ return checkEllipseEllipseCollision(ca, ta, cb, tb);
797
+ // Polygon–Ellipse (both orders; polygon is LOCAL + Transform via PolyLocal support)
798
+ if (ca.type === ColliderType.Polygon && cb.type === ColliderType.Ellipse)
799
+ return checkPolyEllipseCollision(ca, ta, cb, tb);
800
+ if (ca.type === ColliderType.Ellipse && cb.type === ColliderType.Polygon)
801
+ return checkPolyEllipseCollision(cb, tb, ca, ta);
802
+ return false;
803
+ }
804
+ //# sourceMappingURL=check-collision.js.map