@react-shimeji/core 0.3.4 → 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 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,11 +1819,28 @@ 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 previousCenterX = previousBox.x + previousBox.width / 2;
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 siblingCenterX = sibling.x + sibling.width / 2;
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
1846
  return isAhead && overlapsVertically && crossesHorizontally;