kiwiengine 0.0.1-alpha → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ko.md +550 -0
- package/README.md +575 -4
- package/examples/auto-battle/assets/bgm/battle.mp3 +0 -0
- package/examples/auto-battle/assets/bitmap-fonts/white-peaberry.fnt +107 -0
- package/examples/auto-battle/assets/bitmap-fonts/white-peaberry.png +0 -0
- package/examples/auto-battle/assets/joystick/joystick.png +0 -0
- package/examples/auto-battle/assets/joystick/knob.png +0 -0
- package/examples/auto-battle/assets/sfx/hero/die/die.wav +0 -0
- package/examples/auto-battle/assets/sfx/hero/heal/heal.wav +0 -0
- package/examples/auto-battle/assets/sfx/hero/hit/hit1.wav +0 -0
- package/examples/auto-battle/assets/sfx/hero/hit/hit2.wav +0 -0
- package/examples/auto-battle/assets/sfx/hero/hit/hit3.wav +0 -0
- package/examples/auto-battle/assets/sfx/hero/miss/miss1.wav +0 -0
- package/examples/auto-battle/assets/sfx/hero/miss/miss2.wav +0 -0
- package/examples/auto-battle/assets/sfx/hero/miss/miss3.wav +0 -0
- package/examples/auto-battle/assets/sfx/orc/die/die.wav +0 -0
- package/examples/auto-battle/assets/sfx/orc/hit/hit1.wav +0 -0
- package/examples/auto-battle/assets/sfx/orc/hit/hit2.wav +0 -0
- package/examples/auto-battle/assets/sfx/orc/hit/hit3.wav +0 -0
- package/examples/auto-battle/assets/sfx/orc/miss/miss1.wav +0 -0
- package/examples/auto-battle/assets/sfx/orc/miss/miss2.wav +0 -0
- package/examples/auto-battle/assets/sfx/orc/miss/miss3.wav +0 -0
- package/examples/auto-battle/assets/spritesheets/hero-atlas.json +246 -0
- package/examples/auto-battle/assets/spritesheets/hero.png +0 -0
- package/examples/auto-battle/assets/spritesheets/orc-atlas.json +246 -0
- package/examples/auto-battle/assets/spritesheets/orc.png +0 -0
- package/examples/auto-battle/assets/spritesheets/potion-atlas.json +68 -0
- package/examples/auto-battle/assets/spritesheets/potion.png +0 -0
- package/examples/auto-battle/dist/game.js +2 -0
- package/examples/auto-battle/dist/game.js.LICENSE.txt +35 -0
- package/examples/auto-battle/hud/damage-text.ts +46 -0
- package/examples/auto-battle/hud/heal-text.ts +46 -0
- package/examples/auto-battle/hud/hp-bar.ts +38 -0
- package/examples/auto-battle/index.ts +41 -0
- package/examples/auto-battle/objects/character.ts +95 -0
- package/examples/auto-battle/objects/hero.ts +119 -0
- package/examples/auto-battle/objects/orc.ts +107 -0
- package/examples/auto-battle/objects/potion.ts +27 -0
- package/examples/auto-battle/stage.ts +366 -0
- package/examples/battle-benchmark-matterjs/assets/bgm/battle.mp3 +0 -0
- package/examples/battle-benchmark-matterjs/assets/bitmap-fonts/white-peaberry.fnt +107 -0
- package/examples/battle-benchmark-matterjs/assets/bitmap-fonts/white-peaberry.png +0 -0
- package/examples/battle-benchmark-matterjs/assets/joystick/joystick.png +0 -0
- package/examples/battle-benchmark-matterjs/assets/joystick/knob.png +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/hero/die/die.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/hero/heal/heal.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/hero/hit/hit1.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/hero/hit/hit2.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/hero/hit/hit3.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/hero/miss/miss1.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/hero/miss/miss2.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/hero/miss/miss3.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/orc/die/die.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/orc/hit/hit1.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/orc/hit/hit2.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/orc/hit/hit3.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/orc/miss/miss1.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/orc/miss/miss2.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/orc/miss/miss3.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/spritesheets/hero-atlas.json +246 -0
- package/examples/battle-benchmark-matterjs/assets/spritesheets/hero.png +0 -0
- package/examples/battle-benchmark-matterjs/assets/spritesheets/orc-atlas.json +246 -0
- package/examples/battle-benchmark-matterjs/assets/spritesheets/orc.png +0 -0
- package/examples/battle-benchmark-matterjs/assets/spritesheets/potion-atlas.json +68 -0
- package/examples/battle-benchmark-matterjs/assets/spritesheets/potion.png +0 -0
- package/examples/battle-benchmark-matterjs/dist/game.js +2 -0
- package/examples/battle-benchmark-matterjs/dist/game.js.LICENSE.txt +35 -0
- package/examples/battle-benchmark-matterjs/hud/damage-text.ts +46 -0
- package/examples/battle-benchmark-matterjs/hud/heal-text.ts +46 -0
- package/examples/battle-benchmark-matterjs/hud/hp-bar.ts +38 -0
- package/examples/battle-benchmark-matterjs/index.html +24 -0
- package/examples/battle-benchmark-matterjs/index.ts +41 -0
- package/examples/battle-benchmark-matterjs/objects/character.ts +95 -0
- package/examples/battle-benchmark-matterjs/objects/hero.ts +111 -0
- package/examples/battle-benchmark-matterjs/objects/orc.ts +107 -0
- package/examples/battle-benchmark-matterjs/objects/potion.ts +27 -0
- package/examples/battle-benchmark-matterjs/stage.ts +177 -0
- package/examples/battle-benchmark-separation/assets/bgm/battle.mp3 +0 -0
- package/examples/battle-benchmark-separation/assets/bitmap-fonts/white-peaberry.fnt +107 -0
- package/examples/battle-benchmark-separation/assets/bitmap-fonts/white-peaberry.png +0 -0
- package/examples/battle-benchmark-separation/assets/joystick/joystick.png +0 -0
- package/examples/battle-benchmark-separation/assets/joystick/knob.png +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/hero/die/die.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/hero/heal/heal.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/hero/hit/hit1.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/hero/hit/hit2.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/hero/hit/hit3.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/hero/miss/miss1.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/hero/miss/miss2.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/hero/miss/miss3.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/orc/die/die.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/orc/hit/hit1.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/orc/hit/hit2.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/orc/hit/hit3.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/orc/miss/miss1.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/orc/miss/miss2.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/orc/miss/miss3.wav +0 -0
- package/examples/battle-benchmark-separation/assets/spritesheets/hero-atlas.json +246 -0
- package/examples/battle-benchmark-separation/assets/spritesheets/hero.png +0 -0
- package/examples/battle-benchmark-separation/assets/spritesheets/orc-atlas.json +246 -0
- package/examples/battle-benchmark-separation/assets/spritesheets/orc.png +0 -0
- package/examples/battle-benchmark-separation/assets/spritesheets/potion-atlas.json +68 -0
- package/examples/battle-benchmark-separation/assets/spritesheets/potion.png +0 -0
- package/examples/battle-benchmark-separation/dist/game.js +2 -0
- package/examples/battle-benchmark-separation/dist/game.js.LICENSE.txt +35 -0
- package/examples/battle-benchmark-separation/hud/damage-text.ts +46 -0
- package/examples/battle-benchmark-separation/hud/heal-text.ts +46 -0
- package/examples/battle-benchmark-separation/hud/hp-bar.ts +38 -0
- package/examples/battle-benchmark-separation/index.html +24 -0
- package/examples/battle-benchmark-separation/index.ts +41 -0
- package/examples/battle-benchmark-separation/objects/character.ts +225 -0
- package/examples/battle-benchmark-separation/objects/hero.ts +110 -0
- package/examples/battle-benchmark-separation/objects/orc.ts +213 -0
- package/examples/battle-benchmark-separation/objects/potion.ts +27 -0
- package/examples/battle-benchmark-separation/stage.ts +178 -0
- package/examples/battle-benchmark-separation2/assets/bgm/battle.mp3 +0 -0
- package/examples/battle-benchmark-separation2/assets/bitmap-fonts/white-peaberry.fnt +107 -0
- package/examples/battle-benchmark-separation2/assets/bitmap-fonts/white-peaberry.png +0 -0
- package/examples/battle-benchmark-separation2/assets/joystick/joystick.png +0 -0
- package/examples/battle-benchmark-separation2/assets/joystick/knob.png +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/hero/die/die.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/hero/heal/heal.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/hero/hit/hit1.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/hero/hit/hit2.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/hero/hit/hit3.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/hero/miss/miss1.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/hero/miss/miss2.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/hero/miss/miss3.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/orc/die/die.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/orc/hit/hit1.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/orc/hit/hit2.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/orc/hit/hit3.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/orc/miss/miss1.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/orc/miss/miss2.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/orc/miss/miss3.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/spritesheets/hero-atlas.json +246 -0
- package/examples/battle-benchmark-separation2/assets/spritesheets/hero.png +0 -0
- package/examples/battle-benchmark-separation2/assets/spritesheets/orc-atlas.json +246 -0
- package/examples/battle-benchmark-separation2/assets/spritesheets/orc.png +0 -0
- package/examples/battle-benchmark-separation2/assets/spritesheets/potion-atlas.json +68 -0
- package/examples/battle-benchmark-separation2/assets/spritesheets/potion.png +0 -0
- package/examples/battle-benchmark-separation2/dist/game.js +2 -0
- package/examples/battle-benchmark-separation2/dist/game.js.LICENSE.txt +35 -0
- package/examples/battle-benchmark-separation2/hud/damage-text.ts +46 -0
- package/examples/battle-benchmark-separation2/hud/heal-text.ts +46 -0
- package/examples/battle-benchmark-separation2/hud/hp-bar.ts +38 -0
- package/examples/battle-benchmark-separation2/index.html +24 -0
- package/examples/battle-benchmark-separation2/index.ts +41 -0
- package/examples/battle-benchmark-separation2/objects/character.ts +195 -0
- package/examples/battle-benchmark-separation2/objects/hero.ts +110 -0
- package/examples/battle-benchmark-separation2/objects/orc.ts +213 -0
- package/examples/battle-benchmark-separation2/objects/potion.ts +27 -0
- package/examples/battle-benchmark-separation2/stage.ts +178 -0
- package/examples/collision-test/assets/cat.png +0 -0
- package/examples/collision-test/dist/game.js +2 -0
- package/examples/collision-test/dist/game.js.LICENSE.txt +35 -0
- package/examples/collision-test/index.html +24 -0
- package/examples/collision-test/index.ts +30 -0
- package/examples/dom-particle-test/assets/bird.png +0 -0
- package/examples/dom-particle-test/dist/game.js +2 -0
- package/examples/dom-particle-test/dist/game.js.LICENSE.txt +35 -0
- package/examples/dom-particle-test/index.html +24 -0
- package/examples/dom-particle-test/index.ts +27 -0
- package/examples/dom-sprite-test/assets/bird.png +0 -0
- package/examples/dom-sprite-test/assets/fire.png +0 -0
- package/examples/dom-sprite-test/assets/run.png +0 -0
- package/examples/dom-sprite-test/dist/game.js +2 -0
- package/examples/dom-sprite-test/dist/game.js.LICENSE.txt +35 -0
- package/examples/dom-sprite-test/index.html +24 -0
- package/examples/dom-sprite-test/index.ts +35 -0
- package/examples/dom-test/dist/game.js +2 -0
- package/examples/dom-test/dist/game.js.LICENSE.txt +35 -0
- package/examples/dom-test/index.html +24 -0
- package/examples/dom-test/index.ts +22 -0
- package/examples/particle-test/assets/bird.png +0 -0
- package/examples/particle-test/dist/game.js +2 -0
- package/examples/particle-test/dist/game.js.LICENSE.txt +35 -0
- package/examples/particle-test/index.html +24 -0
- package/examples/particle-test/index.ts +30 -0
- package/examples/renderer-test/dist/game.js +2 -0
- package/examples/renderer-test/dist/game.js.LICENSE.txt +35 -0
- package/examples/renderer-test/index.html +24 -0
- package/examples/renderer-test/index.ts +9 -0
- package/examples/simple-battle/assets/bgm/battle.mp3 +0 -0
- package/examples/simple-battle/assets/bitmap-fonts/white-peaberry.fnt +107 -0
- package/examples/simple-battle/assets/bitmap-fonts/white-peaberry.png +0 -0
- package/examples/simple-battle/assets/joystick/joystick.png +0 -0
- package/examples/simple-battle/assets/joystick/knob.png +0 -0
- package/examples/simple-battle/assets/sfx/hero/die/die.wav +0 -0
- package/examples/simple-battle/assets/sfx/hero/heal/heal.wav +0 -0
- package/examples/simple-battle/assets/sfx/hero/hit/hit1.wav +0 -0
- package/examples/simple-battle/assets/sfx/hero/hit/hit2.wav +0 -0
- package/examples/simple-battle/assets/sfx/hero/hit/hit3.wav +0 -0
- package/examples/simple-battle/assets/sfx/hero/miss/miss1.wav +0 -0
- package/examples/simple-battle/assets/sfx/hero/miss/miss2.wav +0 -0
- package/examples/simple-battle/assets/sfx/hero/miss/miss3.wav +0 -0
- package/examples/simple-battle/assets/sfx/orc/die/die.wav +0 -0
- package/examples/simple-battle/assets/sfx/orc/hit/hit1.wav +0 -0
- package/examples/simple-battle/assets/sfx/orc/hit/hit2.wav +0 -0
- package/examples/simple-battle/assets/sfx/orc/hit/hit3.wav +0 -0
- package/examples/simple-battle/assets/sfx/orc/miss/miss1.wav +0 -0
- package/examples/simple-battle/assets/sfx/orc/miss/miss2.wav +0 -0
- package/examples/simple-battle/assets/sfx/orc/miss/miss3.wav +0 -0
- package/examples/simple-battle/assets/spritesheets/hero-atlas.json +246 -0
- package/examples/simple-battle/assets/spritesheets/hero.png +0 -0
- package/examples/simple-battle/assets/spritesheets/orc-atlas.json +246 -0
- package/examples/simple-battle/assets/spritesheets/orc.png +0 -0
- package/examples/simple-battle/assets/spritesheets/potion-atlas.json +68 -0
- package/examples/simple-battle/assets/spritesheets/potion.png +0 -0
- package/examples/simple-battle/dist/game.js +2 -0
- package/examples/simple-battle/dist/game.js.LICENSE.txt +35 -0
- package/examples/simple-battle/hud/damage-text.ts +46 -0
- package/examples/simple-battle/hud/heal-text.ts +46 -0
- package/examples/simple-battle/hud/hp-bar.ts +38 -0
- package/examples/simple-battle/index.html +24 -0
- package/examples/simple-battle/index.ts +41 -0
- package/examples/simple-battle/objects/character.ts +95 -0
- package/examples/simple-battle/objects/hero.ts +111 -0
- package/examples/simple-battle/objects/orc.ts +107 -0
- package/examples/simple-battle/objects/potion.ts +27 -0
- package/examples/simple-battle/stage.ts +174 -0
- package/examples/spine-test/assets/spine/spineboy.atlas +95 -0
- package/examples/spine-test/assets/spine/spineboy.png +0 -0
- package/examples/spine-test/assets/spine/spineboy.skel +0 -0
- package/examples/spine-test/dist/game.js +2 -0
- package/examples/spine-test/dist/game.js.LICENSE.txt +35 -0
- package/examples/spine-test/index.html +24 -0
- package/examples/spine-test/index.ts +29 -0
- package/examples/sprite-test/assets/bird.png +0 -0
- package/examples/sprite-test/assets/fire.png +0 -0
- package/examples/sprite-test/dist/game.js +2 -0
- package/examples/sprite-test/dist/game.js.LICENSE.txt +35 -0
- package/examples/sprite-test/index.html +24 -0
- package/examples/sprite-test/index.ts +38 -0
- package/examples/tsconfig.json +2 -1
- package/examples/webpack.config.js +17 -3
- package/jest.config.ts +10 -0
- package/lib/asset/audio.js +47 -11
- package/lib/asset/audio.js.map +1 -1
- package/lib/asset/loaders/audio.js +7 -4
- package/lib/asset/loaders/audio.js.map +1 -1
- package/lib/asset/loaders/binary.js +7 -4
- package/lib/asset/loaders/binary.js.map +1 -1
- package/lib/asset/loaders/bitmap-font.js +74 -0
- package/lib/asset/loaders/bitmap-font.js.map +1 -0
- package/lib/asset/loaders/font.js +4 -1
- package/lib/asset/loaders/font.js.map +1 -1
- package/lib/asset/loaders/loader.js +17 -12
- package/lib/asset/loaders/loader.js.map +1 -1
- package/lib/asset/loaders/spritesheet.js +18 -8
- package/lib/asset/loaders/spritesheet.js.map +1 -1
- package/lib/asset/loaders/text.js +6 -3
- package/lib/asset/loaders/text.js.map +1 -1
- package/lib/asset/loaders/texture.js +22 -26
- package/lib/asset/loaders/texture.js.map +1 -1
- package/lib/asset/preload.js +60 -56
- package/lib/asset/preload.js.map +1 -1
- package/lib/collision/check-collision.js +804 -0
- package/lib/collision/check-collision.js.map +1 -0
- package/lib/collision/check-collision.test.js +300 -0
- package/lib/collision/check-collision.test.js.map +1 -0
- package/lib/collision/colliders.js +8 -0
- package/lib/collision/colliders.js.map +1 -0
- package/lib/debug.js.map +1 -0
- package/lib/dom/dom-animated-sprite.js +106 -0
- package/lib/dom/dom-animated-sprite.js.map +1 -0
- package/lib/dom/dom-game-object.js +108 -0
- package/lib/dom/dom-game-object.js.map +1 -0
- package/lib/dom/dom-particle.js +105 -0
- package/lib/dom/dom-particle.js.map +1 -0
- package/lib/dom/dom-preload.js +43 -0
- package/lib/dom/dom-preload.js.map +1 -0
- package/lib/dom/dom-sprite.js +40 -0
- package/lib/dom/dom-sprite.js.map +1 -0
- package/lib/dom/dom-texture-loader.js +36 -0
- package/lib/dom/dom-texture-loader.js.map +1 -0
- package/lib/dom/dom-utils.js +20 -0
- package/lib/dom/dom-utils.js.map +1 -0
- package/lib/index copy.js +16 -0
- package/lib/index copy.js.map +1 -0
- package/lib/index.js +36 -10
- package/lib/index.js.map +1 -1
- package/lib/input/joystick.js +262 -0
- package/lib/input/joystick.js.map +1 -0
- package/lib/node/core/dirty-number.js +19 -0
- package/lib/node/core/dirty-number.js.map +1 -0
- package/lib/node/core/game-node.js +63 -0
- package/lib/node/core/game-node.js.map +1 -0
- package/lib/node/core/game-object.js +8 -0
- package/lib/node/core/game-object.js.map +1 -0
- package/lib/node/core/renderable.js +59 -0
- package/lib/node/core/renderable.js.map +1 -0
- package/lib/node/core/transform.js +70 -0
- package/lib/node/core/transform.js.map +1 -0
- package/lib/node/core/transformable.js +85 -0
- package/lib/node/core/transformable.js.map +1 -0
- package/lib/node/ext/animated-sprite.js +77 -0
- package/lib/node/ext/animated-sprite.js.map +1 -0
- package/lib/node/ext/bitmap-text.js +93 -0
- package/lib/node/ext/bitmap-text.js.map +1 -0
- package/lib/node/ext/circle.js +43 -0
- package/lib/node/ext/circle.js.map +1 -0
- package/lib/node/ext/deplay.js +22 -0
- package/lib/node/ext/deplay.js.map +1 -0
- package/lib/node/ext/dom-container.js +51 -0
- package/lib/node/ext/dom-container.js.map +1 -0
- package/lib/node/ext/interval.js +22 -0
- package/lib/node/ext/interval.js.map +1 -0
- package/lib/node/ext/particle.js +98 -0
- package/lib/node/ext/particle.js.map +1 -0
- package/lib/node/ext/rectangle.js +52 -0
- package/lib/node/ext/rectangle.js.map +1 -0
- package/lib/node/ext/spine.js +272 -0
- package/lib/node/ext/spine.js.map +1 -0
- package/lib/node/ext/sprite.js +42 -0
- package/lib/node/ext/sprite.js.map +1 -0
- package/lib/node/physics/physics-object.js +92 -0
- package/lib/node/physics/physics-object.js.map +1 -0
- package/lib/node/physics/physics-world.js +29 -0
- package/lib/node/physics/physics-world.js.map +1 -0
- package/lib/node/physics/rigidbodies.js +7 -0
- package/lib/node/physics/rigidbodies.js.map +1 -0
- package/lib/renderer/camera.js +19 -0
- package/lib/renderer/camera.js.map +1 -0
- package/lib/renderer/container-manager.js +29 -0
- package/lib/renderer/container-manager.js.map +1 -0
- package/lib/renderer/fps-display.js +18 -0
- package/lib/renderer/fps-display.js.map +1 -0
- package/lib/renderer/layer.js +12 -0
- package/lib/renderer/layer.js.map +1 -0
- package/lib/renderer/renderer.js +146 -0
- package/lib/renderer/renderer.js.map +1 -0
- package/lib/renderer/ticker.js +56 -0
- package/lib/renderer/ticker.js.map +1 -0
- package/lib/renderer/ticker.test.js +241 -0
- package/lib/renderer/ticker.test.js.map +1 -0
- package/lib/types/animation-atlas.js +2 -0
- package/lib/types/animation-atlas.js.map +1 -0
- package/lib/types/asset/audio.d.ts +5 -4
- package/lib/types/asset/audio.d.ts.map +1 -1
- package/lib/types/asset/loaders/audio.d.ts +2 -1
- package/lib/types/asset/loaders/audio.d.ts.map +1 -1
- package/lib/types/asset/loaders/binary.d.ts +2 -1
- package/lib/types/asset/loaders/binary.d.ts.map +1 -1
- package/lib/types/asset/loaders/bitmap-font.d.ts +17 -0
- package/lib/types/asset/loaders/bitmap-font.d.ts.map +1 -0
- package/lib/types/asset/loaders/font.d.ts +2 -1
- package/lib/types/asset/loaders/font.d.ts.map +1 -1
- package/lib/types/asset/loaders/loader.d.ts +6 -6
- package/lib/types/asset/loaders/loader.d.ts.map +1 -1
- package/lib/types/asset/loaders/spritesheet.d.ts +14 -6
- package/lib/types/asset/loaders/spritesheet.d.ts.map +1 -1
- package/lib/types/asset/loaders/text.d.ts +2 -1
- package/lib/types/asset/loaders/text.d.ts.map +1 -1
- package/lib/types/asset/loaders/texture.d.ts +2 -2
- package/lib/types/asset/loaders/texture.d.ts.map +1 -1
- package/lib/types/asset/preload.d.ts +7 -5
- package/lib/types/asset/preload.d.ts.map +1 -1
- package/lib/types/atlas copy.js +2 -0
- package/lib/types/atlas copy.js.map +1 -0
- package/lib/types/atlas.js +2 -0
- package/lib/types/atlas.js.map +1 -0
- package/lib/types/bitmap-font.js +2 -0
- package/lib/types/bitmap-font.js.map +1 -0
- package/lib/types/collision/check-collision.d.ts +4 -0
- package/lib/types/collision/check-collision.d.ts.map +1 -0
- package/lib/types/collision/check-collision.test.d.ts +2 -0
- package/lib/types/collision/check-collision.test.d.ts.map +1 -0
- package/lib/types/collision/colliders.d.ts +34 -0
- package/lib/types/collision/colliders.d.ts.map +1 -0
- package/lib/types/debug.d.ts.map +1 -0
- package/lib/types/dom/dom-animated-sprite.d.ts +23 -0
- package/lib/types/dom/dom-animated-sprite.d.ts.map +1 -0
- package/lib/types/dom/dom-game-object.d.ts +44 -0
- package/lib/types/dom/dom-game-object.d.ts.map +1 -0
- package/lib/types/dom/dom-particle.d.ts +30 -0
- package/lib/types/dom/dom-particle.d.ts.map +1 -0
- package/lib/types/dom/dom-preload.d.ts +2 -0
- package/lib/types/dom/dom-preload.d.ts.map +1 -0
- package/lib/types/dom/dom-sprite.d.ts +13 -0
- package/lib/types/dom/dom-sprite.d.ts.map +1 -0
- package/lib/types/dom/dom-texture-loader.d.ts +8 -0
- package/lib/types/dom/dom-texture-loader.d.ts.map +1 -0
- package/lib/types/dom/dom-utils.d.ts +3 -0
- package/lib/types/dom/dom-utils.d.ts.map +1 -0
- package/lib/types/index copy.d.ts +16 -0
- package/lib/types/index copy.d.ts.map +1 -0
- package/lib/types/index.d.ts +26 -11
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/input/joystick.d.ts +28 -0
- package/lib/types/input/joystick.d.ts.map +1 -0
- package/lib/types/node/core/dirty-number.d.ts +9 -0
- package/lib/types/node/core/dirty-number.d.ts.map +1 -0
- package/lib/types/node/core/game-node.d.ts +16 -0
- package/lib/types/node/core/game-node.d.ts.map +1 -0
- package/lib/types/node/core/game-object.d.ts +8 -0
- package/lib/types/node/core/game-object.d.ts.map +1 -0
- package/lib/types/node/core/renderable.d.ts +23 -0
- package/lib/types/node/core/renderable.d.ts.map +1 -0
- package/lib/types/node/core/transform.d.ts +27 -0
- package/lib/types/node/core/transform.d.ts.map +1 -0
- package/lib/types/node/core/transformable.d.ts +44 -0
- package/lib/types/node/core/transformable.d.ts.map +1 -0
- package/lib/types/node/ext/animated-sprite.d.ts +22 -0
- package/lib/types/node/ext/animated-sprite.d.ts.map +1 -0
- package/lib/types/node/ext/bitmap-text.d.ts +14 -0
- package/lib/types/node/ext/bitmap-text.d.ts.map +1 -0
- package/lib/types/node/ext/circle.d.ts +19 -0
- package/lib/types/node/ext/circle.d.ts.map +1 -0
- package/lib/types/node/ext/deplay.d.ts +8 -0
- package/lib/types/node/ext/deplay.d.ts.map +1 -0
- package/lib/types/node/ext/dom-container.d.ts +12 -0
- package/lib/types/node/ext/dom-container.d.ts.map +1 -0
- package/lib/types/node/ext/interval.d.ts +9 -0
- package/lib/types/node/ext/interval.d.ts.map +1 -0
- package/lib/types/node/ext/particle.d.ts +30 -0
- package/lib/types/node/ext/particle.d.ts.map +1 -0
- package/lib/types/node/ext/rectangle.d.ts +22 -0
- package/lib/types/node/ext/rectangle.d.ts.map +1 -0
- package/lib/types/node/ext/spine.d.ts +36 -0
- package/lib/types/node/ext/spine.d.ts.map +1 -0
- package/lib/types/node/ext/sprite.d.ts +13 -0
- package/lib/types/node/ext/sprite.d.ts.map +1 -0
- package/lib/types/node/physics/physics-object.d.ts +38 -0
- package/lib/types/node/physics/physics-object.d.ts.map +1 -0
- package/lib/types/node/physics/physics-world.d.ts +18 -0
- package/lib/types/node/physics/physics-world.d.ts.map +1 -0
- package/lib/types/node/physics/rigidbodies.d.ts +23 -0
- package/lib/types/node/physics/rigidbodies.d.ts.map +1 -0
- package/lib/types/renderer/camera.d.ts +13 -0
- package/lib/types/renderer/camera.d.ts.map +1 -0
- package/lib/types/renderer/container-manager.d.ts +9 -0
- package/lib/types/renderer/container-manager.d.ts.map +1 -0
- package/lib/types/renderer/fps-display.d.ts +7 -0
- package/lib/types/renderer/fps-display.d.ts.map +1 -0
- package/lib/types/renderer/layer.d.ts +7 -0
- package/lib/types/renderer/layer.d.ts.map +1 -0
- package/lib/types/renderer/renderer.d.ts +40 -0
- package/lib/types/renderer/renderer.d.ts.map +1 -0
- package/lib/types/renderer/ticker.d.ts +6 -0
- package/lib/types/renderer/ticker.d.ts.map +1 -0
- package/lib/types/renderer/ticker.test.d.ts +40 -0
- package/lib/types/renderer/ticker.test.d.ts.map +1 -0
- package/lib/types/sprite-atlas.js +2 -0
- package/lib/types/sprite-atlas.js.map +1 -0
- package/lib/types/types/animation-atlas.d.ts +14 -0
- package/lib/types/types/animation-atlas.d.ts.map +1 -0
- package/lib/types/types/atlas copy.d.ts +12 -0
- package/lib/types/types/atlas copy.d.ts.map +1 -0
- package/lib/types/types/atlas.d.ts +16 -0
- package/lib/types/types/atlas.d.ts.map +1 -0
- package/lib/types/types/bitmap-font.d.ts +18 -0
- package/lib/types/types/bitmap-font.d.ts.map +1 -0
- package/lib/types/types/sprite-atlas.d.ts +13 -0
- package/lib/types/types/sprite-atlas.d.ts.map +1 -0
- package/lib/types/utils/device.d.ts +2 -0
- package/lib/types/utils/device.d.ts.map +1 -0
- package/lib/utils/device.js +2 -0
- package/lib/utils/device.js.map +1 -0
- package/package.json +8 -7
- package/src/asset/audio.ts +134 -90
- package/src/asset/loaders/audio.ts +23 -20
- package/src/asset/loaders/binary.ts +20 -16
- package/src/asset/loaders/bitmap-font.ts +91 -0
- package/src/asset/loaders/font.ts +18 -14
- package/src/asset/loaders/loader.ts +27 -23
- package/src/asset/loaders/spritesheet.ts +47 -36
- package/src/asset/loaders/text.ts +19 -15
- package/src/asset/loaders/texture.ts +30 -37
- package/src/asset/preload.ts +71 -64
- package/src/collision/check-collision.test.ts +349 -0
- package/src/collision/check-collision.ts +821 -0
- package/src/collision/colliders.ts +19 -0
- package/src/debug.ts +5 -0
- package/src/dom/dom-animated-sprite.ts +132 -0
- package/src/dom/dom-game-object.ts +134 -0
- package/src/dom/dom-particle.ts +151 -0
- package/src/dom/dom-preload.ts +54 -0
- package/src/dom/dom-sprite.ts +50 -0
- package/src/dom/dom-texture-loader.ts +44 -0
- package/src/dom/dom-utils.ts +19 -0
- package/src/index.ts +47 -13
- package/src/input/joystick.ts +316 -0
- package/src/node/core/dirty-number.ts +21 -0
- package/src/node/core/game-node.ts +74 -0
- package/src/node/core/game-object.ts +11 -0
- package/src/node/core/renderable.ts +72 -0
- package/src/node/core/transform.ts +82 -0
- package/src/node/core/transformable.ts +111 -0
- package/src/node/ext/animated-sprite.ts +103 -0
- package/src/node/ext/bitmap-text.ts +113 -0
- package/src/node/ext/circle.ts +55 -0
- package/src/node/ext/deplay.ts +25 -0
- package/src/node/ext/dom-container.ts +62 -0
- package/src/node/ext/interval.ts +25 -0
- package/src/node/ext/particle.ts +142 -0
- package/src/node/ext/rectangle.ts +71 -0
- package/src/node/ext/spine.ts +323 -0
- package/src/node/ext/sprite.ts +53 -0
- package/src/node/physics/physics-object.ts +127 -0
- package/src/node/physics/physics-world.ts +41 -0
- package/src/node/physics/rigidbodies.ts +14 -0
- package/src/renderer/camera.ts +25 -0
- package/src/renderer/container-manager.ts +36 -0
- package/src/renderer/fps-display.ts +21 -0
- package/src/renderer/layer.ts +15 -0
- package/src/renderer/renderer.ts +181 -0
- package/src/renderer/ticker.test.ts +325 -0
- package/src/renderer/ticker.ts +54 -0
- package/src/types/atlas.ts +17 -0
- package/src/types/bitmap-font.ts +19 -0
- package/src/utils/device.ts +1 -0
- package/examples/test-dom/index.ts +0 -21
- package/lib/game-object/game-object-physics.js +0 -188
- package/lib/game-object/game-object-physics.js.map +0 -1
- package/lib/game-object/game-object-rendering.js +0 -35
- package/lib/game-object/game-object-rendering.js.map +0 -1
- package/lib/game-object/game-object.js +0 -162
- package/lib/game-object/game-object.js.map +0 -1
- package/lib/game-object/transform.js +0 -118
- package/lib/game-object/transform.js.map +0 -1
- package/lib/game-object-ext/animated-sprite.js +0 -117
- package/lib/game-object-ext/animated-sprite.js.map +0 -1
- package/lib/game-object-ext/dom-container.js +0 -56
- package/lib/game-object-ext/dom-container.js.map +0 -1
- package/lib/game-object-ext/rect.js +0 -30
- package/lib/game-object-ext/rect.js.map +0 -1
- package/lib/game-object-ext/spine.js +0 -206
- package/lib/game-object-ext/spine.js.map +0 -1
- package/lib/game-object-ext/sprite.js +0 -46
- package/lib/game-object-ext/sprite.js.map +0 -1
- package/lib/game-object-ext/text.js +0 -68
- package/lib/game-object-ext/text.js.map +0 -1
- package/lib/game-object-ext/tiling-sprite.js +0 -64
- package/lib/game-object-ext/tiling-sprite.js.map +0 -1
- package/lib/types/game-object/game-object-physics.d.ts +0 -42
- package/lib/types/game-object/game-object-physics.d.ts.map +0 -1
- package/lib/types/game-object/game-object-rendering.d.ts +0 -15
- package/lib/types/game-object/game-object-rendering.d.ts.map +0 -1
- package/lib/types/game-object/game-object.d.ts +0 -81
- package/lib/types/game-object/game-object.d.ts.map +0 -1
- package/lib/types/game-object/transform.d.ts +0 -43
- package/lib/types/game-object/transform.d.ts.map +0 -1
- package/lib/types/game-object-ext/animated-sprite.d.ts +0 -29
- package/lib/types/game-object-ext/animated-sprite.d.ts.map +0 -1
- package/lib/types/game-object-ext/dom-container.d.ts +0 -16
- package/lib/types/game-object-ext/dom-container.d.ts.map +0 -1
- package/lib/types/game-object-ext/rect.d.ts +0 -17
- package/lib/types/game-object-ext/rect.d.ts.map +0 -1
- package/lib/types/game-object-ext/spine.d.ts +0 -35
- package/lib/types/game-object-ext/spine.d.ts.map +0 -1
- package/lib/types/game-object-ext/sprite.d.ts +0 -14
- package/lib/types/game-object-ext/sprite.d.ts.map +0 -1
- package/lib/types/game-object-ext/text.d.ts +0 -26
- package/lib/types/game-object-ext/text.d.ts.map +0 -1
- package/lib/types/game-object-ext/tiling-sprite.d.ts +0 -20
- package/lib/types/game-object-ext/tiling-sprite.d.ts.map +0 -1
- package/lib/types/utils/debug.d.ts.map +0 -1
- package/lib/types/utils/go.d.ts +0 -26
- package/lib/types/utils/go.d.ts.map +0 -1
- package/lib/types/world/world-debug.d.ts +0 -11
- package/lib/types/world/world-debug.d.ts.map +0 -1
- package/lib/types/world/world-physics.d.ts +0 -16
- package/lib/types/world/world-physics.d.ts.map +0 -1
- package/lib/types/world/world-rendering.d.ts +0 -28
- package/lib/types/world/world-rendering.d.ts.map +0 -1
- package/lib/types/world/world.d.ts +0 -38
- package/lib/types/world/world.d.ts.map +0 -1
- package/lib/utils/debug.js.map +0 -1
- package/lib/utils/go.js +0 -33
- package/lib/utils/go.js.map +0 -1
- package/lib/world/world-debug.js +0 -89
- package/lib/world/world-debug.js.map +0 -1
- package/lib/world/world-physics.js +0 -45
- package/lib/world/world-physics.js.map +0 -1
- package/lib/world/world-rendering.js +0 -123
- package/lib/world/world-rendering.js.map +0 -1
- package/lib/world/world.js +0 -147
- package/lib/world/world.js.map +0 -1
- package/src/game-object/game-object-physics.ts +0 -191
- package/src/game-object/game-object-rendering.ts +0 -27
- package/src/game-object/game-object.ts +0 -190
- package/src/game-object/transform.ts +0 -164
- package/src/game-object-ext/animated-sprite.ts +0 -140
- package/src/game-object-ext/dom-container.ts +0 -67
- package/src/game-object-ext/rect.ts +0 -40
- package/src/game-object-ext/spine.ts +0 -235
- package/src/game-object-ext/sprite.ts +0 -55
- package/src/game-object-ext/text.ts +0 -83
- package/src/game-object-ext/tiling-sprite.ts +0 -73
- package/src/utils/debug.ts +0 -5
- package/src/utils/go.ts +0 -53
- package/src/world/world-debug.ts +0 -114
- package/src/world/world-physics.ts +0 -52
- package/src/world/world-rendering.ts +0 -145
- package/src/world/world.ts +0 -171
- /package/examples/{test-dom → auto-battle}/index.html +0 -0
- /package/lib/{utils/debug.js → debug.js} +0 -0
- /package/lib/types/{utils/debug.d.ts → debug.d.ts} +0 -0
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import { WorldTransform } from '../node/core/transform'
|
|
2
|
+
import { checkCollision } from './check-collision'
|
|
3
|
+
import { CircleCollider, ColliderType, EllipseCollider, PolygonCollider, RectangleCollider } from './colliders'
|
|
4
|
+
|
|
5
|
+
// ===== Local type alias to match the engine ========================================================
|
|
6
|
+
type Transform = WorldTransform
|
|
7
|
+
|
|
8
|
+
// ===== Builders ====================================================================================
|
|
9
|
+
const rad = (deg: number) => (deg * Math.PI) / 180
|
|
10
|
+
|
|
11
|
+
function T(x = 0, y = 0, rotDeg = 0, sx = 1, sy = 1): Transform {
|
|
12
|
+
const v = rad(rotDeg)
|
|
13
|
+
return {
|
|
14
|
+
x: { v: x },
|
|
15
|
+
y: { v: y },
|
|
16
|
+
scaleX: { v: sx },
|
|
17
|
+
scaleY: { v: sy },
|
|
18
|
+
rotation: { v, sin: Math.sin(v), cos: Math.cos(v) },
|
|
19
|
+
} as unknown as Transform
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function R(width: number, height: number, ox = 0, oy = 0): RectangleCollider {
|
|
23
|
+
return { type: ColliderType.Rectangle, width, height, x: ox, y: oy } as RectangleCollider
|
|
24
|
+
}
|
|
25
|
+
function C(radius: number, ox = 0, oy = 0): CircleCollider {
|
|
26
|
+
return { type: ColliderType.Circle, radius, x: ox, y: oy } as CircleCollider
|
|
27
|
+
}
|
|
28
|
+
function E(width: number, height: number, ox = 0, oy = 0): EllipseCollider {
|
|
29
|
+
return { type: ColliderType.Ellipse, width, height, x: ox, y: oy } as EllipseCollider
|
|
30
|
+
}
|
|
31
|
+
function P(points: Array<[number, number]>): PolygonCollider {
|
|
32
|
+
const vertices = points.map(([x, y]) => ({ x, y }))
|
|
33
|
+
return { type: ColliderType.Polygon, vertices } as PolygonCollider
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ===== RNG & helpers ===============================================================================
|
|
37
|
+
let _seed = 0x9e3779b9 | 0
|
|
38
|
+
const setSeed = (s: number) => (_seed = s | 0)
|
|
39
|
+
const rnd = () => {
|
|
40
|
+
let x = _seed | 0; x ^= x << 13; x ^= x >>> 17; x ^= x << 5; _seed = x | 0; return (x >>> 0) / 4294967296
|
|
41
|
+
}
|
|
42
|
+
const rrange = (a: number, b: number) => a + (b - a) * rnd()
|
|
43
|
+
const rint = (a: number, b: number) => Math.floor(rrange(a, b + 1))
|
|
44
|
+
|
|
45
|
+
const translateT = (t: Transform, dx: number, dy: number): Transform =>
|
|
46
|
+
T(t.x.v + dx, t.y.v + dy, (t.rotation.v * 180) / Math.PI, t.scaleX.v, t.scaleY.v)
|
|
47
|
+
|
|
48
|
+
const rotatePoint = (x: number, y: number, theta: number): [number, number] => [
|
|
49
|
+
Math.cos(theta) * x - Math.sin(theta) * y,
|
|
50
|
+
Math.sin(theta) * x + Math.cos(theta) * y
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
const rigidRotateT = (t: Transform, deltaDeg: number): Transform => {
|
|
54
|
+
const theta = rad(deltaDeg)
|
|
55
|
+
const [nx, ny] = rotatePoint(t.x.v, t.y.v, theta)
|
|
56
|
+
const newRotDeg = (t.rotation.v * 180) / Math.PI + deltaDeg
|
|
57
|
+
return T(nx, ny, newRotDeg, t.scaleX.v, t.scaleY.v)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Apply transforms per-shape for property tests
|
|
61
|
+
function applyTranslation(
|
|
62
|
+
col: CircleCollider | RectangleCollider | EllipseCollider | PolygonCollider,
|
|
63
|
+
t: Transform,
|
|
64
|
+
dx: number, dy: number
|
|
65
|
+
): [typeof col, Transform] {
|
|
66
|
+
return [col, translateT(t, dx, dy)]
|
|
67
|
+
}
|
|
68
|
+
function applyRotation(
|
|
69
|
+
col: CircleCollider | RectangleCollider | EllipseCollider | PolygonCollider,
|
|
70
|
+
t: Transform,
|
|
71
|
+
deg: number
|
|
72
|
+
): [typeof col, Transform] {
|
|
73
|
+
return [col, rigidRotateT(t, deg)]
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ---- Stability checks to avoid near-tangency numerical flicker -----------------------------------
|
|
77
|
+
function isStablePair(
|
|
78
|
+
a: CircleCollider | RectangleCollider | EllipseCollider | PolygonCollider, ta: Transform,
|
|
79
|
+
b: CircleCollider | RectangleCollider | EllipseCollider | PolygonCollider, tb: Transform
|
|
80
|
+
) {
|
|
81
|
+
const base = checkCollision(a, ta, b, tb)
|
|
82
|
+
const eps = 1e-6
|
|
83
|
+
const dirs: Array<[number, number]> = [[eps, -eps], [-eps, eps], [eps, eps], [-eps, -eps]]
|
|
84
|
+
for (const [dx, dy] of dirs) {
|
|
85
|
+
const [a2, ta2] = applyTranslation(a, ta, dx, dy)
|
|
86
|
+
const [b2, tb2] = applyTranslation(b, tb, -dx, -dy)
|
|
87
|
+
const j = checkCollision(a2, ta2, b2, tb2)
|
|
88
|
+
if (j !== base) return false
|
|
89
|
+
}
|
|
90
|
+
return true
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function isRotationStablePair(
|
|
94
|
+
a: CircleCollider | RectangleCollider | EllipseCollider | PolygonCollider, ta: Transform,
|
|
95
|
+
b: CircleCollider | RectangleCollider | EllipseCollider | PolygonCollider, tb: Transform,
|
|
96
|
+
deltaDeg: number
|
|
97
|
+
) {
|
|
98
|
+
const [aR, taR] = applyRotation(a, ta, deltaDeg)
|
|
99
|
+
const [bR, tbR] = applyRotation(b, tb, deltaDeg)
|
|
100
|
+
const baseRot = checkCollision(aR, taR, bR, tbR)
|
|
101
|
+
|
|
102
|
+
// small rotation jitter — use a slightly larger epsilon to catch GJK flips
|
|
103
|
+
const epsDeg = 1e-3
|
|
104
|
+
const [aR1, taR1] = applyRotation(a, ta, deltaDeg + epsDeg)
|
|
105
|
+
const [bR1, tbR1] = applyRotation(b, tb, deltaDeg + epsDeg)
|
|
106
|
+
const [aR2, taR2] = applyRotation(a, ta, deltaDeg - epsDeg)
|
|
107
|
+
const [bR2, tbR2] = applyRotation(b, tb, deltaDeg - epsDeg)
|
|
108
|
+
const r1 = checkCollision(aR1, taR1, bR1, tbR1)
|
|
109
|
+
const r2 = checkCollision(aR2, taR2, bR2, tbR2)
|
|
110
|
+
if (r1 !== baseRot || r2 !== baseRot) return false
|
|
111
|
+
|
|
112
|
+
// small translation jitter after rotation
|
|
113
|
+
const eps = 1e-5
|
|
114
|
+
const [aRt1, taRt1] = applyTranslation(aR, taR, eps, -eps)
|
|
115
|
+
const [bRt1, tbRt1] = applyTranslation(bR, tbR, -eps, eps)
|
|
116
|
+
const [aRt2, taRt2] = applyTranslation(aR, taR, -eps, eps)
|
|
117
|
+
const [bRt2, tbRt2] = applyTranslation(bR, tbR, eps, -eps)
|
|
118
|
+
const t1 = checkCollision(aRt1, taRt1, bRt1, tbRt1)
|
|
119
|
+
const t2 = checkCollision(aRt2, taRt2, bRt2, tbRt2)
|
|
120
|
+
return t1 === baseRot && t2 === baseRot
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const randomConvexPoly = (n: number, radius = 2, jitter = 0.5): PolygonCollider => {
|
|
124
|
+
const pts: Array<[number, number]> = []
|
|
125
|
+
for (let i = 0; i < n; i++) {
|
|
126
|
+
const a = (i + rnd() * 0.1) * (2 * Math.PI / n)
|
|
127
|
+
const r = radius * (1 - jitter / 2 + jitter * rnd())
|
|
128
|
+
pts.push([r * Math.cos(a), r * Math.sin(a)])
|
|
129
|
+
}
|
|
130
|
+
pts.sort((p, q) => Math.atan2(p[1], p[0]) - Math.atan2(q[1], q[0]))
|
|
131
|
+
return P(pts)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function randomColliderAndTransform(): [CircleCollider | RectangleCollider | EllipseCollider | PolygonCollider, Transform] {
|
|
135
|
+
switch (rint(0, 3)) {
|
|
136
|
+
case 0: return [R(rrange(0.2, 4.0), rrange(0.2, 4.0)), randomTransform()]
|
|
137
|
+
case 1: return [C(rrange(0.2, 2.5)), randomTransform()]
|
|
138
|
+
case 2: return [E(rrange(0.4, 5.0), rrange(0.4, 5.0)), randomTransform()]
|
|
139
|
+
default: return [randomConvexPoly(rint(3, 7)), randomTransform()]
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function randomTransform(): Transform {
|
|
143
|
+
return T(
|
|
144
|
+
rrange(-5, 5),
|
|
145
|
+
rrange(-5, 5),
|
|
146
|
+
rrange(-180, 180),
|
|
147
|
+
rrange(0.5, 2.0) * (rnd() < 0.05 ? -1 : 1),
|
|
148
|
+
rrange(0.5, 2.0) * (rnd() < 0.05 ? -1 : 1),
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Invariance test should not be affected by anisotropic/negative scales.
|
|
153
|
+
function normalizeForRigid(t: Transform): Transform {
|
|
154
|
+
return T(t.x.v, t.y.v, (t.rotation.v * 180) / Math.PI, 1, 1)
|
|
155
|
+
}
|
|
156
|
+
const isEllipse = (col: any): boolean => col.type === ColliderType.Ellipse
|
|
157
|
+
|
|
158
|
+
// Utility wrappers that also check symmetry implicitly
|
|
159
|
+
function expectCollide(a: any, ta: Transform, b: any, tb: Transform, hint?: string) {
|
|
160
|
+
const ab = checkCollision(a, ta, b, tb)
|
|
161
|
+
const ba = checkCollision(b, tb, a, ta)
|
|
162
|
+
if (!(ab && ba)) throw new Error(hint ?? `expected collision but got ab=${ab}, ba=${ba}`)
|
|
163
|
+
}
|
|
164
|
+
function expectSeparate(a: any, ta: Transform, b: any, tb: Transform, hint?: string) {
|
|
165
|
+
const ab = checkCollision(a, ta, b, tb)
|
|
166
|
+
const ba = checkCollision(b, tb, a, ta)
|
|
167
|
+
if (ab || ba) throw new Error(hint ?? `expected separation but got ab=${ab}, ba=${ba}`)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// ===== TESTS =======================================================================================
|
|
171
|
+
|
|
172
|
+
describe('Rect-Rect (AABB fast path)', () => {
|
|
173
|
+
it('overlap', () => {
|
|
174
|
+
expectCollide(R(2, 2), T(0, 0), R(2, 2), T(1, 0))
|
|
175
|
+
})
|
|
176
|
+
it('touching edge inclusive', () => {
|
|
177
|
+
expectCollide(R(2, 2), T(0, 0), R(2, 2), T(2, 0))
|
|
178
|
+
})
|
|
179
|
+
it('separated', () => {
|
|
180
|
+
expectSeparate(R(2, 2), T(0, 0), R(2, 2), T(2.01, 0))
|
|
181
|
+
})
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
describe('Rect-Rect (rotated, SAT path)', () => {
|
|
185
|
+
it('overlap (same center)', () => {
|
|
186
|
+
expectCollide(R(2, 2), T(0, 0, 45), R(2, 2), T(0, 0, -30))
|
|
187
|
+
})
|
|
188
|
+
it('separated', () => {
|
|
189
|
+
expectSeparate(R(2, 1), T(0, 0, 37), R(1.2, 2.4), T(4, 0, -20))
|
|
190
|
+
})
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
describe('Circle-Circle', () => {
|
|
194
|
+
it('overlap', () => {
|
|
195
|
+
expectCollide(C(1), T(0, 0), C(1), T(1.5, 0))
|
|
196
|
+
})
|
|
197
|
+
it('touching inclusive', () => {
|
|
198
|
+
expectCollide(C(1), T(0, 0), C(1), T(2, 0))
|
|
199
|
+
})
|
|
200
|
+
it('separated', () => {
|
|
201
|
+
expectSeparate(C(1), T(0, 0), C(1), T(2.01, 0))
|
|
202
|
+
})
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
describe('Circle scaling anisotropy (conservative)', () => {
|
|
206
|
+
it('still overlap when max scale enlarges radius', () => {
|
|
207
|
+
expectCollide(C(1), T(0, 0, 0, 2, 0.5), C(1), T(2.9, 0))
|
|
208
|
+
})
|
|
209
|
+
it('separated beyond conservative sum', () => {
|
|
210
|
+
expectSeparate(C(1), T(0, 0, 0, 2, 0.5), C(1), T(4.01, 0))
|
|
211
|
+
})
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
describe('Rect-Circle', () => {
|
|
215
|
+
it('overlap', () => {
|
|
216
|
+
expectCollide(R(2, 2), T(0, 0), C(1), T(1.2, 0))
|
|
217
|
+
})
|
|
218
|
+
it('touching inclusive', () => {
|
|
219
|
+
expectCollide(R(2, 2), T(0, 0), C(1), T(2, 0))
|
|
220
|
+
})
|
|
221
|
+
it('separated', () => {
|
|
222
|
+
expectSeparate(R(2, 2), T(0, 0), C(1), T(2.01, 0))
|
|
223
|
+
})
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
describe('Poly-Poly (convex)', () => {
|
|
227
|
+
const square = P([[-1, -1], [1, -1], [1, 1], [-1, 1]])
|
|
228
|
+
it('overlap', () => {
|
|
229
|
+
expectCollide(square, T(0, 0), square, T(1, 0))
|
|
230
|
+
})
|
|
231
|
+
it('separated', () => {
|
|
232
|
+
const moved = P(square.vertices.map(p => [p.x + 2.1, p.y]))
|
|
233
|
+
expectSeparate(square, T(0, 0), moved, T(0, 0))
|
|
234
|
+
})
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
describe('Poly-Circle', () => {
|
|
238
|
+
it('edge touching inclusive', () => {
|
|
239
|
+
const poly = P([[-1, -1], [1, -1], [1, 1], [-1, 1]])
|
|
240
|
+
expectCollide(poly, T(0, 0), C(1), T(2, 0))
|
|
241
|
+
})
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
describe('Poly-Rect', () => {
|
|
245
|
+
it('overlap with rotated rect', () => {
|
|
246
|
+
expectCollide(P([[-2, -1], [2, -1], [2, 1], [-2, 1]]), T(0, 0), R(1.5, 1.5), T(1.6, 0, 30))
|
|
247
|
+
})
|
|
248
|
+
it('separated gap', () => {
|
|
249
|
+
expectSeparate(P([[-1, -1], [1, -1], [1, 1], [-1, 1]]), T(0, 0), R(1, 1), T(2.05, 0, 15))
|
|
250
|
+
})
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
describe('Ellipse interactions (GJK)', () => {
|
|
254
|
+
it('Ellipse-Rect overlap axis-aligned', () => {
|
|
255
|
+
// rx=2 + rect.hx=0.5 → boundary=2.5; pick 2.2 for stable overlap
|
|
256
|
+
expectCollide(E(4, 2), T(0, 0), R(1, 1), T(2.2, 0))
|
|
257
|
+
})
|
|
258
|
+
it('Ellipse-Rect separated axis-aligned', () => {
|
|
259
|
+
expectSeparate(E(4, 2), T(0, 0), R(1, 1), T(3.6, 0))
|
|
260
|
+
})
|
|
261
|
+
it('Ellipse-Rect overlap rotated both', () => {
|
|
262
|
+
expectCollide(E(6, 2), T(0, 0, 25), R(2, 3), T(2.2, 0.5, -35))
|
|
263
|
+
})
|
|
264
|
+
it('Ellipse-Circle touching-ish (use slight overlap)', () => {
|
|
265
|
+
expectCollide(E(4, 2), T(0, 0), C(1), T(2.99, 0))
|
|
266
|
+
})
|
|
267
|
+
it('Ellipse-Circle separated', () => {
|
|
268
|
+
expectSeparate(E(4, 2), T(0, 0), C(1), T(3.05, 0))
|
|
269
|
+
})
|
|
270
|
+
it('Ellipse-Ellipse overlap axis-aligned', () => {
|
|
271
|
+
expectCollide(E(4, 2), T(0, 0), E(6, 2), T(4.7, 0))
|
|
272
|
+
})
|
|
273
|
+
it('Ellipse-Ellipse near-touching vs separated (robust)', () => {
|
|
274
|
+
expectCollide(E(4, 2), T(0, 0), E(6, 2), T(4.999, 0))
|
|
275
|
+
expectSeparate(E(4, 2), T(0, 0), E(6, 2), T(5.001, 0))
|
|
276
|
+
})
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
describe('Degenerate/edge sanity', () => {
|
|
280
|
+
it('Zero-radius circles coincident centers collide', () => {
|
|
281
|
+
expectCollide(C(0), T(1, 2), C(0), T(1, 2))
|
|
282
|
+
})
|
|
283
|
+
it('Zero-radius circle vs rectangle far separated', () => {
|
|
284
|
+
expectSeparate(C(0), T(10, 0), R(2, 2), T(0, 0))
|
|
285
|
+
})
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
// ===== Properties ==================================================================================
|
|
289
|
+
|
|
290
|
+
describe('Properties', () => {
|
|
291
|
+
it('symmetry over random pairs', () => {
|
|
292
|
+
setSeed(0xc0ffee)
|
|
293
|
+
const N = 300
|
|
294
|
+
for (let i = 0; i < N; i++) {
|
|
295
|
+
const [a, ta] = randomColliderAndTransform()
|
|
296
|
+
const [b, tb] = randomColliderAndTransform()
|
|
297
|
+
const ab = checkCollision(a, ta, b, tb)
|
|
298
|
+
const ba = checkCollision(b, tb, a, ta)
|
|
299
|
+
if (ab !== ba) throw new Error(`symmetry failed at i=${i}`)
|
|
300
|
+
}
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
it('translation invariance', () => {
|
|
304
|
+
setSeed(0xbadc0de)
|
|
305
|
+
const N = 200
|
|
306
|
+
for (let i = 0; i < N; i++) {
|
|
307
|
+
const [a, ta] = randomColliderAndTransform()
|
|
308
|
+
const [b, tb] = randomColliderAndTransform()
|
|
309
|
+
const base = checkCollision(a, ta, b, tb)
|
|
310
|
+
const dx = rrange(-5, 5), dy = rrange(-5, 5)
|
|
311
|
+
|
|
312
|
+
const [a2, ta2] = applyTranslation(a, ta, dx, dy)
|
|
313
|
+
const [b2, tb2] = applyTranslation(b, tb, dx, dy)
|
|
314
|
+
|
|
315
|
+
const moved = checkCollision(a2, ta2, b2, tb2)
|
|
316
|
+
if (base !== moved) throw new Error(`translation invariance failed at i=${i}`)
|
|
317
|
+
}
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
it('rigid rotation invariance (about origin)', () => {
|
|
321
|
+
setSeed(0xfeedface)
|
|
322
|
+
const N = 200
|
|
323
|
+
for (let i = 0; i < N; i++) {
|
|
324
|
+
const [a0, ta0] = randomColliderAndTransform()
|
|
325
|
+
const [b0, tb0] = randomColliderAndTransform()
|
|
326
|
+
|
|
327
|
+
// Remove anisotropic/negative scaling effect for the invariance test.
|
|
328
|
+
const ta = normalizeForRigid(ta0)
|
|
329
|
+
const tb = normalizeForRigid(tb0)
|
|
330
|
+
|
|
331
|
+
// Skip near-tangency base pairs.
|
|
332
|
+
if (!isStablePair(a0, ta, b0, tb)) continue
|
|
333
|
+
|
|
334
|
+
// IMPORTANT: skip ellipses here — GJK can flip at razor edges even after jitter checks.
|
|
335
|
+
if (isEllipse(a0) || isEllipse(b0)) continue
|
|
336
|
+
|
|
337
|
+
const base = checkCollision(a0, ta, b0, tb)
|
|
338
|
+
const deltaDeg = rrange(-180, 180)
|
|
339
|
+
|
|
340
|
+
// If the rotated result flickers under tiny perturbations, skip as unstable.
|
|
341
|
+
if (!isRotationStablePair(a0, ta, b0, tb, deltaDeg)) continue
|
|
342
|
+
|
|
343
|
+
const [a2, ta2] = applyRotation(a0, ta, deltaDeg)
|
|
344
|
+
const [b2, tb2] = applyRotation(b0, tb, deltaDeg)
|
|
345
|
+
const rotated = checkCollision(a2, ta2, b2, tb2)
|
|
346
|
+
if (base !== rotated) throw new Error(`rotation invariance failed at i=${i}`)
|
|
347
|
+
}
|
|
348
|
+
})
|
|
349
|
+
})
|