@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.js CHANGED
@@ -1702,6 +1702,7 @@ var Mascot = class {
1702
1702
  const visualTop = this.state.y - this.state.anchorY;
1703
1703
  return {
1704
1704
  id: this.id,
1705
+ positionX: this.state.x,
1705
1706
  x: visualLeft + (spriteWidth - width) / 2,
1706
1707
  y: visualTop + spriteHeight - height,
1707
1708
  width,
@@ -1771,15 +1772,31 @@ var Mascot = class {
1771
1772
  const movingRight = dx > 0;
1772
1773
  const sweptLeft = Math.min(previousBox.x, currentBox.x) - (movingRight ? 0 : MASCOT_COLLISION_LOOKAHEAD);
1773
1774
  const sweptRight = Math.max(previousBox.x + previousBox.width, currentBox.x + currentBox.width) + (movingRight ? MASCOT_COLLISION_LOOKAHEAD : 0);
1774
- const previousCenterX = previousBox.x + previousBox.width / 2;
1775
+ const overlappingSiblings = siblings.filter((sibling) => {
1776
+ if (sibling.id === this.id) return false;
1777
+ const overlapsVertically = currentBox.y < sibling.y + sibling.height && sibling.y < currentBox.y + currentBox.height;
1778
+ const overlapsHorizontally = previousBox.x < sibling.x + sibling.width && sibling.x < previousBox.x + previousBox.width;
1779
+ return overlapsVertically && (overlapsHorizontally || sibling.positionX === previous.x);
1780
+ });
1781
+ if (overlappingSiblings.length > 0) {
1782
+ const coincidentIds = [
1783
+ this.id,
1784
+ ...overlappingSiblings.filter((sibling) => sibling.positionX === previous.x).map((sibling) => sibling.id)
1785
+ ].sort();
1786
+ const escapeRight = coincidentIds.length > 1 ? coincidentIds.indexOf(this.id) >= coincidentIds.length / 2 : overlappingSiblings.reduce((sum, sibling) => sum + sibling.positionX, 0) / overlappingSiblings.length < previous.x;
1787
+ if (movingRight !== escapeRight) {
1788
+ this.state.x = previous.x;
1789
+ this.state.vx = 0;
1790
+ this.state.lookRight = !this.state.lookRight;
1791
+ }
1792
+ return;
1793
+ }
1775
1794
  const collision = siblings.some((sibling) => {
1776
1795
  if (sibling.id === this.id) return false;
1777
- const siblingCenterX = sibling.x + sibling.width / 2;
1778
- const isAhead = movingRight ? siblingCenterX >= previousCenterX : siblingCenterX <= previousCenterX;
1796
+ const isAhead = movingRight ? sibling.positionX > previous.x : sibling.positionX < previous.x;
1779
1797
  const overlapsVertically = currentBox.y < sibling.y + sibling.height && sibling.y < currentBox.y + currentBox.height;
1780
1798
  const crossesHorizontally = sweptLeft <= sibling.x + sibling.width && sibling.x <= sweptRight;
1781
- const wasAlreadyOverlapping = overlapsVertically && previousBox.x < sibling.x + sibling.width && sibling.x < previousBox.x + previousBox.width;
1782
- return isAhead && overlapsVertically && crossesHorizontally && !wasAlreadyOverlapping;
1799
+ return isAhead && overlapsVertically && crossesHorizontally;
1783
1800
  });
1784
1801
  if (!collision) return;
1785
1802
  this.state.x = previous.x;