feat: 1:1 drag tracking and rockets for spontaneous matches
moveDrag now targets the row under the pointer (floor of field y), clamped to the still stack, and swaps step by step to that row only. A short pull no longer jumps a full cell, and a stopped pointer moves nothing else. Launch-by-pulling-above-the-top is unchanged. Pointer coordinates are mapped through the CSS box and the 10×13 field, not canvas.width / app.tile, so a high-DPR backing store cannot inflate a small finger move into a full-column swipe. Spontaneous lines of 3+ after a cargo attach, a cluster merge, a ground landing or a settle/recolor become rockets, the same as a player-made match. A match inside an already flying cluster re-launches the whole cluster from its current position (same height as a player push). Hanging cargo after recolor still falls from rest.
@@ -496,6 +496,7 @@ GameCore.prototype.tick = function (dt)
496
496
{
497
497
var step = Math.min(SUBSTEP, left);
498
498
this.integrateFalling(step);
499
this.resolveFlyingMatches();
499
500
this.integrateClusters(step);
500
501
this.mergeFlyingClusters();
501
502
this.integrateManual(step);
@@ -708,8 +709,9 @@ GameCore.prototype.integrateClusters = function (dt)
708
709
}
709
710
710
711
this.catchFallingOntoCluster(cluster, members);
712
this.checkChainRelaunch(cluster);
711
713
712
if (cluster.phase === 'down')
714
if (cluster.phase === 'down' && this.clusters[cluster.id])
713
715
{ this.tryLandCluster(cluster, this.clusterMembers(cluster.id)); }
714
716
}
715
717
};
@@ -818,7 +820,8 @@ GameCore.prototype.mergeClusterGroup = function (clusters)
818
820
{ delete this.clusters[clusters[c].id]; }
819
821
}
820
822
this.packClusterOverlaps(keep);
821
if (keep.phase === 'down')
823
this.checkChainRelaunch(keep);
824
if (keep.phase === 'down' && this.clusters[keep.id])
822
825
{ this.tryLandCluster(keep, this.clusterMembers(keep.id)); }
823
826
};
824
827
@@ -1078,6 +1081,24 @@ GameCore.prototype.pushClusterColumn = function (clusterId, col)
1078
1081
return true;
1079
1082
};
1080
1083
1084
/**
1085
* After a cargo attach or a cluster merge (or any other mid-air state
1086
* change), turn spontaneous lines of 3+ into rockets and give the whole
1087
* already-flying cluster an extra launch from its current position —
1088
* the same re-launch as a player push that completes a row.
1089
*/
1090
GameCore.prototype.resolveFlyingMatches = function ()
1091
{
1092
var ids = Object.keys(this.clusters);
1093
for (var n = 0; n < ids.length; n++)
1094
{
1095
var cluster = this.clusters[ids[n]];
1096
if (!cluster || cluster.phase === 'landed')
1097
{ continue; }
1098
this.checkChainRelaunch(cluster);
1099
}
1100
};
1101
1081
1102
GameCore.prototype.checkChainRelaunch = function (cluster)
1082
1103
{
1083
1104
if (!this.clusters[cluster.id])
@@ -1696,38 +1717,25 @@ GameCore.prototype.moveDrag = function (y)
1696
1717
this.drag = null;
1697
1718
return;
1698
1719
}
1699
var dy = y - this.drag.pointerY;
1700
1720
this.drag.pointerY = y;
1701
if (this.drag.accum == null)
1702
{ this.drag.accum = 0; }
1703
this.drag.accum += dy;
1704
// One swap per tile of travel, triggered after a minimal SWAP_DISTANCE.
1705
// A single large move (fast swipe) walks every tile; none are skipped.
1706
var guard = 0;
1707
while (guard++ < this.height + 2
1708
&& (this.drag.accum >= SWAP_DISTANCE || this.drag.accum <= -SWAP_DISTANCE))
1709
{
1710
var dir = this.drag.accum > 0 ? 1 : -1;
1711
if (!this.swapOne(block, dir))
1712
{
1713
if (dir > 0)
1714
{ this.drag.accum = Math.min(this.drag.accum, SWAP_DISTANCE - 1e-9); }
1715
else
1716
{ this.drag.accum = Math.max(this.drag.accum, -(SWAP_DISTANCE - 1e-9)); }
1717
break;
1718
}
1719
this.drag.accum -= dir;
1720
// A short move (SWAP_DISTANCE < 1) leaves a negative leftover;
1721
// do not let that immediately swap back the other way.
1722
if ((dir > 0 && this.drag.accum < 0) || (dir < 0 && this.drag.accum > 0))
1723
{ this.drag.accum = 0; }
1724
if (!this.isColumnStill(block.col))
1725
{
1726
this.drag = null;
1727
return;
1728
}
1729
}
1721
// 1:1 tracking: the target row is the one under the pointer, clamped
1722
// to the still stack. Swap step by step with each neighbour, and stop
1723
// exactly there. When the pointer stops, nothing else moves.
1724
// Accumulated deltas are not used: a SWAP_DISTANCE (0.25) threshold
1725
// used to jump a full cell on a short pull, and one large event
1726
// could walk the entire column (the "jumps all the way" bug).
1730
1727
var top = this.columnStackTopRow(block.col);
1728
var bottom = this.columnStackBottomRow(block.col);
1729
var target = Math.floor(y + 1e-12);
1730
if (bottom < 0)
1731
{ bottom = 0; }
1732
if (target < bottom)
1733
{ target = bottom; }
1734
if (target > top)
1735
{ target = top; }
1736
this.swapToward(block, target);
1737
1738
top = this.columnStackTopRow(block.col);
1731
1739
var isTop = Math.abs(block.y - top) < ALIGN_EPS;
1732
1740
if (this.drag.startedAsTop)
1733
1741
{
@@ -1790,6 +1798,18 @@ GameCore.prototype.columnStackTopRow = function (col)
1790
1798
return top;
1791
1799
};
1792
1800
1801
GameCore.prototype.columnStackBottomRow = function (col)
1802
{
1803
var bottom = Infinity;
1804
var list = this.blocksInColumn(col);
1805
for (var i = 0; i < list.length; i++)
1806
{
1807
if (this.isGrounded(list[i]) && list[i].y < bottom)
1808
{ bottom = list[i].y; }
1809
}
1810
return bottom === Infinity ? 0 : bottom;
1811
};
1812
1793
1813
GameCore.prototype.swapToward = function (block, targetY)
1794
1814
{
1795
1815
var guard = 0;
@@ -496,6 +496,7 @@ GameCore.prototype.tick = function (dt)496
{496
{497
var step = Math.min(SUBSTEP, left);497
var step = Math.min(SUBSTEP, left);498
this.integrateFalling(step);498
this.integrateFalling(step);499
this.resolveFlyingMatches();499
this.integrateClusters(step);500
this.integrateClusters(step);500
this.mergeFlyingClusters();501
this.mergeFlyingClusters();501
this.integrateManual(step);502
this.integrateManual(step);@@ -708,8 +709,9 @@ GameCore.prototype.integrateClusters = function (dt)708
}709
}709
710
710
this.catchFallingOntoCluster(cluster, members);711
this.catchFallingOntoCluster(cluster, members);712
this.checkChainRelaunch(cluster);711
713
712
if (cluster.phase === 'down')714
if (cluster.phase === 'down' && this.clusters[cluster.id])713
{ this.tryLandCluster(cluster, this.clusterMembers(cluster.id)); }715
{ this.tryLandCluster(cluster, this.clusterMembers(cluster.id)); }714
}716
}715
};717
};@@ -818,7 +820,8 @@ GameCore.prototype.mergeClusterGroup = function (clusters)818
{ delete this.clusters[clusters[c].id]; }820
{ delete this.clusters[clusters[c].id]; }819
}821
}820
this.packClusterOverlaps(keep);822
this.packClusterOverlaps(keep);821
if (keep.phase === 'down')823
this.checkChainRelaunch(keep);824
if (keep.phase === 'down' && this.clusters[keep.id])822
{ this.tryLandCluster(keep, this.clusterMembers(keep.id)); }825
{ this.tryLandCluster(keep, this.clusterMembers(keep.id)); }823
};826
};824
827
@@ -1078,6 +1081,24 @@ GameCore.prototype.pushClusterColumn = function (clusterId, col)1078
return true;1081
return true;1079
};1082
};1080
1083
1084
/**1085
* After a cargo attach or a cluster merge (or any other mid-air state1086
* change), turn spontaneous lines of 3+ into rockets and give the whole1087
* already-flying cluster an extra launch from its current position —1088
* the same re-launch as a player push that completes a row.1089
*/1090
GameCore.prototype.resolveFlyingMatches = function ()1091
{1092
var ids = Object.keys(this.clusters);1093
for (var n = 0; n < ids.length; n++)1094
{1095
var cluster = this.clusters[ids[n]];1096
if (!cluster || cluster.phase === 'landed')1097
{ continue; }1098
this.checkChainRelaunch(cluster);1099
}1100
};1101
1081
GameCore.prototype.checkChainRelaunch = function (cluster)1102
GameCore.prototype.checkChainRelaunch = function (cluster)1082
{1103
{1083
if (!this.clusters[cluster.id])1104
if (!this.clusters[cluster.id])@@ -1696,38 +1717,25 @@ GameCore.prototype.moveDrag = function (y)1696
this.drag = null;1717
this.drag = null;1697
return;1718
return;1698
}1719
}1699
var dy = y - this.drag.pointerY;1700
this.drag.pointerY = y;1720
this.drag.pointerY = y;1701
if (this.drag.accum == null)1721
// 1:1 tracking: the target row is the one under the pointer, clamped1702
{ this.drag.accum = 0; }1722
// to the still stack. Swap step by step with each neighbour, and stop1703
this.drag.accum += dy;1723
// exactly there. When the pointer stops, nothing else moves.1704
// One swap per tile of travel, triggered after a minimal SWAP_DISTANCE.1724
// Accumulated deltas are not used: a SWAP_DISTANCE (0.25) threshold1705
// A single large move (fast swipe) walks every tile; none are skipped.1725
// used to jump a full cell on a short pull, and one large event1706
var guard = 0;1726
// could walk the entire column (the "jumps all the way" bug).1707
while (guard++ < this.height + 21708
&& (this.drag.accum >= SWAP_DISTANCE || this.drag.accum <= -SWAP_DISTANCE))1709
{1710
var dir = this.drag.accum > 0 ? 1 : -1;1711
if (!this.swapOne(block, dir))1712
{1713
if (dir > 0)1714
{ this.drag.accum = Math.min(this.drag.accum, SWAP_DISTANCE - 1e-9); }1715
else1716
{ this.drag.accum = Math.max(this.drag.accum, -(SWAP_DISTANCE - 1e-9)); }1717
break;1718
}1719
this.drag.accum -= dir;1720
// A short move (SWAP_DISTANCE < 1) leaves a negative leftover;1721
// do not let that immediately swap back the other way.1722
if ((dir > 0 && this.drag.accum < 0) || (dir < 0 && this.drag.accum > 0))1723
{ this.drag.accum = 0; }1724
if (!this.isColumnStill(block.col))1725
{1726
this.drag = null;1727
return;1728
}1729
}1730
var top = this.columnStackTopRow(block.col);1727
var top = this.columnStackTopRow(block.col);1728
var bottom = this.columnStackBottomRow(block.col);1729
var target = Math.floor(y + 1e-12);1730
if (bottom < 0)1731
{ bottom = 0; }1732
if (target < bottom)1733
{ target = bottom; }1734
if (target > top)1735
{ target = top; }1736
this.swapToward(block, target);1737
1738
top = this.columnStackTopRow(block.col);1731
var isTop = Math.abs(block.y - top) < ALIGN_EPS;1739
var isTop = Math.abs(block.y - top) < ALIGN_EPS;1732
if (this.drag.startedAsTop)1740
if (this.drag.startedAsTop)1733
{1741
{@@ -1790,6 +1798,18 @@ GameCore.prototype.columnStackTopRow = function (col)1790
return top;1798
return top;1791
};1799
};1792
1800
1801
GameCore.prototype.columnStackBottomRow = function (col)1802
{1803
var bottom = Infinity;1804
var list = this.blocksInColumn(col);1805
for (var i = 0; i < list.length; i++)1806
{1807
if (this.isGrounded(list[i]) && list[i].y < bottom)1808
{ bottom = list[i].y; }1809
}1810
return bottom === Infinity ? 0 : bottom;1811
};1812
1793
GameCore.prototype.swapToward = function (block, targetY)1813
GameCore.prototype.swapToward = function (block, targetY)1794
{1814
{1795
var guard = 0;1815
var guard = 0;@@ -539,11 +539,14 @@ function fieldFromEvent (e)
539
539
var rect = canvas.getBoundingClientRect();
540
540
if (rect.width <= 0 || rect.height <= 0)
541
541
{ return null; }
542
var x = (e.clientX - rect.left) * (canvas.width / rect.width);
543
var y = (e.clientY - rect.top) * (canvas.height / rect.height);
544
// Fractional column so beginDrag can snap across a nearby edge.
545
var col = x / app.tile;
546
var fieldY = (canvas.height - y) / app.tile;
542
// Map through the CSS box only. Using canvas.width / app.tile would
543
// scale the pointer by the backing-store ratio whenever that differs
544
// from the layout size (high-DPR devices), so a short finger move
545
// would look like a long swipe.
546
var width = Planet.FIELD_WIDTH;
547
var height = Planet.FIELD_HEIGHT;
548
var col = ((e.clientX - rect.left) / rect.width) * width;
549
var fieldY = (1 - (e.clientY - rect.top) / rect.height) * height;
547
550
return { col: col, y: fieldY };
548
551
}
549
552
@@ -539,11 +539,14 @@ function fieldFromEvent (e)539
var rect = canvas.getBoundingClientRect();539
var rect = canvas.getBoundingClientRect();540
if (rect.width <= 0 || rect.height <= 0)540
if (rect.width <= 0 || rect.height <= 0)541
{ return null; }541
{ return null; }542
var x = (e.clientX - rect.left) * (canvas.width / rect.width);542
// Map through the CSS box only. Using canvas.width / app.tile would543
var y = (e.clientY - rect.top) * (canvas.height / rect.height);543
// scale the pointer by the backing-store ratio whenever that differs544
// Fractional column so beginDrag can snap across a nearby edge.544
// from the layout size (high-DPR devices), so a short finger move545
var col = x / app.tile;545
// would look like a long swipe.546
var fieldY = (canvas.height - y) / app.tile;546
var width = Planet.FIELD_WIDTH;547
var height = Planet.FIELD_HEIGHT;548
var col = ((e.clientX - rect.left) / rect.width) * width;549
var fieldY = (1 - (e.clientY - rect.top) / rect.height) * height;547
return { col: col, y: fieldY };550
return { col: col, y: fieldY };548
}551
}549
552