chore: rebuild game.js with smooth launch/land arcs (t1134–t1136)
@@ -2695,7 +2695,8 @@ GameCore.prototype.cullOffTop = function ()
2695
2695
id: block.id,
2696
2696
color: block.color,
2697
2697
col: block.col,
2698
y: block.y
2698
y: block.y,
2699
vy: block.vy
2699
2700
});
2700
2701
this.score += 1;
2701
2702
this.removeBlock(block);
@@ -4567,7 +4568,7 @@ Online.playerFieldRect = function ()
4567
4568
4568
4569
/**
4569
4570
* True if (x, y) is inside the field's interior. The top edge (a few
4570
* pixels) is not interior: that is where arcs may land (t1128).
4571
* pixels) is not interior: launch and landing may use that band.
4571
4572
*/
4572
4573
Online.pointInFieldInterior = function (x, y, field, slop)
4573
4574
{
@@ -4578,107 +4579,363 @@ Online.pointInFieldInterior = function (x, y, field, slop)
4578
4579
&& y > field.top + slop && y < field.bottom - 0.5;
4579
4580
};
4580
4581
4582
/** Cubic Bezier C(t), t ∈ [0, 1]. C¹ (in fact C^∞) on (0, 1) — no corners (t1134). */
4583
Online.cubicBezier = function (p0, p1, p2, p3, t)
4584
{
4585
if (t < 0)
4586
{ t = 0; }
4587
if (t > 1)
4588
{ t = 1; }
4589
var u = 1 - t;
4590
var a = u * u * u;
4591
var b = 3 * u * u * t;
4592
var c = 3 * u * t * t;
4593
var d = t * t * t;
4594
return {
4595
x: a * p0.x + b * p1.x + c * p2.x + d * p3.x,
4596
y: a * p0.y + b * p1.y + c * p2.y + d * p3.y
4597
};
4598
};
4599
4600
/** C'(t) = 3(1−t)²(P1−P0) + 6(1−t)t(P2−P1) + 3t²(P3−P2). */
4601
Online.cubicBezierDeriv = function (p0, p1, p2, p3, t)
4602
{
4603
if (t < 0)
4604
{ t = 0; }
4605
if (t > 1)
4606
{ t = 1; }
4607
var u = 1 - t;
4608
return {
4609
x: 3 * u * u * (p1.x - p0.x) + 6 * u * t * (p2.x - p1.x) + 3 * t * t * (p3.x - p2.x),
4610
y: 3 * u * u * (p1.y - p0.y) + 6 * u * t * (p2.y - p1.y) + 3 * t * t * (p3.y - p2.y)
4611
};
4612
};
4613
4581
4614
/**
4582
* Waypoints that route a player↔enemy arc around the field, never
4583
* through its interior: up the outside, across above the top edge,
4584
* then into the target (t1128). If both ends already sit at or above
4585
* the top, a simple two-point path is enough.
4615
* Hermite parameter with p(0)=0, p(1)=1, p'(0)=v0, p'(1)=v1.
4616
* v0=v1=1 is linear (constant speed in t, no endpoint halt).
4586
4617
*/
4587
Online.waypointsAroundField = function (start, end, field, clearance)
4618
Online.smoothParam = function (t, v0, v1)
4619
{
4620
if (t < 0)
4621
{ return 0; }
4622
if (t > 1)
4623
{ return 1; }
4624
if (v0 == null)
4625
{ v0 = 1; }
4626
if (v1 == null)
4627
{ v1 = 1; }
4628
var b = 3 - 2 * v0 - v1;
4629
var a = v0 + v1 - 2;
4630
return ((a * t + b) * t + v0) * t;
4631
};
4632
4633
/**
4634
* A simple up-and-over cubic, used when there is no field to route
4635
* around (enemy→enemy) or both ends already sit above the apex.
4636
*/
4637
Online._singleCubic = function (start, end, apexY, opts)
4638
{
4639
opts = opts || {};
4640
var rise = Math.max(40, Math.abs(start.y - apexY) * 0.9);
4641
if (opts.startSpeedPx)
4642
{ rise = Math.max(rise, opts.startSpeedPx); }
4643
var fall = Math.max(40, Math.abs(end.y - apexY) * 0.9);
4644
if (opts.endSpeedPx)
4645
{ fall = Math.max(40, opts.endSpeedPx); }
4646
var p1 = { x: start.x, y: Math.min(start.y - rise, apexY) };
4647
var p2 = { x: end.x, y: Math.min(end.y - fall, apexY) };
4648
return { p0: start, p1: p1, p2: p2, p3: end, apexY: apexY };
4649
};
4650
4651
/**
4652
* Smooth C¹ path: rise up (launch column or outside), cruise above
4653
* the field, dive into the landing column (t1134 / t1135). Joints
4654
* are quarter-turn cubics with matching tangents, so there are no
4655
* corners and no speed jerks. The curve may use the launch and
4656
* landing corridors but does not cut across the field interior.
4657
*/
4658
Online.makeAroundCurve = function (start, end, field, opts)
4588
4659
{
4589
if (!start || !end)
4590
{ return [start || { x: 0, y: 0 }, end || { x: 0, y: 0 }]; }
4660
opts = opts || {};
4661
if (!start)
4662
{ start = { x: 0, y: 0 }; }
4663
if (!end)
4664
{ end = { x: 0, y: 0 }; }
4665
var clearance = opts.clearance || 80;
4591
4666
if (!field)
4592
{ return [start, end]; }
4593
clearance = clearance || 64;
4667
{
4668
var looseApex = Math.min(start.y, end.y) - Math.max(40, clearance * 0.5);
4669
if (looseApex < 8)
4670
{ looseApex = Math.min(start.y, end.y) - 24; }
4671
return this._singleCubic(start, end, looseApex, opts);
4672
}
4594
4673
var top = field.top;
4595
4674
var left = field.left;
4596
4675
var right = field.right;
4597
var pad = 10;
4598
var apexY = Math.min(start.y, end.y, top) - clearance;
4676
var apexY = top - clearance;
4599
4677
if (apexY < 8)
4600
4678
{ apexY = Math.max(8, top - Math.max(24, clearance * 0.5)); }
4601
4679
4602
if (start.y <= top + 6 && end.y <= top + 6)
4603
{ return [start, end]; }
4680
if (start.y <= apexY + 8 && end.y <= apexY + 8)
4681
{ return this._singleCubic(start, end, apexY, opts); }
4604
4682
4605
var w1x = start.x;
4606
var w2x = end.x;
4607
if (start.x < left)
4608
{ w1x = Math.min(start.x, left - pad); }
4609
else if (start.x > right)
4610
{ w1x = Math.max(start.x, right + pad); }
4611
if (end.x < left)
4612
{ w2x = Math.min(end.x, left - pad); }
4613
else if (end.x > right)
4614
{ w2x = Math.max(end.x, right + pad); }
4683
var pad = 14;
4684
var dir = end.x >= start.x ? 1 : -1;
4685
var span = Math.abs(end.x - start.x);
4686
var horiz = Math.max(28, Math.min(80, span * 0.15 + 8));
4687
function outsideX (x)
4688
{
4689
if (x < left + 8)
4690
{ return Math.min(x, left - pad); }
4691
if (x > right - 8)
4692
{ return Math.max(x, right + pad); }
4693
return x;
4694
}
4695
var riseX = outsideX(start.x);
4696
var diveX = outsideX(end.x);
4697
var segments = [];
4615
4698
4616
return [
4617
start,
4618
{ x: w1x, y: apexY },
4619
{ x: w2x, y: apexY },
4620
end
4621
];
4699
// Rise ends already turned toward the cruise, at apex.
4700
var riseEnd = { x: riseX + dir * horiz, y: apexY };
4701
if (start.y > apexY + 4)
4702
{
4703
var p1 = { x: start.x, y: apexY };
4704
var p2 = { x: riseX, y: apexY };
4705
segments.push({ p0: start, p1: p1, p2: p2, p3: riseEnd });
4706
}
4707
else
4708
{ riseEnd = { x: start.x, y: Math.min(start.y, apexY) }; }
4709
4710
// Cruise stays on the apex line (convex hull is above the field).
4711
var diveStart = { x: diveX - dir * horiz, y: apexY };
4712
if (Math.abs(riseEnd.x - diveStart.x) > 4 || Math.abs(riseEnd.y - diveStart.y) > 4)
4713
{
4714
// Keep the cruise direction consistent; if the two joints
4715
// would cross, just connect them directly.
4716
var cdir = diveStart.x >= riseEnd.x ? 1 : -1;
4717
var c1 = { x: riseEnd.x + cdir * horiz, y: riseEnd.y };
4718
if (c1.y > apexY)
4719
{ c1.y = apexY; }
4720
var c2 = { x: diveStart.x - cdir * horiz, y: diveStart.y };
4721
segments.push({ p0: { x: riseEnd.x, y: riseEnd.y }, p1: c1, p2: c2, p3: diveStart });
4722
}
4723
4724
if (end.y > apexY + 4 || Math.abs(end.x - (diveStart.x + dir * horiz)) > 2)
4725
{
4726
var u0 = (Math.abs(riseEnd.x - diveStart.x) > 4 || segments.length === 0)
4727
? diveStart
4728
: riseEnd;
4729
if (segments.length && segments[segments.length - 1].p3.x === u0.x
4730
&& segments[segments.length - 1].p3.y === u0.y)
4731
{ /* already joined */ }
4732
else if (segments.length === 0)
4733
{ u0 = riseEnd; }
4734
var u1 = { x: u0.x + dir * horiz, y: u0.y };
4735
var fall = Math.max(24, Math.abs(end.y - apexY) * 0.45);
4736
if (opts.endSpeedPx)
4737
{
4738
// |P3-P2| so arrival ≈ fallSpeed after equal-param scaling.
4739
// velocity = 3*|P3-P2|*n*v1/duration; endSpeedPx is
4740
// (cells*px*duration)/3, so |P3-P2| = endSpeedPx/(n*v1).
4741
var nEst = Math.max(1, segments.length + 1);
4742
fall = Math.max(20, opts.endSpeedPx / (nEst * 0.85));
4743
}
4744
var u2 = { x: end.x, y: end.y - fall };
4745
// P2 may sit between the apex and the end (slower arrival);
4746
// only clamp if it would pass the end or fly far past the apex.
4747
if (u2.y < apexY - 240)
4748
{ u2.y = apexY - 240; }
4749
if (u2.y > end.y - 8)
4750
{ u2.y = end.y - 8; }
4751
segments.push({ p0: u0, p1: u1, p2: u2, p3: end });
4752
}
4753
4754
if (segments.length === 0)
4755
{ return this._singleCubic(start, end, apexY, opts); }
4756
if (segments.length === 1 && !segments[0].p0)
4757
{ return this._singleCubic(start, end, apexY, opts); }
4758
4759
return { segments: segments, apexY: apexY, p0: start, p3: end };
4622
4760
};
4623
4761
4624
/**
4625
* Point at parameter u ∈ [0, 1] along a polyline, with a small upward
4626
* bulge on each segment so the path reads as a "boogje".
4627
*/
4628
Online.pointOnPath = function (points, u)
4762
Online._measureCurve = function (curve)
4629
4763
{
4630
u = u < 0 ? 0 : (u > 1 ? 1 : u);
4631
if (!points || !points.length)
4632
{ return { x: 0, y: 0 }; }
4633
if (points.length === 1)
4634
{ return { x: points[0].x, y: points[0].y }; }
4764
if (!curve.segments)
4765
{ return curve; }
4635
4766
var lens = [];
4636
4767
var total = 0;
4637
for (var i = 1; i < points.length; i++)
4768
for (var i = 0; i < curve.segments.length; i++)
4638
4769
{
4639
var dx = points[i].x - points[i - 1].x;
4640
var dy = points[i].y - points[i - 1].y;
4641
var L = Math.sqrt(dx * dx + dy * dy);
4642
if (L < 1)
4643
{ L = 1; }
4770
var L = this._segLen(curve.segments[i]);
4644
4771
lens.push(L);
4645
4772
total += L;
4646
4773
}
4647
var dist = u * total;
4648
var acc = 0;
4649
for (var i = 0; i < lens.length; i++)
4774
curve.lens = lens;
4775
curve.totalLen = Math.max(total, 1);
4776
return curve;
4777
};
4778
4779
Online._segLen = function (seg, steps)
4780
{
4781
steps = steps || 10;
4782
var len = 0;
4783
var prev = this.cubicBezier(seg.p0, seg.p1, seg.p2, seg.p3, 0);
4784
for (var i = 1; i <= steps; i++)
4650
4785
{
4651
if (acc + lens[i] >= dist || i === lens.length - 1)
4652
{
4653
var t = (dist - acc) / lens[i];
4654
if (t < 0)
4655
{ t = 0; }
4656
if (t > 1)
4657
{ t = 1; }
4658
var a = points[i];
4659
var b = points[i + 1];
4660
var bump = 4 * 16 * t * (1 - t);
4661
return {
4662
x: a.x + (b.x - a.x) * t,
4663
y: a.y + (b.y - a.y) * t - bump
4664
};
4665
}
4666
acc += lens[i];
4786
var p = this.cubicBezier(seg.p0, seg.p1, seg.p2, seg.p3, i / steps);
4787
var dx = p.x - prev.x;
4788
var dy = p.y - prev.y;
4789
len += Math.sqrt(dx * dx + dy * dy);
4790
prev = p;
4791
}
4792
return Math.max(len, 1);
4793
};
4794
4795
/**
4796
* Equal-parameter split across segments so matching local C'(t)
4797
* at joints also matches dP/du (no speed jerk).
4798
*/
4799
Online._curveSegmentAt = function (curve, u)
4800
{
4801
if (!curve)
4802
{ return null; }
4803
if (!curve.segments)
4804
{
4805
return { seg: curve, t: u < 0 ? 0 : (u > 1 ? 1 : u), scale: 1 };
4667
4806
}
4668
var last = points[points.length - 1];
4669
return { x: last.x, y: last.y };
4807
var segs = curve.segments;
4808
var n = segs.length;
4809
if (u <= 0)
4810
{ return { seg: segs[0], t: 0, scale: n }; }
4811
if (u >= 1)
4812
{ return { seg: segs[n - 1], t: 1, scale: n }; }
4813
var at = u * n;
4814
var i = Math.floor(at);
4815
if (i >= n)
4816
{ i = n - 1; }
4817
var t = at - i;
4818
return { seg: segs[i], t: t, scale: n };
4819
};
4820
4821
/** Point on a (possibly multi-segment C¹) curve at u ∈ [0, 1]. */
4822
Online.curvePoint = function (curve, u)
4823
{
4824
var at = this._curveSegmentAt(curve, u);
4825
if (!at)
4826
{ return { x: 0, y: 0 }; }
4827
var s = at.seg;
4828
if (s && s.p1)
4829
{ return this.cubicBezier(s.p0, s.p1, s.p2, s.p3, at.t); }
4830
if (s && s.p0)
4831
{ return { x: s.p0.x, y: s.p0.y }; }
4832
return { x: 0, y: 0 };
4833
};
4834
4835
/** dP/du of the curve (C¹ across joints). */
4836
Online.curveDeriv = function (curve, u)
4837
{
4838
var at = this._curveSegmentAt(curve, u);
4839
if (!at || !at.seg || !at.seg.p1)
4840
{ return { x: 0, y: 0 }; }
4841
var s = at.seg;
4842
var d = this.cubicBezierDeriv(s.p0, s.p1, s.p2, s.p3, at.t);
4843
return { x: d.x * at.scale, y: d.y * at.scale };
4670
4844
};
4671
4845
4672
/** Sample a player↔enemy path; used by tests and the ticker. */
4846
/**
4847
* Sample the smooth around-field curve at u ∈ [0, 1] (t1134).
4848
* `clearance` may be a number or an options object.
4849
*/
4673
4850
Online.aroundFieldPoint = function (start, end, u, field, clearance)
4674
4851
{
4675
var pts = this.waypointsAroundField(start, end, field, clearance);
4676
if (pts.length === 2)
4852
var opts = (clearance && typeof clearance === 'object') ? clearance : { clearance: clearance };
4853
var curve = opts.curve || this.makeAroundCurve(start, end, field, opts);
4854
return this.curvePoint(curve, u);
4855
};
4856
4857
/** Guide points (start, joints, end) for older tests. */
4858
Online.waypointsAroundField = function (start, end, field, clearance)
4859
{
4860
var c = this.makeAroundCurve(start, end, field, { clearance: clearance || 64 });
4861
if (c.segments && c.segments.length)
4862
{
4863
var pts = [{ x: c.segments[0].p0.x, y: c.segments[0].p0.y }];
4864
for (var i = 0; i < c.segments.length; i++)
4865
{ pts.push({ x: c.segments[i].p3.x, y: c.segments[i].p3.y }); }
4866
return pts;
4867
}
4868
return [c.p0, c.p1, c.p2, c.p3];
4869
};
4870
4871
Online.pointOnPath = function (points, u)
4872
{
4873
// Legacy polyline; new flights use cubicBezier.
4874
u = u < 0 ? 0 : (u > 1 ? 1 : u);
4875
if (!points || !points.length)
4876
{ return { x: 0, y: 0 }; }
4877
if (points.length === 4 && points[0] && points[3])
4878
{ return this.cubicBezier(points[0], points[1], points[2], points[3], u); }
4879
if (points.length === 1)
4880
{ return { x: points[0].x, y: points[0].y }; }
4881
var n = points.length - 1;
4882
var at = u * n;
4883
var i = Math.floor(at);
4884
if (i >= n)
4885
{ i = n - 1; }
4886
var t = at - i;
4887
var a = points[i];
4888
var b = points[i + 1];
4889
return { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t };
4890
};
4891
4892
/** Viewport centre of a field cell (y=0 is the bottom row). */
4893
Online.cellViewport = function (col, y, rect)
4894
{
4895
if (!rect)
4677
4896
{
4678
var h = this.arcHeight(start, end);
4679
return this.arcPoint(start, end, u, h);
4897
var field = this.playerFieldRect();
4898
if (!field)
4899
{ return { x: 0, y: 0 }; }
4900
rect = field;
4680
4901
}
4681
return this.pointOnPath(pts, u);
4902
var w = rect.width != null ? rect.width : (rect.right - rect.left);
4903
var h = rect.height != null ? rect.height : (rect.bottom - rect.top);
4904
return {
4905
x: rect.left + ((col + 0.5) / 10) * w,
4906
y: rect.top + (1 - (y + 0.5) / 13) * h
4907
};
4908
};
4909
4910
/** Handoff point of an incoming garbage block: y = 13, just into the column (t1135). */
4911
Online.fieldEntry = function (col)
4912
{
4913
return this.cellViewport(col == null ? 4.5 : col, 13);
4914
};
4915
4916
Online.miniCellViewport = function (playerId, col, y)
4917
{
4918
var el = this.miniElement(playerId);
4919
var canvas = el && (el.querySelector ? el.querySelector('canvas') : null);
4920
var box = canvas || el;
4921
if (!box || !box.getBoundingClientRect)
4922
{ return { x: window.innerWidth / 2, y: 48 }; }
4923
return this.cellViewport(col == null ? 4.5 : col, y == null ? 13 : y, box.getBoundingClientRect());
4924
};
4925
4926
Online._fallSpeedPx = function (field, duration)
4927
{
4928
var px = 40;
4929
if (field && field.height)
4930
{ px = field.height / 13; }
4931
else if (typeof app !== 'undefined' && app.tile)
4932
{ px = app.tile; }
4933
var cells = 13 / 3;
4934
if (typeof app !== 'undefined' && app.planet && app.planet.fallSpeed)
4935
{ cells = app.planet.fallSpeed; }
4936
duration = duration || this.FLIGHT_DURATION;
4937
// Distance of P2 from P3 so C'(1)/duration ≈ fall speed (t1135).
4938
return (cells * px * duration) / 3;
4682
4939
};
4683
4940
4684
4941
Online.rememberLandCol = function (id, col)
@@ -4746,17 +5003,17 @@ Online._miniAnchor = function (playerId, dir)
4746
5003
4747
5004
Online._fieldTop = function (col)
4748
5005
{
4749
return this._flightStart(col);
5006
return this.fieldEntry(col);
4750
5007
};
4751
5008
4752
5009
/**
4753
5010
* Animate shot results. `locals` is a map of client_id → {col, y, color,
4754
5011
* startX, startY, from_id} in viewport pixels.
4755
5012
*
4756
* Visual-only (t1125): a parabolic arc whose scale goes from mini-cell
4757
* to full tile (or the reverse). Enemy-to-enemy arcs stay small and
4758
* are drawn behind the player's field. Delivery timing is unchanged;
4759
* a late-seen flight starts mid-arc via `age`.
5013
* Visual-only: a smooth cubic that leaves the real cell, arcs around
5014
* the field, and dives into the landing column at the spawn pose
5015
* (t1134 / t1135). Enemy-to-enemy arcs stay small and are drawn
5016
* behind the player's field. A late-seen flight starts mid-arc via `age`.
4760
5017
*/
4761
5018
Online.spawnFlights = function (results, locals)
4762
5019
{
@@ -4767,6 +5024,8 @@ Online.spawnFlights = function (results, locals)
4767
5024
{ return; }
4768
5025
if (!this._flightSeen)
4769
5026
{ this._flightSeen = Object.create(null); }
5027
if (!this._previewIds)
5028
{ this._previewIds = Object.create(null); }
4770
5029
var now = performance.now();
4771
5030
var full = this._fullTileSize();
4772
5031
for (var i = 0; i < results.length; i++)
@@ -4774,7 +5033,18 @@ Online.spawnFlights = function (results, locals)
4774
5033
var r = results[i];
4775
5034
var sid = String(r.id != null ? r.id : (r.client_id || ('tmp-' + i)));
4776
5035
if (this._flightSeen[sid])
4777
{ continue; }
5036
{
5037
if (this._previewIds[sid])
5038
{
5039
var existing = this._findFlight(sid);
5040
if (existing)
5041
{
5042
var meta0 = locals[r.client_id] || locals[sid] || {};
5043
this.retargetFlight(existing, r, meta0, now);
5044
}
5045
}
5046
continue;
5047
}
4778
5048
this._flightSeen[sid] = now;
4779
5049
4780
5050
var meta = locals[r.client_id] || locals[sid] || {};
@@ -4801,11 +5071,15 @@ Online.spawnFlights = function (results, locals)
4801
5071
{ this.rememberLandCol(r.client_id, landCol); }
4802
5072
}
4803
5073
5074
var startCol = meta.col != null ? meta.col : r.col;
5075
var startY = meta.y != null ? meta.y : r.y;
4804
5076
var start;
4805
5077
if (meta.startX != null && isFinite(meta.startX))
4806
5078
{ start = { x: meta.startX, y: meta.startY }; }
4807
5079
else if (kind === 'player-to-enemy' || kind === 'player-miss')
4808
{ start = this._flightStart(meta.col != null ? meta.col : r.col); }
5080
{ start = this._flightStart(startCol, startY); }
5081
else if (startCol != null || startY != null)
5082
{ start = this.miniCellViewport(fromId, startCol, startY != null ? startY : 12); }
4809
5083
else
4810
5084
{ start = this._miniAnchor(fromId, 'out'); }
4811
5085
@@ -4813,7 +5087,7 @@ Online.spawnFlights = function (results, locals)
4813
5087
if (miss)
4814
5088
{ end = this._missEnd(start, kind === 'enemy-miss'); }
4815
5089
else if (kind === 'enemy-to-player')
4816
{ end = this._fieldTop(landCol != null ? landCol : 4.5); }
5090
{ end = this.fieldEntry(landCol != null ? landCol : 4.5); }
4817
5091
else
4818
5092
{ end = this._targetEnd(targetId, start, landCol); }
4819
5093
@@ -4874,7 +5148,14 @@ Online.spawnFlights = function (results, locals)
4874
5148
: this.arcHeight(start, end);
4875
5149
var field = this.playerFieldRect();
4876
5150
var around = !miss && (kind === 'enemy-to-player' || kind === 'player-to-enemy');
4877
var waypoints = around ? this.waypointsAroundField(start, end, field, height * 0.45) : null;
5151
var clearance = Math.max(64, height * 0.45);
5152
var endSpeed = this._fallSpeedPx(field, duration / 1000);
5153
var curve = miss ? null : this.makeAroundCurve(start, end, around ? field : null, {
5154
clearance: clearance,
5155
startSpeedPx: endSpeed,
5156
endSpeedPx: endSpeed,
5157
duration: duration / 1000
5158
});
4878
5159
this._flights.push({
4879
5160
el: el,
4880
5161
start: start,
@@ -4883,16 +5164,16 @@ Online.spawnFlights = function (results, locals)
4883
5164
height: height,
4884
5165
t0: t0,
4885
5166
duration: duration,
4886
spin: (Math.random() * 2 - 1) * 720,
5167
spin: miss ? ((Math.random() * 2 - 1) * 720) : ((Math.random() * 2 - 1) * 120),
4887
5168
miss: miss,
4888
5169
kind: kind,
4889
5170
startScale: startScale,
4890
5171
endScale: endScale,
4891
angle: Math.random() * 360,
5172
angle: 0,
4892
5173
id: sid,
4893
5174
landCol: landCol,
4894
5175
field: field,
4895
waypoints: waypoints,
5176
curve: curve,
4896
5177
color: flightColor
4897
5178
});
4898
5179
}
@@ -4909,30 +5190,17 @@ Online.rememberFlightLocal = function (shot, startX, startY)
4909
5190
color: shot.color,
4910
5191
startX: startX,
4911
5192
startY: startY,
4912
from_id: shot.from_id
5193
from_id: shot.from_id,
5194
land_col: shot.land_col,
5195
vy: shot.vy
4913
5196
};
4914
5197
};
4915
5198
4916
Online._flightStart = function (col)
5199
Online._flightStart = function (col, y)
4917
5200
{
4918
var appRef = typeof app !== 'undefined' ? app : null;
4919
if (appRef && appRef.scene && appRef.scene.canvas)
4920
{
4921
var canvas = appRef.scene.canvas;
4922
var rect = canvas.getBoundingClientRect();
4923
var c = col == null ? 4.5 : col;
4924
return {
4925
x: rect.left + (c + 0.5) * (rect.width / 10),
4926
y: rect.top + 4
4927
};
4928
}
4929
var field = document.querySelector('canvas');
4930
if (field)
4931
{
4932
var rect = field.getBoundingClientRect();
4933
return { x: rect.left + rect.width / 2, y: rect.top };
4934
}
4935
return { x: window.innerWidth / 2, y: window.innerHeight * 0.3 };
5201
if (y == null || !isFinite(y))
5202
{ y = 12; }
5203
return this.cellViewport(col == null ? 4.5 : col, y);
4936
5204
};
4937
5205
4938
5206
Online._targetEnd = function (targetId, start, col)
@@ -4940,12 +5208,8 @@ Online._targetEnd = function (targetId, start, col)
4940
5208
var el = targetId && this.miniElement(targetId);
4941
5209
if (el)
4942
5210
{
4943
var canvas = el.querySelector('canvas') || el;
4944
var r = canvas.getBoundingClientRect();
4945
var x = r.left + r.width / 2;
4946
if (col != null && isFinite(col))
4947
{ x = r.left + ((col + 0.5) / 10) * r.width; }
4948
return { x: x, y: r.top + 4 };
5211
// Slightly inside the mini, in the landing column (t1135).
5212
return this.miniCellViewport(targetId, col, 12);
4949
5213
}
4950
5214
return { x: start.x + (Math.random() - 0.5) * 80, y: 40 };
4951
5215
};
@@ -4980,6 +5244,251 @@ Online._hitCtrl = function (start, end)
4980
5244
};
4981
5245
};
4982
5246
5247
Online._findFlight = function (sid)
5248
{
5249
sid = String(sid);
5250
if (!this._flights)
5251
{ return null; }
5252
for (var i = 0; i < this._flights.length; i++)
5253
{
5254
if (String(this._flights[i].id) === sid)
5255
{ return this._flights[i]; }
5256
}
5257
return null;
5258
};
5259
5260
/**
5261
* Early visual takeover: a flying rocket near the top of a field
5262
* becomes a flight sprite at its exact cell, so it is seen flying
5263
* *out* rather than popping in above the canvas (t1134). When the
5264
* shot is later dispatched, `retargetFlight` picks up from the
5265
* current pose and aims at the real landing column.
5266
*/
5267
Online.previewExit = function (info)
5268
{
5269
if (!info || info.id == null)
5270
{ return; }
5271
var sid = String(info.id);
5272
if (!this._flights)
5273
{ this._flights = []; }
5274
if (!this._flightSeen)
5275
{ this._flightSeen = Object.create(null); }
5276
if (!this._previewIds)
5277
{ this._previewIds = Object.create(null); }
5278
if (this._previewIds[sid] || this._flightSeen[sid])
5279
{ return; }
5280
var front = document.getElementById('flights');
5281
if (!front || !info.start)
5282
{ return; }
5283
var start = info.start;
5284
var field = this.playerFieldRect();
5285
var clearance = 80;
5286
if (typeof MiniLayout !== 'undefined' && MiniLayout.ARC_TOP_PAD)
5287
{ clearance = Math.max(clearance, MiniLayout.ARC_TOP_PAD * 0.7); }
5288
var apexY = (field ? field.top : start.y) - clearance;
5289
if (apexY < 8)
5290
{ apexY = Math.max(8, start.y - 80); }
5291
var end = { x: start.x, y: apexY };
5292
var duration = this.FLIGHT_DURATION * 1000;
5293
var full = this._fullTileSize();
5294
var el = document.createElement('img');
5295
el.src = colorSpriteUrl(info.color);
5296
el.alt = '';
5297
el.className = 'flight';
5298
el.style.width = full + 'px';
5299
el.style.height = full + 'px';
5300
front.appendChild(el);
5301
var endSpeed = this._fallSpeedPx(field, this.FLIGHT_DURATION);
5302
var curve = this.makeAroundCurve(start, end, info.from_id ? null : field, {
5303
clearance: clearance,
5304
startSpeedPx: endSpeed,
5305
endSpeedPx: endSpeed
5306
});
5307
var now = performance.now();
5308
var mini = info.from_id ? (this._miniCellSize(info.from_id) / full) : 1;
5309
if (mini < 0.12)
5310
{ mini = 0.2; }
5311
this._flights.push({
5312
el: el,
5313
start: start,
5314
end: end,
5315
ctrl: null,
5316
height: clearance,
5317
t0: now,
5318
duration: duration,
5319
spin: (Math.random() * 2 - 1) * 90,
5320
miss: false,
5321
kind: info.from_id ? 'enemy-to-enemy' : 'player-to-enemy',
5322
startScale: mini,
5323
endScale: mini,
5324
angle: 0,
5325
id: sid,
5326
landCol: null,
5327
field: field,
5328
curve: curve,
5329
preview: true,
5330
color: info.color,
5331
from_id: info.from_id || null
5332
});
5333
this._previewIds[sid] = true;
5334
this._flightSeen[sid] = now;
5335
};
5336
5337
/** True while a field sprite should stay hidden — the flight is its visual. */
5338
Online.hasExitVisual = function (id)
5339
{
5340
if (id == null)
5341
{ return false; }
5342
var sid = String(id);
5343
if (this._previewIds && this._previewIds[sid])
5344
{ return true; }
5345
var f = this._findFlight(sid);
5346
if (!f || f.miss)
5347
{ return false; }
5348
var raw = (performance.now() - f.t0) / f.duration;
5349
return raw < 0.4;
5350
};
5351
5352
/**
5353
* Once the shot is scored, pick up the preview at its current pose
5354
* and fly the rest of the way to the real end (no jump).
5355
*/
5356
Online.retargetFlight = function (f, r, meta, now)
5357
{
5358
now = now || performance.now();
5359
meta = meta || {};
5360
var raw = (now - f.t0) / f.duration;
5361
if (raw < 0)
5362
{ raw = 0; }
5363
if (raw > 0.95)
5364
{ raw = 0.95; }
5365
var u = this.smoothParam(raw, 0.9, 0.9);
5366
var pt = f.curve
5367
? this.curvePoint(f.curve, u)
5368
: { x: f.start.x, y: f.start.y };
5369
var curScale = f.startScale + (f.endScale - f.startScale) * u;
5370
5371
var fromId = r.from_id || r.from_user || meta.from_id || f.from_id || null;
5372
var targetId = r.target_id != null ? r.target_id : r.to_user;
5373
var miss = !!r.miss;
5374
var kind = this.flightKind(fromId, targetId, miss);
5375
var duration = (r.flight_duration || this.FLIGHT_DURATION) * 1000;
5376
5377
var landCol = null;
5378
if (r.land_col != null && isFinite(r.land_col))
5379
{ landCol = r.land_col | 0; }
5380
else if (meta.land_col != null && isFinite(meta.land_col))
5381
{ landCol = meta.land_col | 0; }
5382
else if (f.landCol != null)
5383
{ landCol = f.landCol; }
5384
if (landCol != null)
5385
{ this.rememberLandCol(String(f.id), landCol); }
5386
5387
var end;
5388
if (miss)
5389
{ end = this._missEnd(pt, kind === 'enemy-miss'); }
5390
else if (kind === 'enemy-to-player')
5391
{ end = this.fieldEntry(landCol != null ? landCol : 4.5); }
5392
else
5393
{ end = this._targetEnd(targetId, pt, landCol); }
5394
5395
var flightColor = miss
5396
? (r.color != null ? r.color : meta.color)
5397
: -1;
5398
if (f.el && flightColor !== f.color)
5399
{ f.el.src = colorSpriteUrl(flightColor); }
5400
5401
var full = this._fullTileSize();
5402
var mini = this._miniCellSize(fromId || targetId) / full;
5403
if (mini < 0.12)
5404
{ mini = 0.2; }
5405
var endScale;
5406
if (kind === 'player-to-enemy')
5407
{ endScale = mini; }
5408
else if (kind === 'enemy-to-player')
5409
{ endScale = 1; }
5410
else if (kind === 'enemy-to-enemy')
5411
{ endScale = mini; }
5412
else
5413
{ endScale = 0; }
5414
5415
var field = this.playerFieldRect();
5416
var around = !miss && (kind === 'enemy-to-player' || kind === 'player-to-enemy');
5417
var height = miss
5418
? Math.max(40, Math.min(160, Math.abs(end.y - pt.y) * 0.35))
5419
: this.arcHeight(pt, end);
5420
var clearance = Math.max(64, height * 0.45);
5421
var endSpeed = this._fallSpeedPx(field, duration / 1000);
5422
var curve = miss ? null : this.makeAroundCurve(pt, end, around ? field : null, {
5423
clearance: clearance,
5424
startSpeedPx: endSpeed,
5425
endSpeedPx: endSpeed
5426
});
5427
5428
f.start = pt;
5429
f.end = end;
5430
f.t0 = now;
5431
f.duration = duration;
5432
f.curve = curve;
5433
f.ctrl = miss ? this._missCtrl(pt, end) : null;
5434
f.height = height;
5435
f.miss = miss;
5436
f.kind = kind;
5437
f.startScale = curScale;
5438
f.endScale = endScale;
5439
f.landCol = landCol;
5440
f.field = field;
5441
f.preview = false;
5442
f.color = flightColor;
5443
f.from_id = fromId;
5444
if (this._previewIds)
5445
{ delete this._previewIds[String(f.id)]; }
5446
5447
if (kind === 'enemy-to-enemy' && f.el)
5448
{
5449
var back = document.getElementById('flights-back');
5450
if (back && f.el.parentNode !== back)
5451
{
5452
f.el.className = 'flight flight-behind';
5453
back.appendChild(f.el);
5454
}
5455
}
5456
};
5457
5458
/** Point and (optional) derivative of a flight at parameter u. */
5459
Online.flightPointAt = function (f, u)
5460
{
5461
if (!f)
5462
{ return { x: 0, y: 0 }; }
5463
if (f.curve)
5464
{ return this.curvePoint(f.curve, u); }
5465
if (f.miss && f.ctrl)
5466
{
5467
var e = u;
5468
var mt = 1 - e;
5469
return {
5470
x: mt * mt * f.start.x + 2 * mt * e * f.ctrl.x + e * e * f.end.x,
5471
y: mt * mt * f.start.y + 2 * mt * e * f.ctrl.y + e * e * f.end.y
5472
};
5473
}
5474
return this.aroundFieldPoint(f.start, f.end, u, f.field, (f.height || 80) * 0.45);
5475
};
5476
5477
Online.pointAllowedOnArc = function (p, field, start, end, slop)
5478
{
5479
if (!this.pointInFieldInterior(p.x, p.y, field, slop))
5480
{ return true; }
5481
if (!field)
5482
{ return true; }
5483
var w = (field.right - field.left) / 10;
5484
var corridor = w * 0.7;
5485
if (start && Math.abs(p.x - start.x) <= corridor)
5486
{ return true; }
5487
if (end && Math.abs(p.x - end.x) <= corridor)
5488
{ return true; }
5489
return false;
5490
};
5491
4983
5492
Online.tickFlights = function (now)
4984
5493
{
4985
5494
now = now || performance.now();
@@ -4992,11 +5501,14 @@ Online.tickFlights = function (now)
4992
5501
{
4993
5502
if (f.el && f.el.parentNode)
4994
5503
{ f.el.parentNode.removeChild(f.el); }
5504
if (this._previewIds)
5505
{ delete this._previewIds[String(f.id)]; }
4995
5506
continue;
4996
5507
}
4997
5508
if (raw < 0)
4998
5509
{ raw = 0; }
4999
var u = this.easeInOutCubic(raw);
5510
// Non-zero endpoint speed so the handoff matches fallSpeed (t1135).
5511
var u = f.miss ? this.easeInOutCubic(raw) : this.smoothParam(raw, 0.85, 0.85);
5000
5512
var x, y;
5001
5513
if (f.miss && f.ctrl)
5002
5514
{
@@ -5005,21 +5517,15 @@ Online.tickFlights = function (now)
5005
5517
x = mt * mt * f.start.x + 2 * mt * e * f.ctrl.x + e * e * f.end.x;
5006
5518
y = mt * mt * f.start.y + 2 * mt * e * f.ctrl.y + e * e * f.end.y;
5007
5519
}
5008
else if (f.waypoints && f.waypoints.length > 2)
5009
{
5010
var pt = this.pointOnPath(f.waypoints, u);
5011
x = pt.x;
5012
y = pt.y;
5013
}
5014
else if (f.waypoints && f.field)
5520
else if (f.curve)
5015
5521
{
5016
var pt = this.aroundFieldPoint(f.start, f.end, u, f.field, (f.height || 80) * 0.45);
5522
var pt = this.curvePoint(f.curve, u);
5017
5523
x = pt.x;
5018
5524
y = pt.y;
5019
5525
}
5020
5526
else
5021
5527
{
5022
var pt = this.arcPoint(f.start, f.end, u, f.height || 80);
5528
var pt = this.aroundFieldPoint(f.start, f.end, u, f.field, (f.height || 80) * 0.45);
5023
5529
x = pt.x;
5024
5530
y = pt.y;
5025
5531
}
@@ -5060,6 +5566,7 @@ Online.clearFlights = function ()
5060
5566
this._flightLocals = {};
5061
5567
this._flightSeen = Object.create(null);
5062
5568
this._pendingLandCol = Object.create(null);
5569
this._previewIds = Object.create(null);
5063
5570
};
5064
5571
5065
5572
if (typeof globalThis !== 'undefined')
@@ -6187,6 +6694,11 @@ function syncSprites (dt)
6187
6694
applyBlockVisual(obj, block);
6188
6695
obj.renderer.visible = true;
6189
6696
obj.renderer.alpha = 1;
6697
if (typeof Online !== 'undefined' && Online.hasExitVisual && Online.hasExitVisual(block.id))
6698
{
6699
obj.renderer.visible = false;
6700
obj.renderer.alpha = 0;
6701
}
6190
6702
6191
6703
if (block.flame)
6192
6704
{
@@ -6213,6 +6725,10 @@ function syncSprites (dt)
6213
6725
}
6214
6726
else if (app.flames[block.id])
6215
6727
{ app.flames[block.id].renderer.visible = false; }
6728
if (block.flame && app.flames[block.id]
6729
&& typeof Online !== 'undefined' && Online.hasExitVisual
6730
&& Online.hasExitVisual(block.id))
6731
{ app.flames[block.id].renderer.visible = false; }
6216
6732
}
6217
6733
6218
6734
var ids = Object.keys(app.sprites);
@@ -6450,6 +6966,7 @@ function tickView (dt)
6450
6966
placeTile(app.cells[i], col, row);
6451
6967
}
6452
6968
6969
previewOutgoingFlights();
6453
6970
app.core.tick(dt);
6454
6971
if (app.offline && app.battle)
6455
6972
{ tickOffline(dt); }
@@ -6970,7 +7487,7 @@ function tickOnline (dt)
6970
7487
for (var i = 0; i < shots.length; i++)
6971
7488
{
6972
7489
var s = shots[i];
6973
var start = fieldToViewport(s.col, s.y + 1);
7490
var start = fieldToViewport(s.col, s.y);
6974
7491
Online.rememberFlightLocal(s, start.x, start.y);
6975
7492
}
6976
7493
Online.queueShots(shots);
@@ -7048,7 +7565,9 @@ function tickOffline (dt)
7048
7565
var s = list[i];
7049
7566
var start;
7050
7567
if (s.from_id === 'player')
7051
{ start = fieldToViewport(s.col, s.y + 1); }
7568
{ start = fieldToViewport(s.col, s.y); }
7569
else if (typeof Online !== 'undefined' && Online.miniCellViewport)
7570
{ start = Online.miniCellViewport(s.from_id, s.col, s.y != null ? s.y : 12); }
7052
7571
else
7053
7572
{ start = miniViewportCenter(s.from_id); }
7054
7573
locals[s.client_id] = {
@@ -7292,6 +7811,58 @@ function updateColumnWarn (dt)
7292
7811
}
7293
7812
}
7294
7813
7814
/**
7815
* Take over a rocket that is about to leave the top of a field (the
7816
* player's, or a bot's) so the flight starts at the real cell and
7817
* continues its upward motion (t1134). Shared by offline and online.
7818
*/
7819
function previewOutgoingFlights ()
7820
{
7821
if (typeof Online === 'undefined' || !Online.previewExit)
7822
{ return; }
7823
if (app.core)
7824
{ previewCoreExits(app.core, null); }
7825
if (app.offline && app.battle && app.battle.bots)
7826
{
7827
var bots = app.battle.bots;
7828
for (var i = 0; i < bots.length; i++)
7829
{
7830
var bot = bots[i];
7831
if (bot && bot.core && !bot.eliminated)
7832
{ previewCoreExits(bot.core, bot.id); }
7833
}
7834
}
7835
}
7836
7837
function previewCoreExits (core, fromId)
7838
{
7839
if (!core || !core.blocks)
7840
{ return; }
7841
var blocks = core.blocks;
7842
for (var i = 0; i < blocks.length; i++)
7843
{
7844
var b = blocks[i];
7845
if (b.y < 11.6)
7846
{ continue; }
7847
if (!(b.vy > 0))
7848
{ continue; }
7849
var start = fromId
7850
? (Online.miniCellViewport
7851
? Online.miniCellViewport(fromId, b.col, b.y)
7852
: miniViewportCenter(fromId))
7853
: fieldToViewport(b.col, b.y);
7854
Online.previewExit({
7855
id: b.id,
7856
col: b.col,
7857
y: b.y,
7858
vy: b.vy,
7859
color: b.color,
7860
start: start,
7861
from_id: fromId || null
7862
});
7863
}
7864
}
7865
7295
7866
function fieldToViewport (col, fieldY)
7296
7867
{
7297
7868
var canvas = app.scene && app.scene.canvas;
@@ -7299,7 +7870,8 @@ function fieldToViewport (col, fieldY)
7299
7870
{ return { x: window.innerWidth / 2, y: 40 }; }
7300
7871
var rect = canvas.getBoundingClientRect();
7301
7872
var x = rect.left + ((col + 0.5) / 10) * rect.width;
7302
var y = rect.top + (1 - (fieldY / 13)) * rect.height;
7873
// Cell centre matches placeTile: y = fieldH - (fieldY + 0.5) * tile (t1134).
7874
var y = rect.top + (1 - ((fieldY + 0.5) / 13)) * rect.height;
7303
7875
return { x: x, y: y };
7304
7876
}
7305
7877
@@ -2695,7 +2695,8 @@ GameCore.prototype.cullOffTop = function ()2695
id: block.id,2695
id: block.id,2696
color: block.color,2696
color: block.color,2697
col: block.col,2697
col: block.col,2698
y: block.y2698
y: block.y,2699
vy: block.vy2699
});2700
});2700
this.score += 1;2701
this.score += 1;2701
this.removeBlock(block);2702
this.removeBlock(block);@@ -4567,7 +4568,7 @@ Online.playerFieldRect = function ()4567
4568
4568
/**4569
/**4569
* True if (x, y) is inside the field's interior. The top edge (a few4570
* True if (x, y) is inside the field's interior. The top edge (a few4570
* pixels) is not interior: that is where arcs may land (t1128).4571
* pixels) is not interior: launch and landing may use that band.4571
*/4572
*/4572
Online.pointInFieldInterior = function (x, y, field, slop)4573
Online.pointInFieldInterior = function (x, y, field, slop)4573
{4574
{@@ -4578,107 +4579,363 @@ Online.pointInFieldInterior = function (x, y, field, slop)4578
&& y > field.top + slop && y < field.bottom - 0.5;4579
&& y > field.top + slop && y < field.bottom - 0.5;4579
};4580
};4580
4581
4582
/** Cubic Bezier C(t), t ∈ [0, 1]. C¹ (in fact C^∞) on (0, 1) — no corners (t1134). */4583
Online.cubicBezier = function (p0, p1, p2, p3, t)4584
{4585
if (t < 0)4586
{ t = 0; }4587
if (t > 1)4588
{ t = 1; }4589
var u = 1 - t;4590
var a = u * u * u;4591
var b = 3 * u * u * t;4592
var c = 3 * u * t * t;4593
var d = t * t * t;4594
return {4595
x: a * p0.x + b * p1.x + c * p2.x + d * p3.x,4596
y: a * p0.y + b * p1.y + c * p2.y + d * p3.y4597
};4598
};4599
4600
/** C'(t) = 3(1−t)²(P1−P0) + 6(1−t)t(P2−P1) + 3t²(P3−P2). */4601
Online.cubicBezierDeriv = function (p0, p1, p2, p3, t)4602
{4603
if (t < 0)4604
{ t = 0; }4605
if (t > 1)4606
{ t = 1; }4607
var u = 1 - t;4608
return {4609
x: 3 * u * u * (p1.x - p0.x) + 6 * u * t * (p2.x - p1.x) + 3 * t * t * (p3.x - p2.x),4610
y: 3 * u * u * (p1.y - p0.y) + 6 * u * t * (p2.y - p1.y) + 3 * t * t * (p3.y - p2.y)4611
};4612
};4613
4581
/**4614
/**4582
* Waypoints that route a player↔enemy arc around the field, never4615
* Hermite parameter with p(0)=0, p(1)=1, p'(0)=v0, p'(1)=v1.4583
* through its interior: up the outside, across above the top edge,4616
* v0=v1=1 is linear (constant speed in t, no endpoint halt).4584
* then into the target (t1128). If both ends already sit at or above4585
* the top, a simple two-point path is enough.4586
*/4617
*/4587
Online.waypointsAroundField = function (start, end, field, clearance)4618
Online.smoothParam = function (t, v0, v1)4619
{4620
if (t < 0)4621
{ return 0; }4622
if (t > 1)4623
{ return 1; }4624
if (v0 == null)4625
{ v0 = 1; }4626
if (v1 == null)4627
{ v1 = 1; }4628
var b = 3 - 2 * v0 - v1;4629
var a = v0 + v1 - 2;4630
return ((a * t + b) * t + v0) * t;4631
};4632
4633
/**4634
* A simple up-and-over cubic, used when there is no field to route4635
* around (enemy→enemy) or both ends already sit above the apex.4636
*/4637
Online._singleCubic = function (start, end, apexY, opts)4638
{4639
opts = opts || {};4640
var rise = Math.max(40, Math.abs(start.y - apexY) * 0.9);4641
if (opts.startSpeedPx)4642
{ rise = Math.max(rise, opts.startSpeedPx); }4643
var fall = Math.max(40, Math.abs(end.y - apexY) * 0.9);4644
if (opts.endSpeedPx)4645
{ fall = Math.max(40, opts.endSpeedPx); }4646
var p1 = { x: start.x, y: Math.min(start.y - rise, apexY) };4647
var p2 = { x: end.x, y: Math.min(end.y - fall, apexY) };4648
return { p0: start, p1: p1, p2: p2, p3: end, apexY: apexY };4649
};4650
4651
/**4652
* Smooth C¹ path: rise up (launch column or outside), cruise above4653
* the field, dive into the landing column (t1134 / t1135). Joints4654
* are quarter-turn cubics with matching tangents, so there are no4655
* corners and no speed jerks. The curve may use the launch and4656
* landing corridors but does not cut across the field interior.4657
*/4658
Online.makeAroundCurve = function (start, end, field, opts)4588
{4659
{4589
if (!start || !end)4660
opts = opts || {};4590
{ return [start || { x: 0, y: 0 }, end || { x: 0, y: 0 }]; }4661
if (!start)4662
{ start = { x: 0, y: 0 }; }4663
if (!end)4664
{ end = { x: 0, y: 0 }; }4665
var clearance = opts.clearance || 80;4591
if (!field)4666
if (!field)4592
{ return [start, end]; }4667
{4593
clearance = clearance || 64;4668
var looseApex = Math.min(start.y, end.y) - Math.max(40, clearance * 0.5);4669
if (looseApex < 8)4670
{ looseApex = Math.min(start.y, end.y) - 24; }4671
return this._singleCubic(start, end, looseApex, opts);4672
}4594
var top = field.top;4673
var top = field.top;4595
var left = field.left;4674
var left = field.left;4596
var right = field.right;4675
var right = field.right;4597
var pad = 10;4676
var apexY = top - clearance;4598
var apexY = Math.min(start.y, end.y, top) - clearance;4599
if (apexY < 8)4677
if (apexY < 8)4600
{ apexY = Math.max(8, top - Math.max(24, clearance * 0.5)); }4678
{ apexY = Math.max(8, top - Math.max(24, clearance * 0.5)); }4601
4679
4602
if (start.y <= top + 6 && end.y <= top + 6)4680
if (start.y <= apexY + 8 && end.y <= apexY + 8)4603
{ return [start, end]; }4681
{ return this._singleCubic(start, end, apexY, opts); }4604
4682
4605
var w1x = start.x;4683
var pad = 14;4606
var w2x = end.x;4684
var dir = end.x >= start.x ? 1 : -1;4607
if (start.x < left)4685
var span = Math.abs(end.x - start.x);4608
{ w1x = Math.min(start.x, left - pad); }4686
var horiz = Math.max(28, Math.min(80, span * 0.15 + 8));4609
else if (start.x > right)4687
function outsideX (x)4610
{ w1x = Math.max(start.x, right + pad); }4688
{4611
if (end.x < left)4689
if (x < left + 8)4612
{ w2x = Math.min(end.x, left - pad); }4690
{ return Math.min(x, left - pad); }4613
else if (end.x > right)4691
if (x > right - 8)4614
{ w2x = Math.max(end.x, right + pad); }4692
{ return Math.max(x, right + pad); }4693
return x;4694
}4695
var riseX = outsideX(start.x);4696
var diveX = outsideX(end.x);4697
var segments = [];4615
4698
4616
return [4699
// Rise ends already turned toward the cruise, at apex.4617
start,4700
var riseEnd = { x: riseX + dir * horiz, y: apexY };4618
{ x: w1x, y: apexY },4701
if (start.y > apexY + 4)4619
{ x: w2x, y: apexY },4702
{4620
end4703
var p1 = { x: start.x, y: apexY };4621
];4704
var p2 = { x: riseX, y: apexY };4705
segments.push({ p0: start, p1: p1, p2: p2, p3: riseEnd });4706
}4707
else4708
{ riseEnd = { x: start.x, y: Math.min(start.y, apexY) }; }4709
4710
// Cruise stays on the apex line (convex hull is above the field).4711
var diveStart = { x: diveX - dir * horiz, y: apexY };4712
if (Math.abs(riseEnd.x - diveStart.x) > 4 || Math.abs(riseEnd.y - diveStart.y) > 4)4713
{4714
// Keep the cruise direction consistent; if the two joints4715
// would cross, just connect them directly.4716
var cdir = diveStart.x >= riseEnd.x ? 1 : -1;4717
var c1 = { x: riseEnd.x + cdir * horiz, y: riseEnd.y };4718
if (c1.y > apexY)4719
{ c1.y = apexY; }4720
var c2 = { x: diveStart.x - cdir * horiz, y: diveStart.y };4721
segments.push({ p0: { x: riseEnd.x, y: riseEnd.y }, p1: c1, p2: c2, p3: diveStart });4722
}4723
4724
if (end.y > apexY + 4 || Math.abs(end.x - (diveStart.x + dir * horiz)) > 2)4725
{4726
var u0 = (Math.abs(riseEnd.x - diveStart.x) > 4 || segments.length === 0)4727
? diveStart4728
: riseEnd;4729
if (segments.length && segments[segments.length - 1].p3.x === u0.x4730
&& segments[segments.length - 1].p3.y === u0.y)4731
{ /* already joined */ }4732
else if (segments.length === 0)4733
{ u0 = riseEnd; }4734
var u1 = { x: u0.x + dir * horiz, y: u0.y };4735
var fall = Math.max(24, Math.abs(end.y - apexY) * 0.45);4736
if (opts.endSpeedPx)4737
{4738
// |P3-P2| so arrival ≈ fallSpeed after equal-param scaling.4739
// velocity = 3*|P3-P2|*n*v1/duration; endSpeedPx is4740
// (cells*px*duration)/3, so |P3-P2| = endSpeedPx/(n*v1).4741
var nEst = Math.max(1, segments.length + 1);4742
fall = Math.max(20, opts.endSpeedPx / (nEst * 0.85));4743
}4744
var u2 = { x: end.x, y: end.y - fall };4745
// P2 may sit between the apex and the end (slower arrival);4746
// only clamp if it would pass the end or fly far past the apex.4747
if (u2.y < apexY - 240)4748
{ u2.y = apexY - 240; }4749
if (u2.y > end.y - 8)4750
{ u2.y = end.y - 8; }4751
segments.push({ p0: u0, p1: u1, p2: u2, p3: end });4752
}4753
4754
if (segments.length === 0)4755
{ return this._singleCubic(start, end, apexY, opts); }4756
if (segments.length === 1 && !segments[0].p0)4757
{ return this._singleCubic(start, end, apexY, opts); }4758
4759
return { segments: segments, apexY: apexY, p0: start, p3: end };4622
};4760
};4623
4761
4624
/**4762
Online._measureCurve = function (curve)4625
* Point at parameter u ∈ [0, 1] along a polyline, with a small upward4626
* bulge on each segment so the path reads as a "boogje".4627
*/4628
Online.pointOnPath = function (points, u)4629
{4763
{4630
u = u < 0 ? 0 : (u > 1 ? 1 : u);4764
if (!curve.segments)4631
if (!points || !points.length)4765
{ return curve; }4632
{ return { x: 0, y: 0 }; }4633
if (points.length === 1)4634
{ return { x: points[0].x, y: points[0].y }; }4635
var lens = [];4766
var lens = [];4636
var total = 0;4767
var total = 0;4637
for (var i = 1; i < points.length; i++)4768
for (var i = 0; i < curve.segments.length; i++)4638
{4769
{4639
var dx = points[i].x - points[i - 1].x;4770
var L = this._segLen(curve.segments[i]);4640
var dy = points[i].y - points[i - 1].y;4641
var L = Math.sqrt(dx * dx + dy * dy);4642
if (L < 1)4643
{ L = 1; }4644
lens.push(L);4771
lens.push(L);4645
total += L;4772
total += L;4646
}4773
}4647
var dist = u * total;4774
curve.lens = lens;4648
var acc = 0;4775
curve.totalLen = Math.max(total, 1);4649
for (var i = 0; i < lens.length; i++)4776
return curve;4777
};4778
4779
Online._segLen = function (seg, steps)4780
{4781
steps = steps || 10;4782
var len = 0;4783
var prev = this.cubicBezier(seg.p0, seg.p1, seg.p2, seg.p3, 0);4784
for (var i = 1; i <= steps; i++)4650
{4785
{4651
if (acc + lens[i] >= dist || i === lens.length - 1)4786
var p = this.cubicBezier(seg.p0, seg.p1, seg.p2, seg.p3, i / steps);4652
{4787
var dx = p.x - prev.x;4653
var t = (dist - acc) / lens[i];4788
var dy = p.y - prev.y;4654
if (t < 0)4789
len += Math.sqrt(dx * dx + dy * dy);4655
{ t = 0; }4790
prev = p;4656
if (t > 1)4791
}4657
{ t = 1; }4792
return Math.max(len, 1);4658
var a = points[i];4793
};4659
var b = points[i + 1];4794
4660
var bump = 4 * 16 * t * (1 - t);4795
/**4661
return {4796
* Equal-parameter split across segments so matching local C'(t)4662
x: a.x + (b.x - a.x) * t,4797
* at joints also matches dP/du (no speed jerk).4663
y: a.y + (b.y - a.y) * t - bump4798
*/4664
};4799
Online._curveSegmentAt = function (curve, u)4665
}4800
{4666
acc += lens[i];4801
if (!curve)4802
{ return null; }4803
if (!curve.segments)4804
{4805
return { seg: curve, t: u < 0 ? 0 : (u > 1 ? 1 : u), scale: 1 };4667
}4806
}4668
var last = points[points.length - 1];4807
var segs = curve.segments;4669
return { x: last.x, y: last.y };4808
var n = segs.length;4809
if (u <= 0)4810
{ return { seg: segs[0], t: 0, scale: n }; }4811
if (u >= 1)4812
{ return { seg: segs[n - 1], t: 1, scale: n }; }4813
var at = u * n;4814
var i = Math.floor(at);4815
if (i >= n)4816
{ i = n - 1; }4817
var t = at - i;4818
return { seg: segs[i], t: t, scale: n };4819
};4820
4821
/** Point on a (possibly multi-segment C¹) curve at u ∈ [0, 1]. */4822
Online.curvePoint = function (curve, u)4823
{4824
var at = this._curveSegmentAt(curve, u);4825
if (!at)4826
{ return { x: 0, y: 0 }; }4827
var s = at.seg;4828
if (s && s.p1)4829
{ return this.cubicBezier(s.p0, s.p1, s.p2, s.p3, at.t); }4830
if (s && s.p0)4831
{ return { x: s.p0.x, y: s.p0.y }; }4832
return { x: 0, y: 0 };4833
};4834
4835
/** dP/du of the curve (C¹ across joints). */4836
Online.curveDeriv = function (curve, u)4837
{4838
var at = this._curveSegmentAt(curve, u);4839
if (!at || !at.seg || !at.seg.p1)4840
{ return { x: 0, y: 0 }; }4841
var s = at.seg;4842
var d = this.cubicBezierDeriv(s.p0, s.p1, s.p2, s.p3, at.t);4843
return { x: d.x * at.scale, y: d.y * at.scale };4670
};4844
};4671
4845
4672
/** Sample a player↔enemy path; used by tests and the ticker. */4846
/**4847
* Sample the smooth around-field curve at u ∈ [0, 1] (t1134).4848
* `clearance` may be a number or an options object.4849
*/4673
Online.aroundFieldPoint = function (start, end, u, field, clearance)4850
Online.aroundFieldPoint = function (start, end, u, field, clearance)4674
{4851
{4675
var pts = this.waypointsAroundField(start, end, field, clearance);4852
var opts = (clearance && typeof clearance === 'object') ? clearance : { clearance: clearance };4676
if (pts.length === 2)4853
var curve = opts.curve || this.makeAroundCurve(start, end, field, opts);4854
return this.curvePoint(curve, u);4855
};4856
4857
/** Guide points (start, joints, end) for older tests. */4858
Online.waypointsAroundField = function (start, end, field, clearance)4859
{4860
var c = this.makeAroundCurve(start, end, field, { clearance: clearance || 64 });4861
if (c.segments && c.segments.length)4862
{4863
var pts = [{ x: c.segments[0].p0.x, y: c.segments[0].p0.y }];4864
for (var i = 0; i < c.segments.length; i++)4865
{ pts.push({ x: c.segments[i].p3.x, y: c.segments[i].p3.y }); }4866
return pts;4867
}4868
return [c.p0, c.p1, c.p2, c.p3];4869
};4870
4871
Online.pointOnPath = function (points, u)4872
{4873
// Legacy polyline; new flights use cubicBezier.4874
u = u < 0 ? 0 : (u > 1 ? 1 : u);4875
if (!points || !points.length)4876
{ return { x: 0, y: 0 }; }4877
if (points.length === 4 && points[0] && points[3])4878
{ return this.cubicBezier(points[0], points[1], points[2], points[3], u); }4879
if (points.length === 1)4880
{ return { x: points[0].x, y: points[0].y }; }4881
var n = points.length - 1;4882
var at = u * n;4883
var i = Math.floor(at);4884
if (i >= n)4885
{ i = n - 1; }4886
var t = at - i;4887
var a = points[i];4888
var b = points[i + 1];4889
return { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t };4890
};4891
4892
/** Viewport centre of a field cell (y=0 is the bottom row). */4893
Online.cellViewport = function (col, y, rect)4894
{4895
if (!rect)4677
{4896
{4678
var h = this.arcHeight(start, end);4897
var field = this.playerFieldRect();4679
return this.arcPoint(start, end, u, h);4898
if (!field)4899
{ return { x: 0, y: 0 }; }4900
rect = field;4680
}4901
}4681
return this.pointOnPath(pts, u);4902
var w = rect.width != null ? rect.width : (rect.right - rect.left);4903
var h = rect.height != null ? rect.height : (rect.bottom - rect.top);4904
return {4905
x: rect.left + ((col + 0.5) / 10) * w,4906
y: rect.top + (1 - (y + 0.5) / 13) * h4907
};4908
};4909
4910
/** Handoff point of an incoming garbage block: y = 13, just into the column (t1135). */4911
Online.fieldEntry = function (col)4912
{4913
return this.cellViewport(col == null ? 4.5 : col, 13);4914
};4915
4916
Online.miniCellViewport = function (playerId, col, y)4917
{4918
var el = this.miniElement(playerId);4919
var canvas = el && (el.querySelector ? el.querySelector('canvas') : null);4920
var box = canvas || el;4921
if (!box || !box.getBoundingClientRect)4922
{ return { x: window.innerWidth / 2, y: 48 }; }4923
return this.cellViewport(col == null ? 4.5 : col, y == null ? 13 : y, box.getBoundingClientRect());4924
};4925
4926
Online._fallSpeedPx = function (field, duration)4927
{4928
var px = 40;4929
if (field && field.height)4930
{ px = field.height / 13; }4931
else if (typeof app !== 'undefined' && app.tile)4932
{ px = app.tile; }4933
var cells = 13 / 3;4934
if (typeof app !== 'undefined' && app.planet && app.planet.fallSpeed)4935
{ cells = app.planet.fallSpeed; }4936
duration = duration || this.FLIGHT_DURATION;4937
// Distance of P2 from P3 so C'(1)/duration ≈ fall speed (t1135).4938
return (cells * px * duration) / 3;4682
};4939
};4683
4940
4684
Online.rememberLandCol = function (id, col)4941
Online.rememberLandCol = function (id, col)@@ -4746,17 +5003,17 @@ Online._miniAnchor = function (playerId, dir)4746
5003
4747
Online._fieldTop = function (col)5004
Online._fieldTop = function (col)4748
{5005
{4749
return this._flightStart(col);5006
return this.fieldEntry(col);4750
};5007
};4751
5008
4752
/**5009
/**4753
* Animate shot results. `locals` is a map of client_id → {col, y, color,5010
* Animate shot results. `locals` is a map of client_id → {col, y, color,4754
* startX, startY, from_id} in viewport pixels.5011
* startX, startY, from_id} in viewport pixels.4755
*5012
*4756
* Visual-only (t1125): a parabolic arc whose scale goes from mini-cell5013
* Visual-only: a smooth cubic that leaves the real cell, arcs around4757
* to full tile (or the reverse). Enemy-to-enemy arcs stay small and5014
* the field, and dives into the landing column at the spawn pose4758
* are drawn behind the player's field. Delivery timing is unchanged;5015
* (t1134 / t1135). Enemy-to-enemy arcs stay small and are drawn4759
* a late-seen flight starts mid-arc via `age`.5016
* behind the player's field. A late-seen flight starts mid-arc via `age`.4760
*/5017
*/4761
Online.spawnFlights = function (results, locals)5018
Online.spawnFlights = function (results, locals)4762
{5019
{@@ -4767,6 +5024,8 @@ Online.spawnFlights = function (results, locals)4767
{ return; }5024
{ return; }4768
if (!this._flightSeen)5025
if (!this._flightSeen)4769
{ this._flightSeen = Object.create(null); }5026
{ this._flightSeen = Object.create(null); }5027
if (!this._previewIds)5028
{ this._previewIds = Object.create(null); }4770
var now = performance.now();5029
var now = performance.now();4771
var full = this._fullTileSize();5030
var full = this._fullTileSize();4772
for (var i = 0; i < results.length; i++)5031
for (var i = 0; i < results.length; i++)@@ -4774,7 +5033,18 @@ Online.spawnFlights = function (results, locals)4774
var r = results[i];5033
var r = results[i];4775
var sid = String(r.id != null ? r.id : (r.client_id || ('tmp-' + i)));5034
var sid = String(r.id != null ? r.id : (r.client_id || ('tmp-' + i)));4776
if (this._flightSeen[sid])5035
if (this._flightSeen[sid])4777
{ continue; }5036
{5037
if (this._previewIds[sid])5038
{5039
var existing = this._findFlight(sid);5040
if (existing)5041
{5042
var meta0 = locals[r.client_id] || locals[sid] || {};5043
this.retargetFlight(existing, r, meta0, now);5044
}5045
}5046
continue;5047
}4778
this._flightSeen[sid] = now;5048
this._flightSeen[sid] = now;4779
5049
4780
var meta = locals[r.client_id] || locals[sid] || {};5050
var meta = locals[r.client_id] || locals[sid] || {};@@ -4801,11 +5071,15 @@ Online.spawnFlights = function (results, locals)4801
{ this.rememberLandCol(r.client_id, landCol); }5071
{ this.rememberLandCol(r.client_id, landCol); }4802
}5072
}4803
5073
5074
var startCol = meta.col != null ? meta.col : r.col;5075
var startY = meta.y != null ? meta.y : r.y;4804
var start;5076
var start;4805
if (meta.startX != null && isFinite(meta.startX))5077
if (meta.startX != null && isFinite(meta.startX))4806
{ start = { x: meta.startX, y: meta.startY }; }5078
{ start = { x: meta.startX, y: meta.startY }; }4807
else if (kind === 'player-to-enemy' || kind === 'player-miss')5079
else if (kind === 'player-to-enemy' || kind === 'player-miss')4808
{ start = this._flightStart(meta.col != null ? meta.col : r.col); }5080
{ start = this._flightStart(startCol, startY); }5081
else if (startCol != null || startY != null)5082
{ start = this.miniCellViewport(fromId, startCol, startY != null ? startY : 12); }4809
else5083
else4810
{ start = this._miniAnchor(fromId, 'out'); }5084
{ start = this._miniAnchor(fromId, 'out'); }4811
5085
@@ -4813,7 +5087,7 @@ Online.spawnFlights = function (results, locals)4813
if (miss)5087
if (miss)4814
{ end = this._missEnd(start, kind === 'enemy-miss'); }5088
{ end = this._missEnd(start, kind === 'enemy-miss'); }4815
else if (kind === 'enemy-to-player')5089
else if (kind === 'enemy-to-player')4816
{ end = this._fieldTop(landCol != null ? landCol : 4.5); }5090
{ end = this.fieldEntry(landCol != null ? landCol : 4.5); }4817
else5091
else4818
{ end = this._targetEnd(targetId, start, landCol); }5092
{ end = this._targetEnd(targetId, start, landCol); }4819
5093
@@ -4874,7 +5148,14 @@ Online.spawnFlights = function (results, locals)4874
: this.arcHeight(start, end);5148
: this.arcHeight(start, end);4875
var field = this.playerFieldRect();5149
var field = this.playerFieldRect();4876
var around = !miss && (kind === 'enemy-to-player' || kind === 'player-to-enemy');5150
var around = !miss && (kind === 'enemy-to-player' || kind === 'player-to-enemy');4877
var waypoints = around ? this.waypointsAroundField(start, end, field, height * 0.45) : null;5151
var clearance = Math.max(64, height * 0.45);5152
var endSpeed = this._fallSpeedPx(field, duration / 1000);5153
var curve = miss ? null : this.makeAroundCurve(start, end, around ? field : null, {5154
clearance: clearance,5155
startSpeedPx: endSpeed,5156
endSpeedPx: endSpeed,5157
duration: duration / 10005158
});4878
this._flights.push({5159
this._flights.push({4879
el: el,5160
el: el,4880
start: start,5161
start: start,@@ -4883,16 +5164,16 @@ Online.spawnFlights = function (results, locals)4883
height: height,5164
height: height,4884
t0: t0,5165
t0: t0,4885
duration: duration,5166
duration: duration,4886
spin: (Math.random() * 2 - 1) * 720,5167
spin: miss ? ((Math.random() * 2 - 1) * 720) : ((Math.random() * 2 - 1) * 120),4887
miss: miss,5168
miss: miss,4888
kind: kind,5169
kind: kind,4889
startScale: startScale,5170
startScale: startScale,4890
endScale: endScale,5171
endScale: endScale,4891
angle: Math.random() * 360,5172
angle: 0,4892
id: sid,5173
id: sid,4893
landCol: landCol,5174
landCol: landCol,4894
field: field,5175
field: field,4895
waypoints: waypoints,5176
curve: curve,4896
color: flightColor5177
color: flightColor4897
});5178
});4898
}5179
}@@ -4909,30 +5190,17 @@ Online.rememberFlightLocal = function (shot, startX, startY)4909
color: shot.color,5190
color: shot.color,4910
startX: startX,5191
startX: startX,4911
startY: startY,5192
startY: startY,4912
from_id: shot.from_id5193
from_id: shot.from_id,5194
land_col: shot.land_col,5195
vy: shot.vy4913
};5196
};4914
};5197
};4915
5198
4916
Online._flightStart = function (col)5199
Online._flightStart = function (col, y)4917
{5200
{4918
var appRef = typeof app !== 'undefined' ? app : null;5201
if (y == null || !isFinite(y))4919
if (appRef && appRef.scene && appRef.scene.canvas)5202
{ y = 12; }4920
{5203
return this.cellViewport(col == null ? 4.5 : col, y);4921
var canvas = appRef.scene.canvas;4922
var rect = canvas.getBoundingClientRect();4923
var c = col == null ? 4.5 : col;4924
return {4925
x: rect.left + (c + 0.5) * (rect.width / 10),4926
y: rect.top + 44927
};4928
}4929
var field = document.querySelector('canvas');4930
if (field)4931
{4932
var rect = field.getBoundingClientRect();4933
return { x: rect.left + rect.width / 2, y: rect.top };4934
}4935
return { x: window.innerWidth / 2, y: window.innerHeight * 0.3 };4936
};5204
};4937
5205
4938
Online._targetEnd = function (targetId, start, col)5206
Online._targetEnd = function (targetId, start, col)@@ -4940,12 +5208,8 @@ Online._targetEnd = function (targetId, start, col)4940
var el = targetId && this.miniElement(targetId);5208
var el = targetId && this.miniElement(targetId);4941
if (el)5209
if (el)4942
{5210
{4943
var canvas = el.querySelector('canvas') || el;5211
// Slightly inside the mini, in the landing column (t1135).4944
var r = canvas.getBoundingClientRect();5212
return this.miniCellViewport(targetId, col, 12);4945
var x = r.left + r.width / 2;4946
if (col != null && isFinite(col))4947
{ x = r.left + ((col + 0.5) / 10) * r.width; }4948
return { x: x, y: r.top + 4 };4949
}5213
}4950
return { x: start.x + (Math.random() - 0.5) * 80, y: 40 };5214
return { x: start.x + (Math.random() - 0.5) * 80, y: 40 };4951
};5215
};@@ -4980,6 +5244,251 @@ Online._hitCtrl = function (start, end)4980
};5244
};4981
};5245
};4982
5246
5247
Online._findFlight = function (sid)5248
{5249
sid = String(sid);5250
if (!this._flights)5251
{ return null; }5252
for (var i = 0; i < this._flights.length; i++)5253
{5254
if (String(this._flights[i].id) === sid)5255
{ return this._flights[i]; }5256
}5257
return null;5258
};5259
5260
/**5261
* Early visual takeover: a flying rocket near the top of a field5262
* becomes a flight sprite at its exact cell, so it is seen flying5263
* *out* rather than popping in above the canvas (t1134). When the5264
* shot is later dispatched, `retargetFlight` picks up from the5265
* current pose and aims at the real landing column.5266
*/5267
Online.previewExit = function (info)5268
{5269
if (!info || info.id == null)5270
{ return; }5271
var sid = String(info.id);5272
if (!this._flights)5273
{ this._flights = []; }5274
if (!this._flightSeen)5275
{ this._flightSeen = Object.create(null); }5276
if (!this._previewIds)5277
{ this._previewIds = Object.create(null); }5278
if (this._previewIds[sid] || this._flightSeen[sid])5279
{ return; }5280
var front = document.getElementById('flights');5281
if (!front || !info.start)5282
{ return; }5283
var start = info.start;5284
var field = this.playerFieldRect();5285
var clearance = 80;5286
if (typeof MiniLayout !== 'undefined' && MiniLayout.ARC_TOP_PAD)5287
{ clearance = Math.max(clearance, MiniLayout.ARC_TOP_PAD * 0.7); }5288
var apexY = (field ? field.top : start.y) - clearance;5289
if (apexY < 8)5290
{ apexY = Math.max(8, start.y - 80); }5291
var end = { x: start.x, y: apexY };5292
var duration = this.FLIGHT_DURATION * 1000;5293
var full = this._fullTileSize();5294
var el = document.createElement('img');5295
el.src = colorSpriteUrl(info.color);5296
el.alt = '';5297
el.className = 'flight';5298
el.style.width = full + 'px';5299
el.style.height = full + 'px';5300
front.appendChild(el);5301
var endSpeed = this._fallSpeedPx(field, this.FLIGHT_DURATION);5302
var curve = this.makeAroundCurve(start, end, info.from_id ? null : field, {5303
clearance: clearance,5304
startSpeedPx: endSpeed,5305
endSpeedPx: endSpeed5306
});5307
var now = performance.now();5308
var mini = info.from_id ? (this._miniCellSize(info.from_id) / full) : 1;5309
if (mini < 0.12)5310
{ mini = 0.2; }5311
this._flights.push({5312
el: el,5313
start: start,5314
end: end,5315
ctrl: null,5316
height: clearance,5317
t0: now,5318
duration: duration,5319
spin: (Math.random() * 2 - 1) * 90,5320
miss: false,5321
kind: info.from_id ? 'enemy-to-enemy' : 'player-to-enemy',5322
startScale: mini,5323
endScale: mini,5324
angle: 0,5325
id: sid,5326
landCol: null,5327
field: field,5328
curve: curve,5329
preview: true,5330
color: info.color,5331
from_id: info.from_id || null5332
});5333
this._previewIds[sid] = true;5334
this._flightSeen[sid] = now;5335
};5336
5337
/** True while a field sprite should stay hidden — the flight is its visual. */5338
Online.hasExitVisual = function (id)5339
{5340
if (id == null)5341
{ return false; }5342
var sid = String(id);5343
if (this._previewIds && this._previewIds[sid])5344
{ return true; }5345
var f = this._findFlight(sid);5346
if (!f || f.miss)5347
{ return false; }5348
var raw = (performance.now() - f.t0) / f.duration;5349
return raw < 0.4;5350
};5351
5352
/**5353
* Once the shot is scored, pick up the preview at its current pose5354
* and fly the rest of the way to the real end (no jump).5355
*/5356
Online.retargetFlight = function (f, r, meta, now)5357
{5358
now = now || performance.now();5359
meta = meta || {};5360
var raw = (now - f.t0) / f.duration;5361
if (raw < 0)5362
{ raw = 0; }5363
if (raw > 0.95)5364
{ raw = 0.95; }5365
var u = this.smoothParam(raw, 0.9, 0.9);5366
var pt = f.curve5367
? this.curvePoint(f.curve, u)5368
: { x: f.start.x, y: f.start.y };5369
var curScale = f.startScale + (f.endScale - f.startScale) * u;5370
5371
var fromId = r.from_id || r.from_user || meta.from_id || f.from_id || null;5372
var targetId = r.target_id != null ? r.target_id : r.to_user;5373
var miss = !!r.miss;5374
var kind = this.flightKind(fromId, targetId, miss);5375
var duration = (r.flight_duration || this.FLIGHT_DURATION) * 1000;5376
5377
var landCol = null;5378
if (r.land_col != null && isFinite(r.land_col))5379
{ landCol = r.land_col | 0; }5380
else if (meta.land_col != null && isFinite(meta.land_col))5381
{ landCol = meta.land_col | 0; }5382
else if (f.landCol != null)5383
{ landCol = f.landCol; }5384
if (landCol != null)5385
{ this.rememberLandCol(String(f.id), landCol); }5386
5387
var end;5388
if (miss)5389
{ end = this._missEnd(pt, kind === 'enemy-miss'); }5390
else if (kind === 'enemy-to-player')5391
{ end = this.fieldEntry(landCol != null ? landCol : 4.5); }5392
else5393
{ end = this._targetEnd(targetId, pt, landCol); }5394
5395
var flightColor = miss5396
? (r.color != null ? r.color : meta.color)5397
: -1;5398
if (f.el && flightColor !== f.color)5399
{ f.el.src = colorSpriteUrl(flightColor); }5400
5401
var full = this._fullTileSize();5402
var mini = this._miniCellSize(fromId || targetId) / full;5403
if (mini < 0.12)5404
{ mini = 0.2; }5405
var endScale;5406
if (kind === 'player-to-enemy')5407
{ endScale = mini; }5408
else if (kind === 'enemy-to-player')5409
{ endScale = 1; }5410
else if (kind === 'enemy-to-enemy')5411
{ endScale = mini; }5412
else5413
{ endScale = 0; }5414
5415
var field = this.playerFieldRect();5416
var around = !miss && (kind === 'enemy-to-player' || kind === 'player-to-enemy');5417
var height = miss5418
? Math.max(40, Math.min(160, Math.abs(end.y - pt.y) * 0.35))5419
: this.arcHeight(pt, end);5420
var clearance = Math.max(64, height * 0.45);5421
var endSpeed = this._fallSpeedPx(field, duration / 1000);5422
var curve = miss ? null : this.makeAroundCurve(pt, end, around ? field : null, {5423
clearance: clearance,5424
startSpeedPx: endSpeed,5425
endSpeedPx: endSpeed5426
});5427
5428
f.start = pt;5429
f.end = end;5430
f.t0 = now;5431
f.duration = duration;5432
f.curve = curve;5433
f.ctrl = miss ? this._missCtrl(pt, end) : null;5434
f.height = height;5435
f.miss = miss;5436
f.kind = kind;5437
f.startScale = curScale;5438
f.endScale = endScale;5439
f.landCol = landCol;5440
f.field = field;5441
f.preview = false;5442
f.color = flightColor;5443
f.from_id = fromId;5444
if (this._previewIds)5445
{ delete this._previewIds[String(f.id)]; }5446
5447
if (kind === 'enemy-to-enemy' && f.el)5448
{5449
var back = document.getElementById('flights-back');5450
if (back && f.el.parentNode !== back)5451
{5452
f.el.className = 'flight flight-behind';5453
back.appendChild(f.el);5454
}5455
}5456
};5457
5458
/** Point and (optional) derivative of a flight at parameter u. */5459
Online.flightPointAt = function (f, u)5460
{5461
if (!f)5462
{ return { x: 0, y: 0 }; }5463
if (f.curve)5464
{ return this.curvePoint(f.curve, u); }5465
if (f.miss && f.ctrl)5466
{5467
var e = u;5468
var mt = 1 - e;5469
return {5470
x: mt * mt * f.start.x + 2 * mt * e * f.ctrl.x + e * e * f.end.x,5471
y: mt * mt * f.start.y + 2 * mt * e * f.ctrl.y + e * e * f.end.y5472
};5473
}5474
return this.aroundFieldPoint(f.start, f.end, u, f.field, (f.height || 80) * 0.45);5475
};5476
5477
Online.pointAllowedOnArc = function (p, field, start, end, slop)5478
{5479
if (!this.pointInFieldInterior(p.x, p.y, field, slop))5480
{ return true; }5481
if (!field)5482
{ return true; }5483
var w = (field.right - field.left) / 10;5484
var corridor = w * 0.7;5485
if (start && Math.abs(p.x - start.x) <= corridor)5486
{ return true; }5487
if (end && Math.abs(p.x - end.x) <= corridor)5488
{ return true; }5489
return false;5490
};5491
4983
Online.tickFlights = function (now)5492
Online.tickFlights = function (now)4984
{5493
{4985
now = now || performance.now();5494
now = now || performance.now();@@ -4992,11 +5501,14 @@ Online.tickFlights = function (now)4992
{5501
{4993
if (f.el && f.el.parentNode)5502
if (f.el && f.el.parentNode)4994
{ f.el.parentNode.removeChild(f.el); }5503
{ f.el.parentNode.removeChild(f.el); }5504
if (this._previewIds)5505
{ delete this._previewIds[String(f.id)]; }4995
continue;5506
continue;4996
}5507
}4997
if (raw < 0)5508
if (raw < 0)4998
{ raw = 0; }5509
{ raw = 0; }4999
var u = this.easeInOutCubic(raw);5510
// Non-zero endpoint speed so the handoff matches fallSpeed (t1135).5511
var u = f.miss ? this.easeInOutCubic(raw) : this.smoothParam(raw, 0.85, 0.85);5000
var x, y;5512
var x, y;5001
if (f.miss && f.ctrl)5513
if (f.miss && f.ctrl)5002
{5514
{@@ -5005,21 +5517,15 @@ Online.tickFlights = function (now)5005
x = mt * mt * f.start.x + 2 * mt * e * f.ctrl.x + e * e * f.end.x;5517
x = mt * mt * f.start.x + 2 * mt * e * f.ctrl.x + e * e * f.end.x;5006
y = mt * mt * f.start.y + 2 * mt * e * f.ctrl.y + e * e * f.end.y;5518
y = mt * mt * f.start.y + 2 * mt * e * f.ctrl.y + e * e * f.end.y;5007
}5519
}5008
else if (f.waypoints && f.waypoints.length > 2)5520
else if (f.curve)5009
{5010
var pt = this.pointOnPath(f.waypoints, u);5011
x = pt.x;5012
y = pt.y;5013
}5014
else if (f.waypoints && f.field)5015
{5521
{5016
var pt = this.aroundFieldPoint(f.start, f.end, u, f.field, (f.height || 80) * 0.45);5522
var pt = this.curvePoint(f.curve, u);5017
x = pt.x;5523
x = pt.x;5018
y = pt.y;5524
y = pt.y;5019
}5525
}5020
else5526
else5021
{5527
{5022
var pt = this.arcPoint(f.start, f.end, u, f.height || 80);5528
var pt = this.aroundFieldPoint(f.start, f.end, u, f.field, (f.height || 80) * 0.45);5023
x = pt.x;5529
x = pt.x;5024
y = pt.y;5530
y = pt.y;5025
}5531
}@@ -5060,6 +5566,7 @@ Online.clearFlights = function ()5060
this._flightLocals = {};5566
this._flightLocals = {};5061
this._flightSeen = Object.create(null);5567
this._flightSeen = Object.create(null);5062
this._pendingLandCol = Object.create(null);5568
this._pendingLandCol = Object.create(null);5569
this._previewIds = Object.create(null);5063
};5570
};5064
5571
5065
if (typeof globalThis !== 'undefined')5572
if (typeof globalThis !== 'undefined')@@ -6187,6 +6694,11 @@ function syncSprites (dt)6187
applyBlockVisual(obj, block);6694
applyBlockVisual(obj, block);6188
obj.renderer.visible = true;6695
obj.renderer.visible = true;6189
obj.renderer.alpha = 1;6696
obj.renderer.alpha = 1;6697
if (typeof Online !== 'undefined' && Online.hasExitVisual && Online.hasExitVisual(block.id))6698
{6699
obj.renderer.visible = false;6700
obj.renderer.alpha = 0;6701
}6190
6702
6191
if (block.flame)6703
if (block.flame)6192
{6704
{@@ -6213,6 +6725,10 @@ function syncSprites (dt)6213
}6725
}6214
else if (app.flames[block.id])6726
else if (app.flames[block.id])6215
{ app.flames[block.id].renderer.visible = false; }6727
{ app.flames[block.id].renderer.visible = false; }6728
if (block.flame && app.flames[block.id]6729
&& typeof Online !== 'undefined' && Online.hasExitVisual6730
&& Online.hasExitVisual(block.id))6731
{ app.flames[block.id].renderer.visible = false; }6216
}6732
}6217
6733
6218
var ids = Object.keys(app.sprites);6734
var ids = Object.keys(app.sprites);@@ -6450,6 +6966,7 @@ function tickView (dt)6450
placeTile(app.cells[i], col, row);6966
placeTile(app.cells[i], col, row);6451
}6967
}6452
6968
6969
previewOutgoingFlights();6453
app.core.tick(dt);6970
app.core.tick(dt);6454
if (app.offline && app.battle)6971
if (app.offline && app.battle)6455
{ tickOffline(dt); }6972
{ tickOffline(dt); }@@ -6970,7 +7487,7 @@ function tickOnline (dt)6970
for (var i = 0; i < shots.length; i++)7487
for (var i = 0; i < shots.length; i++)6971
{7488
{6972
var s = shots[i];7489
var s = shots[i];6973
var start = fieldToViewport(s.col, s.y + 1);7490
var start = fieldToViewport(s.col, s.y);6974
Online.rememberFlightLocal(s, start.x, start.y);7491
Online.rememberFlightLocal(s, start.x, start.y);6975
}7492
}6976
Online.queueShots(shots);7493
Online.queueShots(shots);@@ -7048,7 +7565,9 @@ function tickOffline (dt)7048
var s = list[i];7565
var s = list[i];7049
var start;7566
var start;7050
if (s.from_id === 'player')7567
if (s.from_id === 'player')7051
{ start = fieldToViewport(s.col, s.y + 1); }7568
{ start = fieldToViewport(s.col, s.y); }7569
else if (typeof Online !== 'undefined' && Online.miniCellViewport)7570
{ start = Online.miniCellViewport(s.from_id, s.col, s.y != null ? s.y : 12); }7052
else7571
else7053
{ start = miniViewportCenter(s.from_id); }7572
{ start = miniViewportCenter(s.from_id); }7054
locals[s.client_id] = {7573
locals[s.client_id] = {@@ -7292,6 +7811,58 @@ function updateColumnWarn (dt)7292
}7811
}7293
}7812
}7294
7813
7814
/**7815
* Take over a rocket that is about to leave the top of a field (the7816
* player's, or a bot's) so the flight starts at the real cell and7817
* continues its upward motion (t1134). Shared by offline and online.7818
*/7819
function previewOutgoingFlights ()7820
{7821
if (typeof Online === 'undefined' || !Online.previewExit)7822
{ return; }7823
if (app.core)7824
{ previewCoreExits(app.core, null); }7825
if (app.offline && app.battle && app.battle.bots)7826
{7827
var bots = app.battle.bots;7828
for (var i = 0; i < bots.length; i++)7829
{7830
var bot = bots[i];7831
if (bot && bot.core && !bot.eliminated)7832
{ previewCoreExits(bot.core, bot.id); }7833
}7834
}7835
}7836
7837
function previewCoreExits (core, fromId)7838
{7839
if (!core || !core.blocks)7840
{ return; }7841
var blocks = core.blocks;7842
for (var i = 0; i < blocks.length; i++)7843
{7844
var b = blocks[i];7845
if (b.y < 11.6)7846
{ continue; }7847
if (!(b.vy > 0))7848
{ continue; }7849
var start = fromId7850
? (Online.miniCellViewport7851
? Online.miniCellViewport(fromId, b.col, b.y)7852
: miniViewportCenter(fromId))7853
: fieldToViewport(b.col, b.y);7854
Online.previewExit({7855
id: b.id,7856
col: b.col,7857
y: b.y,7858
vy: b.vy,7859
color: b.color,7860
start: start,7861
from_id: fromId || null7862
});7863
}7864
}7865
7295
function fieldToViewport (col, fieldY)7866
function fieldToViewport (col, fieldY)7296
{7867
{7297
var canvas = app.scene && app.scene.canvas;7868
var canvas = app.scene && app.scene.canvas;@@ -7299,7 +7870,8 @@ function fieldToViewport (col, fieldY)7299
{ return { x: window.innerWidth / 2, y: 40 }; }7870
{ return { x: window.innerWidth / 2, y: 40 }; }7300
var rect = canvas.getBoundingClientRect();7871
var rect = canvas.getBoundingClientRect();7301
var x = rect.left + ((col + 0.5) / 10) * rect.width;7872
var x = rect.left + ((col + 0.5) / 10) * rect.width;7302
var y = rect.top + (1 - (fieldY / 13)) * rect.height;7873
// Cell centre matches placeTile: y = fieldH - (fieldY + 0.5) * tile (t1134).7874
var y = rect.top + (1 - ((fieldY + 0.5) / 13)) * rect.height;7303
return { x: x, y: y };7875
return { x: x, y: y };7304
}7876
}7305
7877