@react-shimeji/core 0.3.5 → 0.3.6
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/dist/index.cjs +22 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +22 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1749,6 +1749,7 @@ var Mascot = class {
|
|
|
1749
1749
|
const visualTop = this.state.y - this.state.anchorY;
|
|
1750
1750
|
return {
|
|
1751
1751
|
id: this.id,
|
|
1752
|
+
positionX: this.state.x,
|
|
1752
1753
|
x: visualLeft + (spriteWidth - width) / 2,
|
|
1753
1754
|
y: visualTop + spriteHeight - height,
|
|
1754
1755
|
width,
|
|
@@ -1818,15 +1819,31 @@ var Mascot = class {
|
|
|
1818
1819
|
const movingRight = dx > 0;
|
|
1819
1820
|
const sweptLeft = Math.min(previousBox.x, currentBox.x) - (movingRight ? 0 : MASCOT_COLLISION_LOOKAHEAD);
|
|
1820
1821
|
const sweptRight = Math.max(previousBox.x + previousBox.width, currentBox.x + currentBox.width) + (movingRight ? MASCOT_COLLISION_LOOKAHEAD : 0);
|
|
1821
|
-
const
|
|
1822
|
+
const overlappingSiblings = siblings.filter((sibling) => {
|
|
1823
|
+
if (sibling.id === this.id) return false;
|
|
1824
|
+
const overlapsVertically = currentBox.y < sibling.y + sibling.height && sibling.y < currentBox.y + currentBox.height;
|
|
1825
|
+
const overlapsHorizontally = previousBox.x < sibling.x + sibling.width && sibling.x < previousBox.x + previousBox.width;
|
|
1826
|
+
return overlapsVertically && (overlapsHorizontally || sibling.positionX === previous.x);
|
|
1827
|
+
});
|
|
1828
|
+
if (overlappingSiblings.length > 0) {
|
|
1829
|
+
const coincidentIds = [
|
|
1830
|
+
this.id,
|
|
1831
|
+
...overlappingSiblings.filter((sibling) => sibling.positionX === previous.x).map((sibling) => sibling.id)
|
|
1832
|
+
].sort();
|
|
1833
|
+
const escapeRight = coincidentIds.length > 1 ? coincidentIds.indexOf(this.id) >= coincidentIds.length / 2 : overlappingSiblings.reduce((sum, sibling) => sum + sibling.positionX, 0) / overlappingSiblings.length < previous.x;
|
|
1834
|
+
if (movingRight !== escapeRight) {
|
|
1835
|
+
this.state.x = previous.x;
|
|
1836
|
+
this.state.vx = 0;
|
|
1837
|
+
this.state.lookRight = !this.state.lookRight;
|
|
1838
|
+
}
|
|
1839
|
+
return;
|
|
1840
|
+
}
|
|
1822
1841
|
const collision = siblings.some((sibling) => {
|
|
1823
1842
|
if (sibling.id === this.id) return false;
|
|
1824
|
-
const
|
|
1825
|
-
const isAhead = movingRight ? siblingCenterX >= previousCenterX : siblingCenterX <= previousCenterX;
|
|
1843
|
+
const isAhead = movingRight ? sibling.positionX > previous.x : sibling.positionX < previous.x;
|
|
1826
1844
|
const overlapsVertically = currentBox.y < sibling.y + sibling.height && sibling.y < currentBox.y + currentBox.height;
|
|
1827
1845
|
const crossesHorizontally = sweptLeft <= sibling.x + sibling.width && sibling.x <= sweptRight;
|
|
1828
|
-
|
|
1829
|
-
return isAhead && overlapsVertically && crossesHorizontally && !wasAlreadyOverlapping;
|
|
1846
|
+
return isAhead && overlapsVertically && crossesHorizontally;
|
|
1830
1847
|
});
|
|
1831
1848
|
if (!collision) return;
|
|
1832
1849
|
this.state.x = previous.x;
|