BlueGit

projects-timfalken-com meteors

Merge branch 'feature/stage1-physics'

Falling cargo on flying clusters, rigid grey landing, smooth apex
descent, air-resistance bounce, top-block manual launch, and the
Click Tween press-scale on a selected block.

timfa Grok Bot · pushed by timfa

Authored 2026-11-13 · 4 days ago

Hash
4f9b5d42a10ca9db28b78854a7a86f6cd39c4451
Pipeline
Failed
13 files changed +1935 −160
README.md +10 −6
@@ -13,8 +13,10 @@ Live (na de eerste deploy): https://projects.timfalken.com/meteors/
13 13 3. In een stilliggende kolom sleep je blokjes verticaal; ze wisselen om met de blokjes waar je langs gaat.
14 14 4. Drie of meer blokjes van dezelfde kleur op een rij (horizontaal of verticaal) worden donkergrijs, krijgen een vlam en springen omhoog. Alles wat erop stond, vliegt mee.
15 15 5. Blokjes die boven de bovenrand van het veld (10×13) verdwijnen, leveren punten op.
16 6. Trek een blokje naar de top van zijn kolom en dan nóg verder omhoog: het springt tot net onder de bovenrand. Komt het tegen een vliegend cluster aan, dan duwt het die kolom één tegel omhoog. Vormt dat een nieuwe drie-op-een-rij, dan springt het hele cluster opnieuw.
17 7. Een kolom die van onder tot boven vol ligt, gaat op slot (donkergrijs, geen interactie, geen nieuwe val). Zitten alle tien kolommen vast, dan is het spel voorbij en ga je terug naar het menu.
16 6. Trek een blokje naar de top van zijn kolom en dan nóg verder omhoog: het springt tot net onder de bovenrand. Is het blokje al het bovenste van de kolom, dan is een trek voorbij zijn eigen positie genoeg (muis en touch). Komt het tegen een vliegend cluster aan, dan duwt het die kolom één tegel omhoog. Vormt dat een nieuwe drie-op-een-rij, dan springt het hele cluster opnieuw.
17 7. Een vallend (gespawnd) blokje landt op een vliegende cluster in dezelfde kolom en vliegt als vracht mee.
18 8. Een gelande grijze cluster blijft als starre groep liggen — een deel kan boven een gat blijven hangen — tot de blokjes na 3 seconden een kleur terugkrijgen. Daarna vallen ongesteunde blokjes afzonderlijk naar beneden.
19 9. Een kolom die van onder tot boven vol ligt, gaat op slot (donkergrijs, geen interactie, geen nieuwe val). Zitten alle tien kolommen vast, dan is het spel voorbij en ga je terug naar het menu.
18 20
19 21 Het standaardveld is de planeet **Terra** (volk: Terrans), met middelmatige zwaartekracht, luchtweerstand en massa. Die drie waarden, plus de Power, staan in de HUD; later (stage 3) kies je zelf een planeet.
20 22
@@ -47,16 +49,18 @@ De spelkern is deterministisch en staat los van tekenen en invoer, zodat stage 2
47 49
48 50 | Pad | Rol |
49 51 | --- | --- |
50 | `src/planet.js` | Planeet: zwaartekracht, luchtweerstand, massa, kleuren/vormen, spronghoogte, Power |
52 | `src/planet.js` | Planeet: zwaartekracht, luchtweerstand, massa, kleuren/vormen, spronghoogte, Power, apex-ease, bounce |
51 53 | `src/rng.js` | Seedable RNG (tests en later replays) |
52 | `src/gameCore.js` | Simulatie: vallen, wisselen, match-3, raketsprong, linken, push-up + her-sprong, landen + 3 s wachten, kolom-slot, game over, punten |
53 | `src/main.js` | Menu, HUD, frameworkv3-scene, muis/touch, schaal naar het scherm |
54 | `src/easing.js` | Qt-eases (easeOutBack / easeOutElastic) en Click-Tween-defaults voor de selectie-animatie |
55 | `src/gameCore.js` | Simulatie: vallen, wisselen, match-3, raketsprong, linken, push-up + her-sprong, landen als starre groep + 3 s wachten, kolom-slot, game over, punten |
56 | `src/main.js` | Menu, HUD, frameworkv3-scene, muis/touch, schaal naar het scherm, landing-bounce, selectie-tween |
57 | `docs/ASSUMPTIONS.md` | Ingevulde aannames waar de specificatie ruimte liet |
54 58 | `src/build.sh` | Concateneert de bronnen naar `build/game.js` (zelfde patroon als de raytracer) |
55 59 | `build/` | Speelbare output: `index.html`, `style.css`, `framework.js`, `game.js`, `images/` |
56 60 | `test/` | Unit tests (`node --test`) voor de kern en de deploy-guard |
57 61 | `ci/` | FTP-deploy, **zonder** `--delete`. Expandeert `$timftproot` zelf. Weigert een map die niet leeg is of niet van Meteors is. |
58 62
59 Sprongfysica is parametrisch. Een horizontale match van 3 springt `13 / jumpsToClear` tegels hoog; een verticale match van 3 krijgt 120 % daarvan, en elk extra blokje +5 % (wordt nergens in het spel uitgelegd). De massa bepaalt hoe lang de sprong omhoog duurt (onafhankelijk van de hoogte); de luchtweerstand bepaalt de constante valsnelheid daarna.
63 Sprongfysica is parametrisch. Een horizontale match van 3 springt `13 / jumpsToClear` tegels hoog; een verticale match van 3 krijgt 120 % daarvan, en elk extra blokje +5 % (wordt nergens in het spel uitgelegd). De massa bepaalt hoe lang de sprong omhoog duurt (onafhankelijk van de hoogte). Op de apex versnelt de cluster geleidelijk tot de valsnelheid (`apexEaseTime = 0,15 × fallTime`); daarna is de daal snelheid constant. De luchtweerstand (`fallTime`) bepaalt die valsnelheid én hoe snel de visuele landing-bounce is (`bounceDuration = 0,12 × fallTime`). Een vastgehouden blokje krijgt dezelfde schaal-tween als Tim's KWin Click Tween (150 ms easeOutBack naar 80 %, 720 ms easeOutElastic terug). Zie `docs/ASSUMPTIONS.md`.
60 64
61 65 ## Deploy
62 66
@@ -13,8 +13,10 @@ Live (na de eerste deploy): https://projects.timfalken.com/meteors/
133. In een stilliggende kolom sleep je blokjes verticaal; ze wisselen om met de blokjes waar je langs gaat.
133. In een stilliggende kolom sleep je blokjes verticaal; ze wisselen om met de blokjes waar je langs gaat.
144. Drie of meer blokjes van dezelfde kleur op een rij (horizontaal of verticaal) worden donkergrijs, krijgen een vlam en springen omhoog. Alles wat erop stond, vliegt mee.
144. Drie of meer blokjes van dezelfde kleur op een rij (horizontaal of verticaal) worden donkergrijs, krijgen een vlam en springen omhoog. Alles wat erop stond, vliegt mee.
155. Blokjes die boven de bovenrand van het veld (10×13) verdwijnen, leveren punten op.
155. Blokjes die boven de bovenrand van het veld (10×13) verdwijnen, leveren punten op.
166. Trek een blokje naar de top van zijn kolom en dan nóg verder omhoog: het springt tot net onder de bovenrand. Komt het tegen een vliegend cluster aan, dan duwt het die kolom één tegel omhoog. Vormt dat een nieuwe drie-op-een-rij, dan springt het hele cluster opnieuw.
166. Trek een blokje naar de top van zijn kolom en dan nóg verder omhoog: het springt tot net onder de bovenrand. Is het blokje al het bovenste van de kolom, dan is een trek voorbij zijn eigen positie genoeg (muis en touch). Komt het tegen een vliegend cluster aan, dan duwt het die kolom één tegel omhoog. Vormt dat een nieuwe drie-op-een-rij, dan springt het hele cluster opnieuw.
177. Een kolom die van onder tot boven vol ligt, gaat op slot (donkergrijs, geen interactie, geen nieuwe val). Zitten alle tien kolommen vast, dan is het spel voorbij en ga je terug naar het menu.
177. Een vallend (gespawnd) blokje landt op een vliegende cluster in dezelfde kolom en vliegt als vracht mee.
188. Een gelande grijze cluster blijft als starre groep liggen — een deel kan boven een gat blijven hangen — tot de blokjes na 3 seconden een kleur terugkrijgen. Daarna vallen ongesteunde blokjes afzonderlijk naar beneden.
199. Een kolom die van onder tot boven vol ligt, gaat op slot (donkergrijs, geen interactie, geen nieuwe val). Zitten alle tien kolommen vast, dan is het spel voorbij en ga je terug naar het menu.
18
20
19Het standaardveld is de planeet **Terra** (volk: Terrans), met middelmatige zwaartekracht, luchtweerstand en massa. Die drie waarden, plus de Power, staan in de HUD; later (stage 3) kies je zelf een planeet.
21Het standaardveld is de planeet **Terra** (volk: Terrans), met middelmatige zwaartekracht, luchtweerstand en massa. Die drie waarden, plus de Power, staan in de HUD; later (stage 3) kies je zelf een planeet.
20
22
@@ -47,16 +49,18 @@ De spelkern is deterministisch en staat los van tekenen en invoer, zodat stage 2
47
49
48| Pad | Rol |
50| Pad | Rol |
49| --- | --- |
51| --- | --- |
50| `src/planet.js` | Planeet: zwaartekracht, luchtweerstand, massa, kleuren/vormen, spronghoogte, Power |
52| `src/planet.js` | Planeet: zwaartekracht, luchtweerstand, massa, kleuren/vormen, spronghoogte, Power, apex-ease, bounce |
51| `src/rng.js` | Seedable RNG (tests en later replays) |
53| `src/rng.js` | Seedable RNG (tests en later replays) |
52| `src/gameCore.js` | Simulatie: vallen, wisselen, match-3, raketsprong, linken, push-up + her-sprong, landen + 3 s wachten, kolom-slot, game over, punten |
54| `src/easing.js` | Qt-eases (easeOutBack / easeOutElastic) en Click-Tween-defaults voor de selectie-animatie |
53| `src/main.js` | Menu, HUD, frameworkv3-scene, muis/touch, schaal naar het scherm |
55| `src/gameCore.js` | Simulatie: vallen, wisselen, match-3, raketsprong, linken, push-up + her-sprong, landen als starre groep + 3 s wachten, kolom-slot, game over, punten |
56| `src/main.js` | Menu, HUD, frameworkv3-scene, muis/touch, schaal naar het scherm, landing-bounce, selectie-tween |
57| `docs/ASSUMPTIONS.md` | Ingevulde aannames waar de specificatie ruimte liet |
54| `src/build.sh` | Concateneert de bronnen naar `build/game.js` (zelfde patroon als de raytracer) |
58| `src/build.sh` | Concateneert de bronnen naar `build/game.js` (zelfde patroon als de raytracer) |
55| `build/` | Speelbare output: `index.html`, `style.css`, `framework.js`, `game.js`, `images/` |
59| `build/` | Speelbare output: `index.html`, `style.css`, `framework.js`, `game.js`, `images/` |
56| `test/` | Unit tests (`node --test`) voor de kern en de deploy-guard |
60| `test/` | Unit tests (`node --test`) voor de kern en de deploy-guard |
57| `ci/` | FTP-deploy, **zonder** `--delete`. Expandeert `$timftproot` zelf. Weigert een map die niet leeg is of niet van Meteors is. |
61| `ci/` | FTP-deploy, **zonder** `--delete`. Expandeert `$timftproot` zelf. Weigert een map die niet leeg is of niet van Meteors is. |
58
62
59Sprongfysica is parametrisch. Een horizontale match van 3 springt `13 / jumpsToClear` tegels hoog; een verticale match van 3 krijgt 120 % daarvan, en elk extra blokje +5 % (wordt nergens in het spel uitgelegd). De massa bepaalt hoe lang de sprong omhoog duurt (onafhankelijk van de hoogte); de luchtweerstand bepaalt de constante valsnelheid daarna.
63Sprongfysica is parametrisch. Een horizontale match van 3 springt `13 / jumpsToClear` tegels hoog; een verticale match van 3 krijgt 120 % daarvan, en elk extra blokje +5 % (wordt nergens in het spel uitgelegd). De massa bepaalt hoe lang de sprong omhoog duurt (onafhankelijk van de hoogte). Op de apex versnelt de cluster geleidelijk tot de valsnelheid (`apexEaseTime = 0,15 × fallTime`); daarna is de daal snelheid constant. De luchtweerstand (`fallTime`) bepaalt die valsnelheid én hoe snel de visuele landing-bounce is (`bounceDuration = 0,12 × fallTime`). Een vastgehouden blokje krijgt dezelfde schaal-tween als Tim's KWin Click Tween (150 ms easeOutBack naar 80 %, 720 ms easeOutElastic terug). Zie `docs/ASSUMPTIONS.md`.
60
64
61## Deploy
65## Deploy
62
66
build/game.js +693 −75
@@ -121,7 +121,14 @@ function createPlanet (opts)
121 121 riseTime: riseTime,
122 122 colors: colors,
123 123 baseJumpHeight: FIELD_HEIGHT / jumpsToClear,
124 fallSpeed: FIELD_HEIGHT / fallTime
124 fallSpeed: FIELD_HEIGHT / fallTime,
125 // Time to ease from vy=0 at the apex to terminal fallSpeed.
126 // Shorter when air resistance is low (small fallTime).
127 apexEaseTime: 0.15 * fallTime,
128 fallAccel: (FIELD_HEIGHT / fallTime) / (0.15 * fallTime),
129 // Visual landing bounce: faster at low air resistance. Stage-3 params.
130 bounceDuration: 0.12 * fallTime,
131 bounceSquash: 0.16
125 132 };
126 133 return planet;
127 134 }
@@ -232,6 +239,127 @@ else if (typeof globalThis !== 'undefined')
232 239 * /workspace/meteors/src/planet.js
233 240 */
234 241
242 /*
243 * Start File:
244 * /workspace/meteors/src/easing.js
245 */
246 'use strict';
247
248 /**
249 * Easing curves matching Qt QEasingCurve defaults (the same values Tim's
250 * KWin Click Tween effect uses). Formulas and default parameters come from
251 * Qt 6's QEasingCurve and https://easings.net/.
252 *
253 * Source of the click/release defaults:
254 * /workspace/click-tween/settings.h (clickTime, releaseTime, easing names)
255 * /workspace/click-tween/clicktween.cpp (press scale 0.8, release scale 1.0)
256 * /workspace/click-tween/README.md
257 */
258
259 /** Qt QEasingCurve default overshoot for InBack / OutBack / InOutBack. */
260 var BACK_OVERSHOOT = 1.70158;
261
262 /** Qt QEasingCurve default period and amplitude for Elastic curves. */
263 var ELASTIC_PERIOD = 0.3;
264 var ELASTIC_AMPLITUDE = 1.0;
265
266 function clamp01 (t)
267 {
268 if (t <= 0)
269 { return 0; }
270 if (t >= 1)
271 { return 1; }
272 return t;
273 }
274
275 /** easeOutBack: overshoots the end value, then settles. Qt / easings.net. */
276 function easeOutBack (t)
277 {
278 t = clamp01(t);
279 var c1 = BACK_OVERSHOOT;
280 var c3 = c1 + 1;
281 var u = t - 1;
282 return 1 + c3 * u * u * u + c1 * u * u;
283 }
284
285 /**
286 * easeOutElastic: decaying sine overshoot past the end value.
287 * Qt default amplitude 1, period 0.3 (equivalent to easings.net).
288 */
289 function easeOutElastic (t)
290 {
291 t = clamp01(t);
292 if (t === 0 || t === 1)
293 { return t; }
294 var p = ELASTIC_PERIOD;
295 var s = p / 4;
296 return Math.pow(2, -10 * t) * Math.sin((t - s) * (2 * Math.PI) / p) + 1;
297 }
298
299 function tween (from, to, t, ease)
300 {
301 return from + (to - from) * ease(clamp01(t));
302 }
303
304 /**
305 * DEFAULT settings of Tim's KWin Click Tween
306 * (git.timfalken.com/timfa/click-tween).
307 *
308 * Press: shrink to 80% in 150 ms with easeOutBack, stay at 80% while held.
309 * Release: grow back to 100% in 720 ms with easeOutElastic.
310 * Mid-animation release starts from the current scale, like QVariantAnimation.
311 */
312 var CLICK_TWEEN = {
313 pressScale: 0.8,
314 releaseScale: 1.0,
315 pressDuration: 0.150,
316 releaseDuration: 0.720,
317 pressEase: easeOutBack,
318 releaseEase: easeOutElastic,
319 backOvershoot: BACK_OVERSHOOT,
320 elasticPeriod: ELASTIC_PERIOD,
321 elasticAmplitude: ELASTIC_AMPLITUDE,
322 source: 'click-tween settings.h + clicktween.cpp (Qt QEasingCurve defaults)'
323 };
324
325 /**
326 * Visual landing bounce, u in 0..1. Subtle squash with a slight stretch
327 * on the other axis and a tiny upward rebound (in tiles, visual only).
328 */
329 function bouncePose (u, squash)
330 {
331 if (u <= 0 || u >= 1)
332 { return { sx: 1, sy: 1, dy: 0 }; }
333 var wave = Math.sin(Math.PI * u);
334 return {
335 sx: 1 + squash * 0.6 * wave,
336 sy: 1 - squash * wave,
337 dy: 0.07 * wave * (1 - u)
338 };
339 }
340
341 var Easing = {
342 BACK_OVERSHOOT: BACK_OVERSHOOT,
343 ELASTIC_PERIOD: ELASTIC_PERIOD,
344 ELASTIC_AMPLITUDE: ELASTIC_AMPLITUDE,
345 easeOutBack: easeOutBack,
346 easeOutElastic: easeOutElastic,
347 tween: tween,
348 CLICK_TWEEN: CLICK_TWEEN,
349 clamp01: clamp01,
350 bouncePose: bouncePose
351 };
352
353 if (typeof module !== 'undefined' && module.exports)
354 { module.exports = Easing; }
355 else if (typeof globalThis !== 'undefined')
356 { globalThis.Easing = Easing; }
357
358 /*
359 * End File:
360 * /workspace/meteors/src/easing.js
361 */
362
235 363 /*
236 364 * Start File:
237 365 * /workspace/meteors/src/gameCore.js
@@ -260,6 +388,8 @@ var STATE_MANUAL = 'manual';
260 388 var ALIGN_EPS = 0.15;
261 389 var SUBSTEP = 1 / 120;
262 390 var DRAG_LAUNCH_SLACK = 0.65;
391 // Upward pull (tiles past the press point) that launches an already-topmost block.
392 var LAUNCH_PULL = 0.35;
263 393
264 394 function UnionFind ()
265 395 {
@@ -309,6 +439,7 @@ function GameCore (planet, rng)
309 439 }
310 440
311 441 GameCore.COLOR_GRAY = COLOR_GRAY;
442 GameCore.LAUNCH_PULL = LAUNCH_PULL;
312 443 GameCore.STATE_STILL = STATE_STILL;
313 444 GameCore.STATE_FALLING = STATE_FALLING;
314 445 GameCore.STATE_FLYING = STATE_FLYING;
@@ -336,7 +467,9 @@ GameCore.prototype.createBlock = function (col, y, color, state)
336 467 pushedClusters: null,
337 468 manualTarget: 0,
338 469 manualDecel: 0,
339 manualPhase: null
470 manualPhase: null,
471 bouncing: false,
472 bounceAge: 0
340 473 };
341 474 this.blocks.push(block);
342 475 return block;
@@ -474,6 +607,199 @@ GameCore.prototype.lockedColumnCount = function ()
474 607 return n;
475 608 };
476 609
610 GameCore.prototype.startBounce = function (block)
611 {
612 if (!block)
613 { return; }
614 block.bouncing = true;
615 block.bounceAge = 0;
616 };
617
618 GameCore.prototype.advanceBounces = function (dt)
619 {
620 var duration = this.planet.bounceDuration;
621 for (var i = 0; i < this.blocks.length; i++)
622 {
623 var block = this.blocks[i];
624 if (!block.bouncing)
625 { continue; }
626 block.bounceAge += dt;
627 if (duration <= 0 || block.bounceAge >= duration)
628 {
629 block.bouncing = false;
630 block.bounceAge = duration;
631 }
632 }
633 };
634
635 /**
636 * True if `block` rests on the floor or on a solid (still / settling /
637 * locked) block immediately below it in the same column.
638 */
639 GameCore.prototype.hasSupport = function (block)
640 {
641 if (block.y <= 1e-9)
642 { return true; }
643 for (var i = 0; i < this.blocks.length; i++)
644 {
645 var other = this.blocks[i];
646 if (other === block || other.col !== block.col)
647 { continue; }
648 if (!this.isGrounded(other))
649 { continue; }
650 if (Math.abs((other.y + 1) - block.y) < ALIGN_EPS)
651 { return true; }
652 }
653 return false;
654 };
655
656 /** Highest flying block in this column whose top is at or below `block.y + 1`. */
657 GameCore.prototype.highestFlyingBelow = function (block)
658 {
659 var best = null;
660 for (var i = 0; i < this.blocks.length; i++)
661 {
662 var other = this.blocks[i];
663 if (other === block || other.col !== block.col)
664 { continue; }
665 if (other.state !== STATE_FLYING || other.clusterId == null)
666 { continue; }
667 var cluster = this.clusters[other.clusterId];
668 if (!cluster || cluster.phase === 'landed')
669 { continue; }
670 // The falling block is at or above this flyer (or already overlapping).
671 if (block.y + 1e-9 < other.y)
672 { continue; }
673 if (!best || other.y > best.y)
674 { best = other; }
675 }
676 return best;
677 };
678
679 GameCore.prototype.highestFallingBelow = function (block)
680 {
681 var best = null;
682 for (var i = 0; i < this.blocks.length; i++)
683 {
684 var other = this.blocks[i];
685 if (other === block || other.col !== block.col)
686 { continue; }
687 if (other.state !== STATE_FALLING)
688 { continue; }
689 if (other.y > block.y - 1e-9)
690 { continue; }
691 if (!best || other.y > best.y)
692 { best = other; }
693 }
694 return best;
695 };
696
697 /**
698 * Make an unsupported still block start falling from rest, so it eases
699 * into fallSpeed under normal gravity. Skips the block being dragged.
700 */
701 GameCore.prototype.releaseUnsupported = function ()
702 {
703 for (var i = 0; i < this.blocks.length; i++)
704 {
705 var block = this.blocks[i];
706 if (block.state !== STATE_STILL)
707 { continue; }
708 if (this.drag && this.drag.blockId === block.id)
709 { continue; }
710 if (this.hasSupport(block))
711 { continue; }
712 block.state = STATE_FALLING;
713 block.vy = 0;
714 block.flame = false;
715 this.leaveCluster(block);
716 }
717 };
718
719 GameCore.prototype.accelerateFall = function (block, dt)
720 {
721 var target = -this.planet.fallSpeed;
722 if (block.vy > target)
723 { block.vy = Math.max(target, block.vy - this.planet.fallAccel * dt); }
724 else
725 { block.vy = target; }
726 };
727
728 GameCore.prototype.landFallingBlock = function (block)
729 {
730 block.vy = 0;
731 block.flame = false;
732 this.startBounce(block);
733 if (block.color === COLOR_GRAY)
734 {
735 block.state = STATE_SETTLING;
736 block.settleTime = 0;
737 }
738 else
739 { block.state = STATE_STILL; }
740 };
741
742 /**
743 * Sit `block` on top of the flying cluster that `flyer` belongs to, and
744 * carry it along as cargo (no flame). Returns true if attached.
745 */
746 GameCore.prototype.attachToFlyingCluster = function (block, flyer)
747 {
748 var cluster = this.clusters[flyer.clusterId];
749 if (!cluster || cluster.phase === 'landed')
750 { return false; }
751 var roof = flyer.y + 1;
752 for (var i = 0; i < this.blocks.length; i++)
753 {
754 var other = this.blocks[i];
755 if (other === block || other.col !== block.col)
756 { continue; }
757 if (other.clusterId !== cluster.id)
758 { continue; }
759 if (other.y + 1 > roof)
760 { roof = other.y + 1; }
761 }
762 block.y = roof;
763 block.state = STATE_FLYING;
764 block.clusterId = cluster.id;
765 block.vy = cluster.vy;
766 block.flame = false;
767 block.settleTime = 0;
768 return true;
769 };
770
771 GameCore.prototype.catchFallingOntoCluster = function (cluster, members)
772 {
773 if (!cluster || cluster.phase === 'landed' || cluster.phase === 'hold')
774 { return; }
775 // Snapshot falling blocks; attaching mutates state.
776 var falling = [];
777 for (var i = 0; i < this.blocks.length; i++)
778 {
779 if (this.blocks[i].state === STATE_FALLING)
780 { falling.push(this.blocks[i]); }
781 }
782 for (var i = 0; i < falling.length; i++)
783 {
784 var block = falling[i];
785 var flyer = null;
786 for (var m = 0; m < members.length; m++)
787 {
788 var other = members[m];
789 if (other.col !== block.col)
790 { continue; }
791 // Overlap or rest on this member's top.
792 if (block.y < other.y + 1 + 1e-9 && block.y + 1 > other.y - 1e-9)
793 {
794 if (!flyer || other.y > flyer.y)
795 { flyer = other; }
796 }
797 }
798 if (flyer)
799 { this.attachToFlyingCluster(block, flyer); }
800 }
801 };
802
477 803 GameCore.prototype.tick = function (dt)
478 804 {
479 805 if (this.state === 'gameover')
@@ -503,7 +829,9 @@ GameCore.prototype.tick = function (dt)
503 829 left -= step;
504 830 }
505 831
832 this.releaseUnsupported();
506 833 this.advanceSettle(dt);
834 this.advanceBounces(dt);
507 835 if (!this.drag)
508 836 { this.resolveMatches(); }
509 837 this.checkLocks();
@@ -551,24 +879,42 @@ GameCore.prototype.trySpawn = function ()
551 879 { return null; }
552 880 var col = eligible[Math.floor(this.rng() * eligible.length) % eligible.length];
553 881 var color = this.randomColor();
554 return this.createBlock(col, this.height, color, STATE_FALLING);
882 var block = this.createBlock(col, this.height, color, STATE_FALLING);
883 block.vy = -this.planet.fallSpeed;
884 return block;
555 885 };
556 886
557 887 GameCore.prototype.integrateFalling = function (dt)
558 888 {
559 var speed = this.planet.fallSpeed;
889 var falling = [];
560 890 for (var i = 0; i < this.blocks.length; i++)
561 891 {
562 var block = this.blocks[i];
892 if (this.blocks[i].state === STATE_FALLING)
893 { falling.push(this.blocks[i]); }
894 }
895 // Lowest first, so a stack of falling blocks rests on itself.
896 falling.sort(function (a, b) { return a.y - b.y; });
897 for (var i = 0; i < falling.length; i++)
898 {
899 var block = falling[i];
563 900 if (block.state !== STATE_FALLING)
564 901 { continue; }
902 this.accelerateFall(block, dt);
903 var nextY = block.y + block.vy * dt;
904 var flyer = this.highestFlyingBelow(block);
905 if (flyer && nextY <= flyer.y + 1 + 1e-9)
906 {
907 if (this.attachToFlyingCluster(block, flyer))
908 { continue; }
909 }
565 910 var top = this.stackTop(block.col);
566 var nextY = block.y - speed * dt;
911 var below = this.highestFallingBelow(block);
912 if (below && below.y + 1 > top)
913 { top = below.y + 1; }
567 914 if (nextY <= top)
568 915 {
569 916 block.y = top;
570 block.state = STATE_STILL;
571 block.vy = 0;
917 this.landFallingBlock(block);
572 918 }
573 919 else
574 920 { block.y = nextY; }
@@ -591,7 +937,8 @@ GameCore.prototype.clusterMembers = function (clusterId)
591 937 * Advance a jump (cluster or manual) by dt. Uses exact kinematics so a
592 938 * jump of height H peaks at exactly H after riseTime. Returns dy.
593 939 * Mutates body.vy and body.phase ('up' / 'down'). body.decel is the
594 * upward deceleration; falling uses planet.fallSpeed.
940 * upward deceleration. After the apex, vy eases from 0 to -fallSpeed
941 * at planet.fallAccel, then stays at terminal fallSpeed.
595 942 */
596 943 GameCore.prototype.advanceJump = function (body, dt)
597 944 {
@@ -624,8 +971,35 @@ GameCore.prototype.advanceJump = function (body, dt)
624 971 }
625 972 if (body.phase === 'down' && left > 0)
626 973 {
627 body.vy = -this.planet.fallSpeed;
628 dy += body.vy * left;
974 var target = -this.planet.fallSpeed;
975 var accel = this.planet.fallAccel;
976 if (accel < 1e-12)
977 {
978 body.vy = target;
979 dy += body.vy * left;
980 }
981 else if (body.vy > target + 1e-12)
982 {
983 var tReach = (body.vy - target) / accel;
984 if (tReach <= left + 1e-15)
985 {
986 dy += (body.vy + target) * 0.5 * tReach;
987 body.vy = target;
988 left -= tReach;
989 dy += body.vy * left;
990 }
991 else
992 {
993 var vyNew = body.vy - accel * left;
994 dy += (body.vy + vyNew) * 0.5 * left;
995 body.vy = vyNew;
996 }
997 }
998 else
999 {
1000 body.vy = target;
1001 dy += body.vy * left;
1002 }
629 1003 }
630 1004 return dy;
631 1005 };
@@ -654,14 +1028,18 @@ GameCore.prototype.integrateClusters = function (dt)
654 1028 members[i].vy = cluster.vy;
655 1029 }
656 1030
1031 this.catchFallingOntoCluster(cluster, members);
1032
657 1033 if (cluster.phase === 'down')
658 { this.tryLandCluster(cluster, members); }
1034 { this.tryLandCluster(cluster, this.clusterMembers(cluster.id)); }
659 1035 }
660 1036 };
661 1037
662 1038 GameCore.prototype.tryLandCluster = function (cluster, members)
663 1039 {
664 var self = this;
1040 if (!members.length)
1041 { return; }
1042 var shift = 0;
665 1043 var hit = false;
666 1044 for (var i = 0; i < members.length; i++)
667 1045 {
@@ -671,63 +1049,109 @@ GameCore.prototype.tryLandCluster = function (cluster, members)
671 1049 return other.clusterId === cluster.id;
672 1050 });
673 1051 if (block.y <= top + 1e-9)
674 { hit = true; }
1052 {
1053 hit = true;
1054 var need = top - block.y;
1055 if (need > shift)
1056 { shift = need; }
1057 }
675 1058 }
676 1059 if (!hit)
677 1060 { return; }
1061 // Lift the whole rigid body so the deepest contact sits flush.
1062 for (var i = 0; i < members.length; i++)
1063 { members[i].y += shift; }
678 1064 this.landCluster(cluster, members);
679 1065 };
680 1066
1067 /**
1068 * Land as a rigid group: relative positions are kept, so part of the
1069 * cluster may hang above a gap. Grey members start the 3s settle timer;
1070 * coloured cargo stays put with them until every grey has recolored.
1071 * Members that actually rest on the floor or on another block bounce.
1072 */
681 1073 GameCore.prototype.landCluster = function (cluster, members)
682 1074 {
683 var byCol = Object.create(null);
684 1075 for (var i = 0; i < members.length; i++)
685 1076 {
686 1077 var block = members[i];
687 if (!byCol[block.col])
688 { byCol[block.col] = []; }
689 byCol[block.col].push(block);
1078 block.vy = 0;
1079 block.flame = false;
1080 block.clusterId = cluster.id;
1081 if (block.color === COLOR_GRAY)
1082 {
1083 block.state = STATE_SETTLING;
1084 block.settleTime = 0;
1085 }
1086 else
1087 {
1088 // Cargo stays in the rigid group (not matchable) until release.
1089 block.state = STATE_SETTLING;
1090 block.settleTime = 0;
1091 }
1092 if (this.hasSupport(block))
1093 { this.startBounce(block); }
690 1094 }
691 var cols = Object.keys(byCol);
692 for (var c = 0; c < cols.length; c++)
1095 cluster.phase = 'landed';
1096 cluster.vy = 0;
1097 };
1098
1099 /**
1100 * After every grey in a landed cluster has recolored, let the group go.
1101 * Unsupported blocks fall individually from rest; supported ones stay.
1102 */
1103 GameCore.prototype.releaseLandedCluster = function (cluster)
1104 {
1105 var members = this.clusterMembers(cluster.id);
1106 var releasing = Object.create(null);
1107 for (var i = 0; i < members.length; i++)
1108 { releasing[members[i].id] = true; }
1109
1110 for (var i = 0; i < members.length; i++)
693 1111 {
694 var col = +cols[c];
695 var list = byCol[col];
696 list.sort(function (a, b) { return a.y - b.y; });
697 var self = this;
698 var top = this.stackTop(col, function (other)
1112 var block = members[i];
1113 if (block.color === COLOR_GRAY)
699 1114 {
700 return other.clusterId === cluster.id;
701 });
702 for (var i = 0; i < list.length; i++)
1115 block.color = this.randomColor();
1116 block.settleTime = 0;
1117 }
1118 block.flame = false;
1119 this.leaveCluster(block);
1120 // Support from outside the group (floor or a foreign block). Fellow
1121 // members that will also fall do not count, so a hanging stack
1122 // drops together without the top one staying put.
1123 var supported = this.hasSupportOutside(block, releasing);
1124 if (supported)
703 1125 {
704 var block = list[i];
705 block.y = top;
1126 block.state = STATE_STILL;
1127 block.vy = 0;
1128 }
1129 else
1130 {
1131 block.state = STATE_FALLING;
706 1132 block.vy = 0;
707 block.flame = false;
708 top = block.y + 1;
709 if (block.color === COLOR_GRAY)
710 {
711 block.state = STATE_SETTLING;
712 block.settleTime = 0;
713 }
714 else
715 {
716 block.state = STATE_STILL;
717 block.clusterId = null;
718 }
719 1133 }
720 1134 }
721 cluster.phase = 'landed';
722 cluster.vy = 0;
723 var remaining = 0;
1135 delete this.clusters[cluster.id];
1136 };
1137
1138 GameCore.prototype.hasSupportOutside = function (block, ignoreIds)
1139 {
1140 if (block.y <= 1e-9)
1141 { return true; }
724 1142 for (var i = 0; i < this.blocks.length; i++)
725 1143 {
726 if (this.blocks[i].clusterId === cluster.id)
727 { remaining++; }
1144 var other = this.blocks[i];
1145 if (other === block || other.col !== block.col)
1146 { continue; }
1147 if (ignoreIds && ignoreIds[other.id])
1148 { continue; }
1149 if (!this.isGrounded(other))
1150 { continue; }
1151 if (Math.abs((other.y + 1) - block.y) < ALIGN_EPS)
1152 { return true; }
728 1153 }
729 if (remaining === 0)
730 { delete this.clusters[cluster.id]; }
1154 return false;
731 1155 };
732 1156
733 1157 GameCore.prototype.integrateManual = function (dt)
@@ -764,8 +1188,11 @@ GameCore.prototype.integrateManual = function (dt)
764 1188
765 1189 if (block.manualPhase === 'down')
766 1190 {
1191 var proxy = { phase: 'down', vy: block.vy, decel: 0 };
1192 var dy = this.advanceJump(proxy, dt);
1193 block.vy = proxy.vy;
1194 var nextY = block.y + dy;
767 1195 var top = this.stackTop(block.col);
768 var nextY = block.y - this.planet.fallSpeed * dt;
769 1196 if (nextY <= top)
770 1197 {
771 1198 block.y = top;
@@ -773,11 +1200,11 @@ GameCore.prototype.integrateManual = function (dt)
773 1200 block.vy = 0;
774 1201 block.manualPhase = null;
775 1202 block.flame = false;
1203 this.startBounce(block);
776 1204 }
777 1205 else
778 1206 {
779 1207 block.y = Math.min(nextY, this.height - 1);
780 block.vy = -this.planet.fallSpeed;
781 1208 }
782 1209 }
783 1210 }
@@ -936,16 +1363,65 @@ GameCore.prototype.advanceSettle = function (dt)
936 1363 var block = this.blocks[i];
937 1364 if (block.state !== STATE_SETTLING)
938 1365 { continue; }
939 block.settleTime += dt;
940 if (block.settleTime >= this.settleTime)
1366 var inLanded = block.clusterId != null
1367 && this.clusters[block.clusterId]
1368 && this.clusters[block.clusterId].phase === 'landed';
1369 if (block.color === COLOR_GRAY)
941 1370 {
942 block.color = this.randomColor();
943 block.state = STATE_STILL;
944 block.settleTime = 0;
945 block.flame = false;
1371 block.settleTime += dt;
1372 if (block.settleTime >= this.settleTime)
1373 {
1374 block.color = this.randomColor();
1375 block.settleTime = 0;
1376 block.flame = false;
1377 if (inLanded)
1378 {
1379 // Stay in the rigid group; releaseLandedCluster runs below.
1380 block.state = STATE_SETTLING;
1381 }
1382 else
1383 {
1384 this.leaveCluster(block);
1385 if (this.hasSupport(block))
1386 {
1387 block.state = STATE_STILL;
1388 block.vy = 0;
1389 }
1390 else
1391 {
1392 block.state = STATE_FALLING;
1393 block.vy = 0;
1394 }
1395 }
1396 }
1397 }
1398 else if (!inLanded)
1399 {
1400 // Coloured settling that is not in a landed cluster (shouldn't
1401 // normally happen): just become still or fall.
946 1402 this.leaveCluster(block);
1403 block.state = this.hasSupport(block) ? STATE_STILL : STATE_FALLING;
1404 if (block.state === STATE_FALLING)
1405 { block.vy = 0; }
947 1406 }
948 1407 }
1408
1409 var ids = Object.keys(this.clusters);
1410 for (var n = 0; n < ids.length; n++)
1411 {
1412 var cluster = this.clusters[ids[n]];
1413 if (!cluster || cluster.phase !== 'landed')
1414 { continue; }
1415 var members = this.clusterMembers(cluster.id);
1416 var greySettling = false;
1417 for (var i = 0; i < members.length; i++)
1418 {
1419 if (members[i].color === COLOR_GRAY && members[i].state === STATE_SETTLING)
1420 { greySettling = true; }
1421 }
1422 if (!greySettling)
1423 { this.releaseLandedCluster(cluster); }
1424 }
949 1425 };
950 1426
951 1427 GameCore.prototype.findMatchLines = function ()
@@ -1258,7 +1734,15 @@ GameCore.prototype.beginDrag = function (col, y)
1258 1734 var block = this.blockAt(col, row);
1259 1735 if (!block || block.state !== STATE_STILL || block.color < 0)
1260 1736 { return false; }
1261 this.drag = { blockId: block.id, pointerY: y, launchIntent: false };
1737 var top = this.columnStackTopRow(col);
1738 var startedAsTop = Math.abs(block.y - top) < ALIGN_EPS;
1739 this.drag = {
1740 blockId: block.id,
1741 pointerY: y,
1742 startY: y,
1743 launchIntent: false,
1744 startedAsTop: startedAsTop
1745 };
1262 1746 return true;
1263 1747 };
1264 1748
@@ -1280,9 +1764,19 @@ GameCore.prototype.moveDrag = function (y)
1280 1764 this.drag.pointerY = y;
1281 1765 this.swapToward(block, y);
1282 1766 var top = this.columnStackTopRow(block.col);
1283 // The top block occupies [top, top+1). Launch only when the pointer
1284 // is pulled into the empty space above the stack.
1285 this.drag.launchIntent = (Math.abs(block.y - top) < ALIGN_EPS && y > top + 1 + 0.25);
1767 var isTop = Math.abs(block.y - top) < ALIGN_EPS;
1768 if (this.drag.startedAsTop)
1769 {
1770 // Already the topmost block: pulling upward past its own position
1771 // (LAUNCH_PULL tiles above the press point) starts a manual jump.
1772 this.drag.launchIntent = isTop && (y > this.drag.startY + LAUNCH_PULL);
1773 }
1774 else
1775 {
1776 // Started mid-stack: swap first, and only launch once the pointer
1777 // is pulled into the empty space above the (new) top.
1778 this.drag.launchIntent = isTop && (y > top + 1 + 0.25);
1779 }
1286 1780 };
1287 1781
1288 1782 GameCore.prototype.endDrag = function ()
@@ -1493,7 +1987,8 @@ var app = {
1493 1987 flames: Object.create(null),
1494 1988 cells: [],
1495 1989 pointerId: null,
1496 gameOverShown: false
1990 gameOverShown: false,
1991 selectTween: null
1497 1992 };
1498 1993
1499 1994 window.onload = function ()
@@ -1539,6 +2034,7 @@ function startPlay ()
1539 2034 app.flames = Object.create(null);
1540 2035 app.cells = [];
1541 2036 app.pointerId = null;
2037 app.selectTween = null;
1542 2038
1543 2039 layout();
1544 2040 app.scene = new Scene(app.fieldX, app.fieldY, app.fieldW, app.fieldH);
@@ -1566,6 +2062,7 @@ function returnToMenu ()
1566 2062 app.sprites = Object.create(null);
1567 2063 app.flames = Object.create(null);
1568 2064 app.cells = [];
2065 app.selectTween = null;
1569 2066
1570 2067 hideEl('hud');
1571 2068 hideEl('game-over');
@@ -1664,6 +2161,7 @@ function syncSprites ()
1664 2161 }
1665 2162 obj.renderer.sprite = spriteFor(block);
1666 2163 placeTile(obj, block.col, block.y);
2164 applyBlockVisual(obj, block);
1667 2165 obj.renderer.visible = true;
1668 2166 obj.renderer.alpha = 1;
1669 2167
@@ -1703,6 +2201,96 @@ function syncSprites ()
1703 2201 }
1704 2202 }
1705 2203
2204 function applyBlockVisual (obj, block)
2205 {
2206 var t = app.tile;
2207 var sx = 1;
2208 var sy = 1;
2209 var dy = 0;
2210 if (block.bouncing && app.planet && app.planet.bounceDuration > 0
2211 && typeof Easing !== 'undefined' && Easing.bouncePose)
2212 {
2213 var u = block.bounceAge / app.planet.bounceDuration;
2214 var pose = Easing.bouncePose(u, app.planet.bounceSquash);
2215 sx = pose.sx;
2216 sy = pose.sy;
2217 dy = pose.dy;
2218 }
2219 var sel = 1;
2220 var tw = app.selectTween;
2221 if (tw && tw.blockId === block.id && tw.phase !== 'idle')
2222 { sel = tw.scale; }
2223 obj.transform.size = { x: t * sx * sel, y: t * sy * sel };
2224 if (dy)
2225 { obj.transform.position.y -= dy * t; }
2226 }
2227
2228 function clickTween ()
2229 {
2230 return (typeof Easing !== 'undefined' && Easing.CLICK_TWEEN) ? Easing.CLICK_TWEEN : null;
2231 }
2232
2233 function startPressTween (blockId)
2234 {
2235 var c = clickTween();
2236 if (!c)
2237 { return; }
2238 var from = (app.selectTween && app.selectTween.phase !== 'idle') ? app.selectTween.scale : 1;
2239 app.selectTween = {
2240 blockId: blockId,
2241 from: from,
2242 to: c.pressScale,
2243 t: 0,
2244 duration: c.pressDuration,
2245 ease: c.pressEase,
2246 scale: from,
2247 phase: 'press'
2248 };
2249 }
2250
2251 function startReleaseTween ()
2252 {
2253 var c = clickTween();
2254 var tw = app.selectTween;
2255 if (!c || !tw || tw.phase === 'idle')
2256 { return; }
2257 app.selectTween = {
2258 blockId: tw.blockId,
2259 from: tw.scale,
2260 to: c.releaseScale,
2261 t: 0,
2262 duration: c.releaseDuration,
2263 ease: c.releaseEase,
2264 scale: tw.scale,
2265 phase: 'release'
2266 };
2267 }
2268
2269 function updateSelectTween (dt)
2270 {
2271 var tw = app.selectTween;
2272 if (!tw || tw.phase === 'idle' || tw.phase === 'hold')
2273 { return; }
2274 tw.t += dt;
2275 var u = tw.duration > 0 ? tw.t / tw.duration : 1;
2276 if (u >= 1)
2277 {
2278 tw.scale = tw.to;
2279 tw.t = tw.duration;
2280 if (tw.phase === 'press')
2281 { tw.phase = 'hold'; }
2282 else
2283 {
2284 tw.phase = 'idle';
2285 tw.scale = 1;
2286 tw.blockId = null;
2287 }
2288 return;
2289 }
2290 var ease = tw.ease || (typeof Easing !== 'undefined' && Easing.easeOutBack);
2291 tw.scale = ease ? Easing.tween(tw.from, tw.to, u, ease) : tw.from + (tw.to - tw.from) * u;
2292 }
2293
1706 2294 function refreshHud ()
1707 2295 {
1708 2296 if (!app.core)
@@ -1743,6 +2331,7 @@ function tickView (dt)
1743 2331 }
1744 2332
1745 2333 app.core.tick(dt);
2334 updateSelectTween(dt);
1746 2335 syncSprites();
1747 2336 refreshHud();
1748 2337
@@ -1758,31 +2347,51 @@ function tickView (dt)
1758 2347 }
1759 2348
1760 2349 /* ---------- pointer input (mouse + touch) --------------------------- */
2350 /*
2351 * Both mouse and touch use Pointer Events. After pointerdown we listen
2352 * on window, so a drag that leaves the canvas (needed to launch a
2353 * block at the top of a full column) still reaches moveDrag. We do
2354 * not treat lostpointercapture as the end of a drag: on some touch
2355 * browsers that fires mid-gesture and would cancel a launch.
2356 */
1761 2357
1762 2358 var boundCanvas = null;
2359 var windowListening = false;
2360
2361 function addWindowPointer ()
2362 {
2363 if (windowListening)
2364 { return; }
2365 window.addEventListener('pointermove', onPointerMove, true);
2366 window.addEventListener('pointerup', onPointerUp, true);
2367 window.addEventListener('pointercancel', onPointerUp, true);
2368 windowListening = true;
2369 }
2370
2371 function removeWindowPointer ()
2372 {
2373 if (!windowListening)
2374 { return; }
2375 window.removeEventListener('pointermove', onPointerMove, true);
2376 window.removeEventListener('pointerup', onPointerUp, true);
2377 window.removeEventListener('pointercancel', onPointerUp, true);
2378 windowListening = false;
2379 }
1763 2380
1764 2381 function bindPointer (canvas)
1765 2382 {
1766 2383 unbindPointer();
1767 2384 boundCanvas = canvas;
1768 2385 canvas.addEventListener('pointerdown', onPointerDown);
1769 canvas.addEventListener('pointermove', onPointerMove);
1770 canvas.addEventListener('pointerup', onPointerUp);
1771 canvas.addEventListener('pointercancel', onPointerUp);
1772 canvas.addEventListener('lostpointercapture', onPointerUp);
1773 2386 canvas.style.touchAction = 'none';
1774 2387 canvas.style.cursor = 'pointer';
1775 2388 }
1776 2389
1777 2390 function unbindPointer ()
1778 2391 {
1779 if (!boundCanvas)
1780 { return; }
1781 boundCanvas.removeEventListener('pointerdown', onPointerDown);
1782 boundCanvas.removeEventListener('pointermove', onPointerMove);
1783 boundCanvas.removeEventListener('pointerup', onPointerUp);
1784 boundCanvas.removeEventListener('pointercancel', onPointerUp);
1785 boundCanvas.removeEventListener('lostpointercapture', onPointerUp);
2392 removeWindowPointer();
2393 if (boundCanvas)
2394 { boundCanvas.removeEventListener('pointerdown', onPointerDown); }
1786 2395 boundCanvas = null;
1787 2396 app.pointerId = null;
1788 2397 }
@@ -1813,9 +2422,10 @@ function onPointerDown (e)
1813 2422 try
1814 2423 { boundCanvas.setPointerCapture(e.pointerId); }
1815 2424 catch (err) { /* ignore */ }
2425 addWindowPointer();
1816 2426 var pos = fieldFromEvent(e);
1817 if (pos)
1818 { app.core.beginDrag(pos.col, pos.y); }
2427 if (pos && app.core.beginDrag(pos.col, pos.y) && app.core.drag)
2428 { startPressTween(app.core.drag.blockId); }
1819 2429 }
1820 2430
1821 2431 function onPointerMove (e)
@@ -1839,6 +2449,14 @@ function onPointerUp (e)
1839 2449 if (e)
1840 2450 { e.preventDefault(); }
1841 2451 app.pointerId = null;
2452 removeWindowPointer();
2453 if (boundCanvas)
2454 {
2455 try
2456 { boundCanvas.releasePointerCapture(e && e.pointerId); }
2457 catch (err) { /* ignore */ }
2458 }
2459 startReleaseTween();
1842 2460 if (app.core)
1843 2461 { app.core.endDrag(); }
1844 2462 }
@@ -121,7 +121,14 @@ function createPlanet (opts)
121 riseTime: riseTime,
121 riseTime: riseTime,
122 colors: colors,
122 colors: colors,
123 baseJumpHeight: FIELD_HEIGHT / jumpsToClear,
123 baseJumpHeight: FIELD_HEIGHT / jumpsToClear,
124 fallSpeed: FIELD_HEIGHT / fallTime
124 fallSpeed: FIELD_HEIGHT / fallTime,
125 // Time to ease from vy=0 at the apex to terminal fallSpeed.
126 // Shorter when air resistance is low (small fallTime).
127 apexEaseTime: 0.15 * fallTime,
128 fallAccel: (FIELD_HEIGHT / fallTime) / (0.15 * fallTime),
129 // Visual landing bounce: faster at low air resistance. Stage-3 params.
130 bounceDuration: 0.12 * fallTime,
131 bounceSquash: 0.16
125 };
132 };
126 return planet;
133 return planet;
127}
134}
@@ -232,6 +239,127 @@ else if (typeof globalThis !== 'undefined')
232 * /workspace/meteors/src/planet.js
239 * /workspace/meteors/src/planet.js
233 */
240 */
234
241
242/*
243 * Start File:
244 * /workspace/meteors/src/easing.js
245 */
246'use strict';
247
248/**
249 * Easing curves matching Qt QEasingCurve defaults (the same values Tim's
250 * KWin Click Tween effect uses). Formulas and default parameters come from
251 * Qt 6's QEasingCurve and https://easings.net/.
252 *
253 * Source of the click/release defaults:
254 * /workspace/click-tween/settings.h (clickTime, releaseTime, easing names)
255 * /workspace/click-tween/clicktween.cpp (press scale 0.8, release scale 1.0)
256 * /workspace/click-tween/README.md
257 */
258
259/** Qt QEasingCurve default overshoot for InBack / OutBack / InOutBack. */
260var BACK_OVERSHOOT = 1.70158;
261
262/** Qt QEasingCurve default period and amplitude for Elastic curves. */
263var ELASTIC_PERIOD = 0.3;
264var ELASTIC_AMPLITUDE = 1.0;
265
266function clamp01 (t)
267{
268 if (t <= 0)
269 { return 0; }
270 if (t >= 1)
271 { return 1; }
272 return t;
273}
274
275/** easeOutBack: overshoots the end value, then settles. Qt / easings.net. */
276function easeOutBack (t)
277{
278 t = clamp01(t);
279 var c1 = BACK_OVERSHOOT;
280 var c3 = c1 + 1;
281 var u = t - 1;
282 return 1 + c3 * u * u * u + c1 * u * u;
283}
284
285/**
286 * easeOutElastic: decaying sine overshoot past the end value.
287 * Qt default amplitude 1, period 0.3 (equivalent to easings.net).
288 */
289function easeOutElastic (t)
290{
291 t = clamp01(t);
292 if (t === 0 || t === 1)
293 { return t; }
294 var p = ELASTIC_PERIOD;
295 var s = p / 4;
296 return Math.pow(2, -10 * t) * Math.sin((t - s) * (2 * Math.PI) / p) + 1;
297}
298
299function tween (from, to, t, ease)
300{
301 return from + (to - from) * ease(clamp01(t));
302}
303
304/**
305 * DEFAULT settings of Tim's KWin Click Tween
306 * (git.timfalken.com/timfa/click-tween).
307 *
308 * Press: shrink to 80% in 150 ms with easeOutBack, stay at 80% while held.
309 * Release: grow back to 100% in 720 ms with easeOutElastic.
310 * Mid-animation release starts from the current scale, like QVariantAnimation.
311 */
312var CLICK_TWEEN = {
313 pressScale: 0.8,
314 releaseScale: 1.0,
315 pressDuration: 0.150,
316 releaseDuration: 0.720,
317 pressEase: easeOutBack,
318 releaseEase: easeOutElastic,
319 backOvershoot: BACK_OVERSHOOT,
320 elasticPeriod: ELASTIC_PERIOD,
321 elasticAmplitude: ELASTIC_AMPLITUDE,
322 source: 'click-tween settings.h + clicktween.cpp (Qt QEasingCurve defaults)'
323};
324
325/**
326 * Visual landing bounce, u in 0..1. Subtle squash with a slight stretch
327 * on the other axis and a tiny upward rebound (in tiles, visual only).
328 */
329function bouncePose (u, squash)
330{
331 if (u <= 0 || u >= 1)
332 { return { sx: 1, sy: 1, dy: 0 }; }
333 var wave = Math.sin(Math.PI * u);
334 return {
335 sx: 1 + squash * 0.6 * wave,
336 sy: 1 - squash * wave,
337 dy: 0.07 * wave * (1 - u)
338 };
339}
340
341var Easing = {
342 BACK_OVERSHOOT: BACK_OVERSHOOT,
343 ELASTIC_PERIOD: ELASTIC_PERIOD,
344 ELASTIC_AMPLITUDE: ELASTIC_AMPLITUDE,
345 easeOutBack: easeOutBack,
346 easeOutElastic: easeOutElastic,
347 tween: tween,
348 CLICK_TWEEN: CLICK_TWEEN,
349 clamp01: clamp01,
350 bouncePose: bouncePose
351};
352
353if (typeof module !== 'undefined' && module.exports)
354{ module.exports = Easing; }
355else if (typeof globalThis !== 'undefined')
356{ globalThis.Easing = Easing; }
357
358/*
359 * End File:
360 * /workspace/meteors/src/easing.js
361 */
362
235/*
363/*
236 * Start File:
364 * Start File:
237 * /workspace/meteors/src/gameCore.js
365 * /workspace/meteors/src/gameCore.js
@@ -260,6 +388,8 @@ var STATE_MANUAL = 'manual';
260var ALIGN_EPS = 0.15;
388var ALIGN_EPS = 0.15;
261var SUBSTEP = 1 / 120;
389var SUBSTEP = 1 / 120;
262var DRAG_LAUNCH_SLACK = 0.65;
390var DRAG_LAUNCH_SLACK = 0.65;
391// Upward pull (tiles past the press point) that launches an already-topmost block.
392var LAUNCH_PULL = 0.35;
263
393
264function UnionFind ()
394function UnionFind ()
265{
395{
@@ -309,6 +439,7 @@ function GameCore (planet, rng)
309}
439}
310
440
311GameCore.COLOR_GRAY = COLOR_GRAY;
441GameCore.COLOR_GRAY = COLOR_GRAY;
442GameCore.LAUNCH_PULL = LAUNCH_PULL;
312GameCore.STATE_STILL = STATE_STILL;
443GameCore.STATE_STILL = STATE_STILL;
313GameCore.STATE_FALLING = STATE_FALLING;
444GameCore.STATE_FALLING = STATE_FALLING;
314GameCore.STATE_FLYING = STATE_FLYING;
445GameCore.STATE_FLYING = STATE_FLYING;
@@ -336,7 +467,9 @@ GameCore.prototype.createBlock = function (col, y, color, state)
336 pushedClusters: null,
467 pushedClusters: null,
337 manualTarget: 0,
468 manualTarget: 0,
338 manualDecel: 0,
469 manualDecel: 0,
339 manualPhase: null
470 manualPhase: null,
471 bouncing: false,
472 bounceAge: 0
340 };
473 };
341 this.blocks.push(block);
474 this.blocks.push(block);
342 return block;
475 return block;
@@ -474,6 +607,199 @@ GameCore.prototype.lockedColumnCount = function ()
474 return n;
607 return n;
475};
608};
476
609
610GameCore.prototype.startBounce = function (block)
611{
612 if (!block)
613 { return; }
614 block.bouncing = true;
615 block.bounceAge = 0;
616};
617
618GameCore.prototype.advanceBounces = function (dt)
619{
620 var duration = this.planet.bounceDuration;
621 for (var i = 0; i < this.blocks.length; i++)
622 {
623 var block = this.blocks[i];
624 if (!block.bouncing)
625 { continue; }
626 block.bounceAge += dt;
627 if (duration <= 0 || block.bounceAge >= duration)
628 {
629 block.bouncing = false;
630 block.bounceAge = duration;
631 }
632 }
633};
634
635/**
636 * True if `block` rests on the floor or on a solid (still / settling /
637 * locked) block immediately below it in the same column.
638 */
639GameCore.prototype.hasSupport = function (block)
640{
641 if (block.y <= 1e-9)
642 { return true; }
643 for (var i = 0; i < this.blocks.length; i++)
644 {
645 var other = this.blocks[i];
646 if (other === block || other.col !== block.col)
647 { continue; }
648 if (!this.isGrounded(other))
649 { continue; }
650 if (Math.abs((other.y + 1) - block.y) < ALIGN_EPS)
651 { return true; }
652 }
653 return false;
654};
655
656/** Highest flying block in this column whose top is at or below `block.y + 1`. */
657GameCore.prototype.highestFlyingBelow = function (block)
658{
659 var best = null;
660 for (var i = 0; i < this.blocks.length; i++)
661 {
662 var other = this.blocks[i];
663 if (other === block || other.col !== block.col)
664 { continue; }
665 if (other.state !== STATE_FLYING || other.clusterId == null)
666 { continue; }
667 var cluster = this.clusters[other.clusterId];
668 if (!cluster || cluster.phase === 'landed')
669 { continue; }
670 // The falling block is at or above this flyer (or already overlapping).
671 if (block.y + 1e-9 < other.y)
672 { continue; }
673 if (!best || other.y > best.y)
674 { best = other; }
675 }
676 return best;
677};
678
679GameCore.prototype.highestFallingBelow = function (block)
680{
681 var best = null;
682 for (var i = 0; i < this.blocks.length; i++)
683 {
684 var other = this.blocks[i];
685 if (other === block || other.col !== block.col)
686 { continue; }
687 if (other.state !== STATE_FALLING)
688 { continue; }
689 if (other.y > block.y - 1e-9)
690 { continue; }
691 if (!best || other.y > best.y)
692 { best = other; }
693 }
694 return best;
695};
696
697/**
698 * Make an unsupported still block start falling from rest, so it eases
699 * into fallSpeed under normal gravity. Skips the block being dragged.
700 */
701GameCore.prototype.releaseUnsupported = function ()
702{
703 for (var i = 0; i < this.blocks.length; i++)
704 {
705 var block = this.blocks[i];
706 if (block.state !== STATE_STILL)
707 { continue; }
708 if (this.drag && this.drag.blockId === block.id)
709 { continue; }
710 if (this.hasSupport(block))
711 { continue; }
712 block.state = STATE_FALLING;
713 block.vy = 0;
714 block.flame = false;
715 this.leaveCluster(block);
716 }
717};
718
719GameCore.prototype.accelerateFall = function (block, dt)
720{
721 var target = -this.planet.fallSpeed;
722 if (block.vy > target)
723 { block.vy = Math.max(target, block.vy - this.planet.fallAccel * dt); }
724 else
725 { block.vy = target; }
726};
727
728GameCore.prototype.landFallingBlock = function (block)
729{
730 block.vy = 0;
731 block.flame = false;
732 this.startBounce(block);
733 if (block.color === COLOR_GRAY)
734 {
735 block.state = STATE_SETTLING;
736 block.settleTime = 0;
737 }
738 else
739 { block.state = STATE_STILL; }
740};
741
742/**
743 * Sit `block` on top of the flying cluster that `flyer` belongs to, and
744 * carry it along as cargo (no flame). Returns true if attached.
745 */
746GameCore.prototype.attachToFlyingCluster = function (block, flyer)
747{
748 var cluster = this.clusters[flyer.clusterId];
749 if (!cluster || cluster.phase === 'landed')
750 { return false; }
751 var roof = flyer.y + 1;
752 for (var i = 0; i < this.blocks.length; i++)
753 {
754 var other = this.blocks[i];
755 if (other === block || other.col !== block.col)
756 { continue; }
757 if (other.clusterId !== cluster.id)
758 { continue; }
759 if (other.y + 1 > roof)
760 { roof = other.y + 1; }
761 }
762 block.y = roof;
763 block.state = STATE_FLYING;
764 block.clusterId = cluster.id;
765 block.vy = cluster.vy;
766 block.flame = false;
767 block.settleTime = 0;
768 return true;
769};
770
771GameCore.prototype.catchFallingOntoCluster = function (cluster, members)
772{
773 if (!cluster || cluster.phase === 'landed' || cluster.phase === 'hold')
774 { return; }
775 // Snapshot falling blocks; attaching mutates state.
776 var falling = [];
777 for (var i = 0; i < this.blocks.length; i++)
778 {
779 if (this.blocks[i].state === STATE_FALLING)
780 { falling.push(this.blocks[i]); }
781 }
782 for (var i = 0; i < falling.length; i++)
783 {
784 var block = falling[i];
785 var flyer = null;
786 for (var m = 0; m < members.length; m++)
787 {
788 var other = members[m];
789 if (other.col !== block.col)
790 { continue; }
791 // Overlap or rest on this member's top.
792 if (block.y < other.y + 1 + 1e-9 && block.y + 1 > other.y - 1e-9)
793 {
794 if (!flyer || other.y > flyer.y)
795 { flyer = other; }
796 }
797 }
798 if (flyer)
799 { this.attachToFlyingCluster(block, flyer); }
800 }
801};
802
477GameCore.prototype.tick = function (dt)
803GameCore.prototype.tick = function (dt)
478{
804{
479 if (this.state === 'gameover')
805 if (this.state === 'gameover')
@@ -503,7 +829,9 @@ GameCore.prototype.tick = function (dt)
503 left -= step;
829 left -= step;
504 }
830 }
505
831
832 this.releaseUnsupported();
506 this.advanceSettle(dt);
833 this.advanceSettle(dt);
834 this.advanceBounces(dt);
507 if (!this.drag)
835 if (!this.drag)
508 { this.resolveMatches(); }
836 { this.resolveMatches(); }
509 this.checkLocks();
837 this.checkLocks();
@@ -551,24 +879,42 @@ GameCore.prototype.trySpawn = function ()
551 { return null; }
879 { return null; }
552 var col = eligible[Math.floor(this.rng() * eligible.length) % eligible.length];
880 var col = eligible[Math.floor(this.rng() * eligible.length) % eligible.length];
553 var color = this.randomColor();
881 var color = this.randomColor();
554 return this.createBlock(col, this.height, color, STATE_FALLING);
882 var block = this.createBlock(col, this.height, color, STATE_FALLING);
883 block.vy = -this.planet.fallSpeed;
884 return block;
555};
885};
556
886
557GameCore.prototype.integrateFalling = function (dt)
887GameCore.prototype.integrateFalling = function (dt)
558{
888{
559 var speed = this.planet.fallSpeed;
889 var falling = [];
560 for (var i = 0; i < this.blocks.length; i++)
890 for (var i = 0; i < this.blocks.length; i++)
561 {
891 {
562 var block = this.blocks[i];
892 if (this.blocks[i].state === STATE_FALLING)
893 { falling.push(this.blocks[i]); }
894 }
895 // Lowest first, so a stack of falling blocks rests on itself.
896 falling.sort(function (a, b) { return a.y - b.y; });
897 for (var i = 0; i < falling.length; i++)
898 {
899 var block = falling[i];
563 if (block.state !== STATE_FALLING)
900 if (block.state !== STATE_FALLING)
564 { continue; }
901 { continue; }
902 this.accelerateFall(block, dt);
903 var nextY = block.y + block.vy * dt;
904 var flyer = this.highestFlyingBelow(block);
905 if (flyer && nextY <= flyer.y + 1 + 1e-9)
906 {
907 if (this.attachToFlyingCluster(block, flyer))
908 { continue; }
909 }
565 var top = this.stackTop(block.col);
910 var top = this.stackTop(block.col);
566 var nextY = block.y - speed * dt;
911 var below = this.highestFallingBelow(block);
912 if (below && below.y + 1 > top)
913 { top = below.y + 1; }
567 if (nextY <= top)
914 if (nextY <= top)
568 {
915 {
569 block.y = top;
916 block.y = top;
570 block.state = STATE_STILL;
917 this.landFallingBlock(block);
571 block.vy = 0;
572 }
918 }
573 else
919 else
574 { block.y = nextY; }
920 { block.y = nextY; }
@@ -591,7 +937,8 @@ GameCore.prototype.clusterMembers = function (clusterId)
591 * Advance a jump (cluster or manual) by dt. Uses exact kinematics so a
937 * Advance a jump (cluster or manual) by dt. Uses exact kinematics so a
592 * jump of height H peaks at exactly H after riseTime. Returns dy.
938 * jump of height H peaks at exactly H after riseTime. Returns dy.
593 * Mutates body.vy and body.phase ('up' / 'down'). body.decel is the
939 * Mutates body.vy and body.phase ('up' / 'down'). body.decel is the
594 * upward deceleration; falling uses planet.fallSpeed.
940 * upward deceleration. After the apex, vy eases from 0 to -fallSpeed
941 * at planet.fallAccel, then stays at terminal fallSpeed.
595 */
942 */
596GameCore.prototype.advanceJump = function (body, dt)
943GameCore.prototype.advanceJump = function (body, dt)
597{
944{
@@ -624,8 +971,35 @@ GameCore.prototype.advanceJump = function (body, dt)
624 }
971 }
625 if (body.phase === 'down' && left > 0)
972 if (body.phase === 'down' && left > 0)
626 {
973 {
627 body.vy = -this.planet.fallSpeed;
974 var target = -this.planet.fallSpeed;
628 dy += body.vy * left;
975 var accel = this.planet.fallAccel;
976 if (accel < 1e-12)
977 {
978 body.vy = target;
979 dy += body.vy * left;
980 }
981 else if (body.vy > target + 1e-12)
982 {
983 var tReach = (body.vy - target) / accel;
984 if (tReach <= left + 1e-15)
985 {
986 dy += (body.vy + target) * 0.5 * tReach;
987 body.vy = target;
988 left -= tReach;
989 dy += body.vy * left;
990 }
991 else
992 {
993 var vyNew = body.vy - accel * left;
994 dy += (body.vy + vyNew) * 0.5 * left;
995 body.vy = vyNew;
996 }
997 }
998 else
999 {
1000 body.vy = target;
1001 dy += body.vy * left;
1002 }
629 }
1003 }
630 return dy;
1004 return dy;
631};
1005};
@@ -654,14 +1028,18 @@ GameCore.prototype.integrateClusters = function (dt)
654 members[i].vy = cluster.vy;
1028 members[i].vy = cluster.vy;
655 }
1029 }
656
1030
1031 this.catchFallingOntoCluster(cluster, members);
1032
657 if (cluster.phase === 'down')
1033 if (cluster.phase === 'down')
658 { this.tryLandCluster(cluster, members); }
1034 { this.tryLandCluster(cluster, this.clusterMembers(cluster.id)); }
659 }
1035 }
660};
1036};
661
1037
662GameCore.prototype.tryLandCluster = function (cluster, members)
1038GameCore.prototype.tryLandCluster = function (cluster, members)
663{
1039{
664 var self = this;
1040 if (!members.length)
1041 { return; }
1042 var shift = 0;
665 var hit = false;
1043 var hit = false;
666 for (var i = 0; i < members.length; i++)
1044 for (var i = 0; i < members.length; i++)
667 {
1045 {
@@ -671,63 +1049,109 @@ GameCore.prototype.tryLandCluster = function (cluster, members)
671 return other.clusterId === cluster.id;
1049 return other.clusterId === cluster.id;
672 });
1050 });
673 if (block.y <= top + 1e-9)
1051 if (block.y <= top + 1e-9)
674 { hit = true; }
1052 {
1053 hit = true;
1054 var need = top - block.y;
1055 if (need > shift)
1056 { shift = need; }
1057 }
675 }
1058 }
676 if (!hit)
1059 if (!hit)
677 { return; }
1060 { return; }
1061 // Lift the whole rigid body so the deepest contact sits flush.
1062 for (var i = 0; i < members.length; i++)
1063 { members[i].y += shift; }
678 this.landCluster(cluster, members);
1064 this.landCluster(cluster, members);
679};
1065};
680
1066
1067/**
1068 * Land as a rigid group: relative positions are kept, so part of the
1069 * cluster may hang above a gap. Grey members start the 3s settle timer;
1070 * coloured cargo stays put with them until every grey has recolored.
1071 * Members that actually rest on the floor or on another block bounce.
1072 */
681GameCore.prototype.landCluster = function (cluster, members)
1073GameCore.prototype.landCluster = function (cluster, members)
682{
1074{
683 var byCol = Object.create(null);
684 for (var i = 0; i < members.length; i++)
1075 for (var i = 0; i < members.length; i++)
685 {
1076 {
686 var block = members[i];
1077 var block = members[i];
687 if (!byCol[block.col])
1078 block.vy = 0;
688 { byCol[block.col] = []; }
1079 block.flame = false;
689 byCol[block.col].push(block);
1080 block.clusterId = cluster.id;
1081 if (block.color === COLOR_GRAY)
1082 {
1083 block.state = STATE_SETTLING;
1084 block.settleTime = 0;
1085 }
1086 else
1087 {
1088 // Cargo stays in the rigid group (not matchable) until release.
1089 block.state = STATE_SETTLING;
1090 block.settleTime = 0;
1091 }
1092 if (this.hasSupport(block))
1093 { this.startBounce(block); }
690 }
1094 }
691 var cols = Object.keys(byCol);
1095 cluster.phase = 'landed';
692 for (var c = 0; c < cols.length; c++)
1096 cluster.vy = 0;
1097};
1098
1099/**
1100 * After every grey in a landed cluster has recolored, let the group go.
1101 * Unsupported blocks fall individually from rest; supported ones stay.
1102 */
1103GameCore.prototype.releaseLandedCluster = function (cluster)
1104{
1105 var members = this.clusterMembers(cluster.id);
1106 var releasing = Object.create(null);
1107 for (var i = 0; i < members.length; i++)
1108 { releasing[members[i].id] = true; }
1109
1110 for (var i = 0; i < members.length; i++)
693 {
1111 {
694 var col = +cols[c];
1112 var block = members[i];
695 var list = byCol[col];
1113 if (block.color === COLOR_GRAY)
696 list.sort(function (a, b) { return a.y - b.y; });
697 var self = this;
698 var top = this.stackTop(col, function (other)
699 {
1114 {
700 return other.clusterId === cluster.id;
1115 block.color = this.randomColor();
701 });
1116 block.settleTime = 0;
702 for (var i = 0; i < list.length; i++)
1117 }
1118 block.flame = false;
1119 this.leaveCluster(block);
1120 // Support from outside the group (floor or a foreign block). Fellow
1121 // members that will also fall do not count, so a hanging stack
1122 // drops together without the top one staying put.
1123 var supported = this.hasSupportOutside(block, releasing);
1124 if (supported)
703 {
1125 {
704 var block = list[i];
1126 block.state = STATE_STILL;
705 block.y = top;
1127 block.vy = 0;
1128 }
1129 else
1130 {
1131 block.state = STATE_FALLING;
706 block.vy = 0;
1132 block.vy = 0;
707 block.flame = false;
708 top = block.y + 1;
709 if (block.color === COLOR_GRAY)
710 {
711 block.state = STATE_SETTLING;
712 block.settleTime = 0;
713 }
714 else
715 {
716 block.state = STATE_STILL;
717 block.clusterId = null;
718 }
719 }
1133 }
720 }
1134 }
721 cluster.phase = 'landed';
1135 delete this.clusters[cluster.id];
722 cluster.vy = 0;
1136};
723 var remaining = 0;
1137
1138GameCore.prototype.hasSupportOutside = function (block, ignoreIds)
1139{
1140 if (block.y <= 1e-9)
1141 { return true; }
724 for (var i = 0; i < this.blocks.length; i++)
1142 for (var i = 0; i < this.blocks.length; i++)
725 {
1143 {
726 if (this.blocks[i].clusterId === cluster.id)
1144 var other = this.blocks[i];
727 { remaining++; }
1145 if (other === block || other.col !== block.col)
1146 { continue; }
1147 if (ignoreIds && ignoreIds[other.id])
1148 { continue; }
1149 if (!this.isGrounded(other))
1150 { continue; }
1151 if (Math.abs((other.y + 1) - block.y) < ALIGN_EPS)
1152 { return true; }
728 }
1153 }
729 if (remaining === 0)
1154 return false;
730 { delete this.clusters[cluster.id]; }
731};
1155};
732
1156
733GameCore.prototype.integrateManual = function (dt)
1157GameCore.prototype.integrateManual = function (dt)
@@ -764,8 +1188,11 @@ GameCore.prototype.integrateManual = function (dt)
764
1188
765 if (block.manualPhase === 'down')
1189 if (block.manualPhase === 'down')
766 {
1190 {
1191 var proxy = { phase: 'down', vy: block.vy, decel: 0 };
1192 var dy = this.advanceJump(proxy, dt);
1193 block.vy = proxy.vy;
1194 var nextY = block.y + dy;
767 var top = this.stackTop(block.col);
1195 var top = this.stackTop(block.col);
768 var nextY = block.y - this.planet.fallSpeed * dt;
769 if (nextY <= top)
1196 if (nextY <= top)
770 {
1197 {
771 block.y = top;
1198 block.y = top;
@@ -773,11 +1200,11 @@ GameCore.prototype.integrateManual = function (dt)
773 block.vy = 0;
1200 block.vy = 0;
774 block.manualPhase = null;
1201 block.manualPhase = null;
775 block.flame = false;
1202 block.flame = false;
1203 this.startBounce(block);
776 }
1204 }
777 else
1205 else
778 {
1206 {
779 block.y = Math.min(nextY, this.height - 1);
1207 block.y = Math.min(nextY, this.height - 1);
780 block.vy = -this.planet.fallSpeed;
781 }
1208 }
782 }
1209 }
783 }
1210 }
@@ -936,16 +1363,65 @@ GameCore.prototype.advanceSettle = function (dt)
936 var block = this.blocks[i];
1363 var block = this.blocks[i];
937 if (block.state !== STATE_SETTLING)
1364 if (block.state !== STATE_SETTLING)
938 { continue; }
1365 { continue; }
939 block.settleTime += dt;
1366 var inLanded = block.clusterId != null
940 if (block.settleTime >= this.settleTime)
1367 && this.clusters[block.clusterId]
1368 && this.clusters[block.clusterId].phase === 'landed';
1369 if (block.color === COLOR_GRAY)
941 {
1370 {
942 block.color = this.randomColor();
1371 block.settleTime += dt;
943 block.state = STATE_STILL;
1372 if (block.settleTime >= this.settleTime)
944 block.settleTime = 0;
1373 {
945 block.flame = false;
1374 block.color = this.randomColor();
1375 block.settleTime = 0;
1376 block.flame = false;
1377 if (inLanded)
1378 {
1379 // Stay in the rigid group; releaseLandedCluster runs below.
1380 block.state = STATE_SETTLING;
1381 }
1382 else
1383 {
1384 this.leaveCluster(block);
1385 if (this.hasSupport(block))
1386 {
1387 block.state = STATE_STILL;
1388 block.vy = 0;
1389 }
1390 else
1391 {
1392 block.state = STATE_FALLING;
1393 block.vy = 0;
1394 }
1395 }
1396 }
1397 }
1398 else if (!inLanded)
1399 {
1400 // Coloured settling that is not in a landed cluster (shouldn't
1401 // normally happen): just become still or fall.
946 this.leaveCluster(block);
1402 this.leaveCluster(block);
1403 block.state = this.hasSupport(block) ? STATE_STILL : STATE_FALLING;
1404 if (block.state === STATE_FALLING)
1405 { block.vy = 0; }
947 }
1406 }
948 }
1407 }
1408
1409 var ids = Object.keys(this.clusters);
1410 for (var n = 0; n < ids.length; n++)
1411 {
1412 var cluster = this.clusters[ids[n]];
1413 if (!cluster || cluster.phase !== 'landed')
1414 { continue; }
1415 var members = this.clusterMembers(cluster.id);
1416 var greySettling = false;
1417 for (var i = 0; i < members.length; i++)
1418 {
1419 if (members[i].color === COLOR_GRAY && members[i].state === STATE_SETTLING)
1420 { greySettling = true; }
1421 }
1422 if (!greySettling)
1423 { this.releaseLandedCluster(cluster); }
1424 }
949};
1425};
950
1426
951GameCore.prototype.findMatchLines = function ()
1427GameCore.prototype.findMatchLines = function ()
@@ -1258,7 +1734,15 @@ GameCore.prototype.beginDrag = function (col, y)
1258 var block = this.blockAt(col, row);
1734 var block = this.blockAt(col, row);
1259 if (!block || block.state !== STATE_STILL || block.color < 0)
1735 if (!block || block.state !== STATE_STILL || block.color < 0)
1260 { return false; }
1736 { return false; }
1261 this.drag = { blockId: block.id, pointerY: y, launchIntent: false };
1737 var top = this.columnStackTopRow(col);
1738 var startedAsTop = Math.abs(block.y - top) < ALIGN_EPS;
1739 this.drag = {
1740 blockId: block.id,
1741 pointerY: y,
1742 startY: y,
1743 launchIntent: false,
1744 startedAsTop: startedAsTop
1745 };
1262 return true;
1746 return true;
1263};
1747};
1264
1748
@@ -1280,9 +1764,19 @@ GameCore.prototype.moveDrag = function (y)
1280 this.drag.pointerY = y;
1764 this.drag.pointerY = y;
1281 this.swapToward(block, y);
1765 this.swapToward(block, y);
1282 var top = this.columnStackTopRow(block.col);
1766 var top = this.columnStackTopRow(block.col);
1283 // The top block occupies [top, top+1). Launch only when the pointer
1767 var isTop = Math.abs(block.y - top) < ALIGN_EPS;
1284 // is pulled into the empty space above the stack.
1768 if (this.drag.startedAsTop)
1285 this.drag.launchIntent = (Math.abs(block.y - top) < ALIGN_EPS && y > top + 1 + 0.25);
1769 {
1770 // Already the topmost block: pulling upward past its own position
1771 // (LAUNCH_PULL tiles above the press point) starts a manual jump.
1772 this.drag.launchIntent = isTop && (y > this.drag.startY + LAUNCH_PULL);
1773 }
1774 else
1775 {
1776 // Started mid-stack: swap first, and only launch once the pointer
1777 // is pulled into the empty space above the (new) top.
1778 this.drag.launchIntent = isTop && (y > top + 1 + 0.25);
1779 }
1286};
1780};
1287
1781
1288GameCore.prototype.endDrag = function ()
1782GameCore.prototype.endDrag = function ()
@@ -1493,7 +1987,8 @@ var app = {
1493 flames: Object.create(null),
1987 flames: Object.create(null),
1494 cells: [],
1988 cells: [],
1495 pointerId: null,
1989 pointerId: null,
1496 gameOverShown: false
1990 gameOverShown: false,
1991 selectTween: null
1497};
1992};
1498
1993
1499window.onload = function ()
1994window.onload = function ()
@@ -1539,6 +2034,7 @@ function startPlay ()
1539 app.flames = Object.create(null);
2034 app.flames = Object.create(null);
1540 app.cells = [];
2035 app.cells = [];
1541 app.pointerId = null;
2036 app.pointerId = null;
2037 app.selectTween = null;
1542
2038
1543 layout();
2039 layout();
1544 app.scene = new Scene(app.fieldX, app.fieldY, app.fieldW, app.fieldH);
2040 app.scene = new Scene(app.fieldX, app.fieldY, app.fieldW, app.fieldH);
@@ -1566,6 +2062,7 @@ function returnToMenu ()
1566 app.sprites = Object.create(null);
2062 app.sprites = Object.create(null);
1567 app.flames = Object.create(null);
2063 app.flames = Object.create(null);
1568 app.cells = [];
2064 app.cells = [];
2065 app.selectTween = null;
1569
2066
1570 hideEl('hud');
2067 hideEl('hud');
1571 hideEl('game-over');
2068 hideEl('game-over');
@@ -1664,6 +2161,7 @@ function syncSprites ()
1664 }
2161 }
1665 obj.renderer.sprite = spriteFor(block);
2162 obj.renderer.sprite = spriteFor(block);
1666 placeTile(obj, block.col, block.y);
2163 placeTile(obj, block.col, block.y);
2164 applyBlockVisual(obj, block);
1667 obj.renderer.visible = true;
2165 obj.renderer.visible = true;
1668 obj.renderer.alpha = 1;
2166 obj.renderer.alpha = 1;
1669
2167
@@ -1703,6 +2201,96 @@ function syncSprites ()
1703 }
2201 }
1704}
2202}
1705
2203
2204function applyBlockVisual (obj, block)
2205{
2206 var t = app.tile;
2207 var sx = 1;
2208 var sy = 1;
2209 var dy = 0;
2210 if (block.bouncing && app.planet && app.planet.bounceDuration > 0
2211 && typeof Easing !== 'undefined' && Easing.bouncePose)
2212 {
2213 var u = block.bounceAge / app.planet.bounceDuration;
2214 var pose = Easing.bouncePose(u, app.planet.bounceSquash);
2215 sx = pose.sx;
2216 sy = pose.sy;
2217 dy = pose.dy;
2218 }
2219 var sel = 1;
2220 var tw = app.selectTween;
2221 if (tw && tw.blockId === block.id && tw.phase !== 'idle')
2222 { sel = tw.scale; }
2223 obj.transform.size = { x: t * sx * sel, y: t * sy * sel };
2224 if (dy)
2225 { obj.transform.position.y -= dy * t; }
2226}
2227
2228function clickTween ()
2229{
2230 return (typeof Easing !== 'undefined' && Easing.CLICK_TWEEN) ? Easing.CLICK_TWEEN : null;
2231}
2232
2233function startPressTween (blockId)
2234{
2235 var c = clickTween();
2236 if (!c)
2237 { return; }
2238 var from = (app.selectTween && app.selectTween.phase !== 'idle') ? app.selectTween.scale : 1;
2239 app.selectTween = {
2240 blockId: blockId,
2241 from: from,
2242 to: c.pressScale,
2243 t: 0,
2244 duration: c.pressDuration,
2245 ease: c.pressEase,
2246 scale: from,
2247 phase: 'press'
2248 };
2249}
2250
2251function startReleaseTween ()
2252{
2253 var c = clickTween();
2254 var tw = app.selectTween;
2255 if (!c || !tw || tw.phase === 'idle')
2256 { return; }
2257 app.selectTween = {
2258 blockId: tw.blockId,
2259 from: tw.scale,
2260 to: c.releaseScale,
2261 t: 0,
2262 duration: c.releaseDuration,
2263 ease: c.releaseEase,
2264 scale: tw.scale,
2265 phase: 'release'
2266 };
2267}
2268
2269function updateSelectTween (dt)
2270{
2271 var tw = app.selectTween;
2272 if (!tw || tw.phase === 'idle' || tw.phase === 'hold')
2273 { return; }
2274 tw.t += dt;
2275 var u = tw.duration > 0 ? tw.t / tw.duration : 1;
2276 if (u >= 1)
2277 {
2278 tw.scale = tw.to;
2279 tw.t = tw.duration;
2280 if (tw.phase === 'press')
2281 { tw.phase = 'hold'; }
2282 else
2283 {
2284 tw.phase = 'idle';
2285 tw.scale = 1;
2286 tw.blockId = null;
2287 }
2288 return;
2289 }
2290 var ease = tw.ease || (typeof Easing !== 'undefined' && Easing.easeOutBack);
2291 tw.scale = ease ? Easing.tween(tw.from, tw.to, u, ease) : tw.from + (tw.to - tw.from) * u;
2292}
2293
1706function refreshHud ()
2294function refreshHud ()
1707{
2295{
1708 if (!app.core)
2296 if (!app.core)
@@ -1743,6 +2331,7 @@ function tickView (dt)
1743 }
2331 }
1744
2332
1745 app.core.tick(dt);
2333 app.core.tick(dt);
2334 updateSelectTween(dt);
1746 syncSprites();
2335 syncSprites();
1747 refreshHud();
2336 refreshHud();
1748
2337
@@ -1758,31 +2347,51 @@ function tickView (dt)
1758}
2347}
1759
2348
1760/* ---------- pointer input (mouse + touch) --------------------------- */
2349/* ---------- pointer input (mouse + touch) --------------------------- */
2350/*
2351 * Both mouse and touch use Pointer Events. After pointerdown we listen
2352 * on window, so a drag that leaves the canvas (needed to launch a
2353 * block at the top of a full column) still reaches moveDrag. We do
2354 * not treat lostpointercapture as the end of a drag: on some touch
2355 * browsers that fires mid-gesture and would cancel a launch.
2356 */
1761
2357
1762var boundCanvas = null;
2358var boundCanvas = null;
2359var windowListening = false;
2360
2361function addWindowPointer ()
2362{
2363 if (windowListening)
2364 { return; }
2365 window.addEventListener('pointermove', onPointerMove, true);
2366 window.addEventListener('pointerup', onPointerUp, true);
2367 window.addEventListener('pointercancel', onPointerUp, true);
2368 windowListening = true;
2369}
2370
2371function removeWindowPointer ()
2372{
2373 if (!windowListening)
2374 { return; }
2375 window.removeEventListener('pointermove', onPointerMove, true);
2376 window.removeEventListener('pointerup', onPointerUp, true);
2377 window.removeEventListener('pointercancel', onPointerUp, true);
2378 windowListening = false;
2379}
1763
2380
1764function bindPointer (canvas)
2381function bindPointer (canvas)
1765{
2382{
1766 unbindPointer();
2383 unbindPointer();
1767 boundCanvas = canvas;
2384 boundCanvas = canvas;
1768 canvas.addEventListener('pointerdown', onPointerDown);
2385 canvas.addEventListener('pointerdown', onPointerDown);
1769 canvas.addEventListener('pointermove', onPointerMove);
1770 canvas.addEventListener('pointerup', onPointerUp);
1771 canvas.addEventListener('pointercancel', onPointerUp);
1772 canvas.addEventListener('lostpointercapture', onPointerUp);
1773 canvas.style.touchAction = 'none';
2386 canvas.style.touchAction = 'none';
1774 canvas.style.cursor = 'pointer';
2387 canvas.style.cursor = 'pointer';
1775}
2388}
1776
2389
1777function unbindPointer ()
2390function unbindPointer ()
1778{
2391{
1779 if (!boundCanvas)
2392 removeWindowPointer();
1780 { return; }
2393 if (boundCanvas)
1781 boundCanvas.removeEventListener('pointerdown', onPointerDown);
2394 { boundCanvas.removeEventListener('pointerdown', onPointerDown); }
1782 boundCanvas.removeEventListener('pointermove', onPointerMove);
1783 boundCanvas.removeEventListener('pointerup', onPointerUp);
1784 boundCanvas.removeEventListener('pointercancel', onPointerUp);
1785 boundCanvas.removeEventListener('lostpointercapture', onPointerUp);
1786 boundCanvas = null;
2395 boundCanvas = null;
1787 app.pointerId = null;
2396 app.pointerId = null;
1788}
2397}
@@ -1813,9 +2422,10 @@ function onPointerDown (e)
1813 try
2422 try
1814 { boundCanvas.setPointerCapture(e.pointerId); }
2423 { boundCanvas.setPointerCapture(e.pointerId); }
1815 catch (err) { /* ignore */ }
2424 catch (err) { /* ignore */ }
2425 addWindowPointer();
1816 var pos = fieldFromEvent(e);
2426 var pos = fieldFromEvent(e);
1817 if (pos)
2427 if (pos && app.core.beginDrag(pos.col, pos.y) && app.core.drag)
1818 { app.core.beginDrag(pos.col, pos.y); }
2428 { startPressTween(app.core.drag.blockId); }
1819}
2429}
1820
2430
1821function onPointerMove (e)
2431function onPointerMove (e)
@@ -1839,6 +2449,14 @@ function onPointerUp (e)
1839 if (e)
2449 if (e)
1840 { e.preventDefault(); }
2450 { e.preventDefault(); }
1841 app.pointerId = null;
2451 app.pointerId = null;
2452 removeWindowPointer();
2453 if (boundCanvas)
2454 {
2455 try
2456 { boundCanvas.releasePointerCapture(e && e.pointerId); }
2457 catch (err) { /* ignore */ }
2458 }
2459 startReleaseTween();
1842 if (app.core)
2460 if (app.core)
1843 { app.core.endDrag(); }
2461 { app.core.endDrag(); }
1844}
2462}
docs/ASSUMPTIONS.md added +124 −0
@@ -0,0 +1,124 @@
1 # Aannames — Meteors
2
3 Waar de specificatie ruimte liet, staat hier hoe we het hebben ingevuld.
4 Als iets onduidelijk was, volgden we de geest van Meteos en (voor de
5 selectie-tween) Tim's bestaande KWin-effecten.
6
7 ## Fase 1 — physics-fixes (t1098u, t1100u, t1101u)
8
9 ### 1. Vallende blokken landen op vliegende clusters
10
11 Een gespawnd (vallend) blok ging soms door een vliegende cluster heen,
12 omdat de val alleen keek naar stilliggende/settling/locked blokken.
13
14 Aanname: het vallende blok botst alleen in dezelfde kolom. Het landt op
15 het hoogste vliegende clustermlid onder hem, wordt vracht van die
16 cluster (`state = flying`, zelfde `clusterId` en `vy`, geen vlam) en
17 vliegt mee, inclusief omhoog als de cluster nog stijgt. Nieuwe vracht
18 zit precies 1 tegel boven het hoogste clustermlid in die kolom.
19
20 Omgekeerd, als een stijgende cluster een vallend blok inrijdt, geldt
21 hetzelfde. Een cluster die al geland is (rigid settling) telt als vaste
22 ondergrond: daar landt een vallend blok gewoon op, het wordt geen vracht.
23
24 ### 2. Grijze clusters landen als starre groep
25
26 Voorheen werd elke kolom bij landing platgedrukt op de stapel, waardoor
27 gaten verdwenen.
28
29 Aanname: zodra één lid de vloer of een stil blok raakt, stopt de hele
30 cluster als star lichaam. De relatieve posities blijven; een deel kan
31 dus boven een gat blijven hangen. Gekleurde vracht (meegedragen blokken)
32 blijft tot het einde van de settle-tijd van 3 s bij de groep — ze
33 verkleuren niet opnieuw, maar vallen ook niet eerder. Na de conversie
34 van de grijze blokken naar willekeurige kleuren laat de hele groep los.
35 Blokken mét steun blijven liggen; blokken zónder steun vallen
36 afzonderlijk, vanuit rust, met dezelfde zwaartekracht als een gewone
37 val (eerst versnellen tot `fallSpeed`, zie punt 3). Gestapelde hangende
38 blokken vallen als stapel (ze blijven op elkaar rusten, zonder te
39 overlappen).
40
41 ### 3. Vloeiende snelheidsovergang op de apex
42
43 Voorheen sprong `vy` op de apex in één frame naar `-fallSpeed`.
44
45 Aanname: vanaf de apex (vy = 0) versnelt de cluster (en een handmatige
46 sprong) met constante `fallAccel` totdat `fallSpeed` is bereikt; daarna
47 constante daalsnelheid. `apexEaseTime = 0.15 * fallTime` en
48 `fallAccel = fallSpeed / apexEaseTime`. Lage luchtweerstand (kleine
49 `fallTime`) geeft dus een kortere, snellere overgang. Voor Terra
50 (`fallTime = 3`) is dat 0,45 s. Hetzelfde geldt voor hangende blokken
51 die na conversie uit rust gaan vallen. Blokken die van boven het veld
52 binnenkomen (spawn) starten al op `fallSpeed` — die vallen al een
53 tijdje.
54
55 ### 4. Bounce bij landing (planeetparameter)
56
57 Aanname: de bounce is visueel (squash van de sprite, plus een heel klein
58 optisch terugveren in Y) en verandert de simulatiefysica niet. Elk blok
59 dat op de vloer of op een ander blok landt, krijgt een bounce; hangende
60 leden van een starre groep die niets raken, niet.
61
62 Snelheid hangt af van de luchtweerstand van het veld, via `fallTime`
63 (1 = weinig lucht, 5 = veel lucht):
64
65 - `bounceDuration = 0.12 * fallTime` (Terra: 0,36 s; bij `fallTime = 1`
66 twee keer zo snel als bij `fallTime = 2`, enz.)
67 - `bounceSquash = 0.16` (subtiele verticale squash naar 84%, met lichte
68 horizontale compensatie)
69
70 Beide zijn planeetparameters, klaar voor fase 3.
71
72 ### 5. Handmatige sprong van het bovenste blok (t1100u)
73
74 Het naar boven slepen van een blok dat al het bovenste van zijn kolom
75 is, moest een handmatige sprong starten (tot net onder de bovenrand).
76 De core vroeg eerder dat de aanwijzer in de lege ruimte boven de stapel
77 kwam (`y > top + 1 + 0,25`). Wie het bovenste blok vasthad en het
78 voorbij zijn eigen positie trok, maar niet een hele tegel het gat in,
79 kreeg geen sprong. Op touch kon `lostpointercapture` de sleep ook te
80 vroeg beëindigen.
81
82 Aanname:
83
84 - Begon de sleep al op het bovenste blok, dan is een trek van
85 `LAUNCH_PULL = 0,35` tegel omhoog vanaf het drukpunt genoeg
86 (“voorbij zijn eigen positie”), voor muis én touch (zelfde
87 Pointer-Events-pad).
88 - Begon de sleep lager in de stapel, dan blijft de oude drempel gelden:
89 eerst wisselen, en pas lanceren als de aanwijzer in de lege ruimte
90 boven de (nieuwe) top zit. Zo lanceer je niet per ongeluk een blok
91 dat je alleen naar de bovenste plek wilt schuiven.
92 - De view luistert na `pointerdown` op `window` voor `pointermove` /
93 `pointerup` / `pointercancel`, zodat een sleep boven het canvas
94 (nodig bij een volle kolom) niet verloren gaat. `lostpointercapture`
95 beëindigt de sleep niet meer.
96
97 ### 6. Selectie-tween (t1101u)
98
99 Een vastgehouden (geselecteerd) blok krijgt dezelfde schaal-animatie
100 als de **DEFAULT**-instellingen van Tim's KWin Click Tween-effect.
101
102 Bron (op deze box): `/workspace/click-tween/`, specifiek:
103
104 - `settings.h`: `clickTime = 150` ms, `releaseTime = 720` ms,
105 `clickEasing = easeOutBack`, `releaseEasing = easeOutElastic`
106 - `clicktween.cpp`: pers-doel `0.8`, loslaat-doel `1.0`; een onderbroken
107 animatie start vanaf de huidige schaal (`QVariantAnimation`)
108 - `README.md`: “krimpt naar 80% in 150 ms”, “groeit in 720 ms terug”,
109 “curveparameters zijn Qt-standaardwaarden”
110
111 Qt `QEasingCurve`-standaardwaarden, ook in de README genoemd:
112
113 - Back-overshoot: `1.70158`
114 - Elastic: amplitude `1.0`, periode `0.3`
115
116 Het blok blijft op 80% zolang het geselecteerd is, en veert bij loslaten
117 terug (ook als het ondertussen gelanceerd wordt). Muis en touch gebruiken
118 dezelfde tween.
119
120 ## Fase 2 — multiplayer (volgt)
121
122 Zie latere secties zodra fase 2 landt. De miss-kans van 30% wordt een
123 parameter (`missChance`, standaard 0,30); de planeetformule
124 `Planet.missChance` (60%–5% via Power) is voor fase 3.
@@ -0,0 +1,124 @@
1# Aannames — Meteors
2
3Waar de specificatie ruimte liet, staat hier hoe we het hebben ingevuld.
4Als iets onduidelijk was, volgden we de geest van Meteos en (voor de
5selectie-tween) Tim's bestaande KWin-effecten.
6
7## Fase 1 — physics-fixes (t1098u, t1100u, t1101u)
8
9### 1. Vallende blokken landen op vliegende clusters
10
11Een gespawnd (vallend) blok ging soms door een vliegende cluster heen,
12omdat de val alleen keek naar stilliggende/settling/locked blokken.
13
14Aanname: het vallende blok botst alleen in dezelfde kolom. Het landt op
15het hoogste vliegende clustermlid onder hem, wordt vracht van die
16cluster (`state = flying`, zelfde `clusterId` en `vy`, geen vlam) en
17vliegt mee, inclusief omhoog als de cluster nog stijgt. Nieuwe vracht
18zit precies 1 tegel boven het hoogste clustermlid in die kolom.
19
20Omgekeerd, als een stijgende cluster een vallend blok inrijdt, geldt
21hetzelfde. Een cluster die al geland is (rigid settling) telt als vaste
22ondergrond: daar landt een vallend blok gewoon op, het wordt geen vracht.
23
24### 2. Grijze clusters landen als starre groep
25
26Voorheen werd elke kolom bij landing platgedrukt op de stapel, waardoor
27gaten verdwenen.
28
29Aanname: zodra één lid de vloer of een stil blok raakt, stopt de hele
30cluster als star lichaam. De relatieve posities blijven; een deel kan
31dus boven een gat blijven hangen. Gekleurde vracht (meegedragen blokken)
32blijft tot het einde van de settle-tijd van 3 s bij de groep — ze
33verkleuren niet opnieuw, maar vallen ook niet eerder. Na de conversie
34van de grijze blokken naar willekeurige kleuren laat de hele groep los.
35Blokken mét steun blijven liggen; blokken zónder steun vallen
36afzonderlijk, vanuit rust, met dezelfde zwaartekracht als een gewone
37val (eerst versnellen tot `fallSpeed`, zie punt 3). Gestapelde hangende
38blokken vallen als stapel (ze blijven op elkaar rusten, zonder te
39overlappen).
40
41### 3. Vloeiende snelheidsovergang op de apex
42
43Voorheen sprong `vy` op de apex in één frame naar `-fallSpeed`.
44
45Aanname: vanaf de apex (vy = 0) versnelt de cluster (en een handmatige
46sprong) met constante `fallAccel` totdat `fallSpeed` is bereikt; daarna
47constante daalsnelheid. `apexEaseTime = 0.15 * fallTime` en
48`fallAccel = fallSpeed / apexEaseTime`. Lage luchtweerstand (kleine
49`fallTime`) geeft dus een kortere, snellere overgang. Voor Terra
50(`fallTime = 3`) is dat 0,45 s. Hetzelfde geldt voor hangende blokken
51die na conversie uit rust gaan vallen. Blokken die van boven het veld
52binnenkomen (spawn) starten al op `fallSpeed` — die vallen al een
53tijdje.
54
55### 4. Bounce bij landing (planeetparameter)
56
57Aanname: de bounce is visueel (squash van de sprite, plus een heel klein
58optisch terugveren in Y) en verandert de simulatiefysica niet. Elk blok
59dat op de vloer of op een ander blok landt, krijgt een bounce; hangende
60leden van een starre groep die niets raken, niet.
61
62Snelheid hangt af van de luchtweerstand van het veld, via `fallTime`
63(1 = weinig lucht, 5 = veel lucht):
64
65- `bounceDuration = 0.12 * fallTime` (Terra: 0,36 s; bij `fallTime = 1`
66 twee keer zo snel als bij `fallTime = 2`, enz.)
67- `bounceSquash = 0.16` (subtiele verticale squash naar 84%, met lichte
68 horizontale compensatie)
69
70Beide zijn planeetparameters, klaar voor fase 3.
71
72### 5. Handmatige sprong van het bovenste blok (t1100u)
73
74Het naar boven slepen van een blok dat al het bovenste van zijn kolom
75is, moest een handmatige sprong starten (tot net onder de bovenrand).
76De core vroeg eerder dat de aanwijzer in de lege ruimte boven de stapel
77kwam (`y > top + 1 + 0,25`). Wie het bovenste blok vasthad en het
78voorbij zijn eigen positie trok, maar niet een hele tegel het gat in,
79kreeg geen sprong. Op touch kon `lostpointercapture` de sleep ook te
80vroeg beëindigen.
81
82Aanname:
83
84- Begon de sleep al op het bovenste blok, dan is een trek van
85 `LAUNCH_PULL = 0,35` tegel omhoog vanaf het drukpunt genoeg
86 (“voorbij zijn eigen positie”), voor muis én touch (zelfde
87 Pointer-Events-pad).
88- Begon de sleep lager in de stapel, dan blijft de oude drempel gelden:
89 eerst wisselen, en pas lanceren als de aanwijzer in de lege ruimte
90 boven de (nieuwe) top zit. Zo lanceer je niet per ongeluk een blok
91 dat je alleen naar de bovenste plek wilt schuiven.
92- De view luistert na `pointerdown` op `window` voor `pointermove` /
93 `pointerup` / `pointercancel`, zodat een sleep boven het canvas
94 (nodig bij een volle kolom) niet verloren gaat. `lostpointercapture`
95 beëindigt de sleep niet meer.
96
97### 6. Selectie-tween (t1101u)
98
99Een vastgehouden (geselecteerd) blok krijgt dezelfde schaal-animatie
100als de **DEFAULT**-instellingen van Tim's KWin Click Tween-effect.
101
102Bron (op deze box): `/workspace/click-tween/`, specifiek:
103
104- `settings.h`: `clickTime = 150` ms, `releaseTime = 720` ms,
105 `clickEasing = easeOutBack`, `releaseEasing = easeOutElastic`
106- `clicktween.cpp`: pers-doel `0.8`, loslaat-doel `1.0`; een onderbroken
107 animatie start vanaf de huidige schaal (`QVariantAnimation`)
108- `README.md`: “krimpt naar 80% in 150 ms”, “groeit in 720 ms terug”,
109 “curveparameters zijn Qt-standaardwaarden”
110
111Qt `QEasingCurve`-standaardwaarden, ook in de README genoemd:
112
113- Back-overshoot: `1.70158`
114- Elastic: amplitude `1.0`, periode `0.3`
115
116Het blok blijft op 80% zolang het geselecteerd is, en veert bij loslaten
117terug (ook als het ondertussen gelanceerd wordt). Muis en touch gebruiken
118dezelfde tween.
119
120## Fase 2 — multiplayer (volgt)
121
122Zie latere secties zodra fase 2 landt. De miss-kans van 30% wordt een
123parameter (`missChance`, standaard 0,30); de planeetformule
124`Planet.missChance` (60%–5% via Power) is voor fase 3.
src/build.sh +1 −0
@@ -13,6 +13,7 @@ rm -f "$BUILD_FILE"
13 13 FILES=(
14 14 "$SRC_DIR/rng.js"
15 15 "$SRC_DIR/planet.js"
16 "$SRC_DIR/easing.js"
16 17 "$SRC_DIR/gameCore.js"
17 18 "$SRC_DIR/main.js"
18 19 )
@@ -13,6 +13,7 @@ rm -f "$BUILD_FILE"
13FILES=(
13FILES=(
14 "$SRC_DIR/rng.js"
14 "$SRC_DIR/rng.js"
15 "$SRC_DIR/planet.js"
15 "$SRC_DIR/planet.js"
16 "$SRC_DIR/easing.js"
16 "$SRC_DIR/gameCore.js"
17 "$SRC_DIR/gameCore.js"
17 "$SRC_DIR/main.js"
18 "$SRC_DIR/main.js"
18)
19)
src/easing.js added +111 −0
@@ -0,0 +1,111 @@
1 'use strict';
2
3 /**
4 * Easing curves matching Qt QEasingCurve defaults (the same values Tim's
5 * KWin Click Tween effect uses). Formulas and default parameters come from
6 * Qt 6's QEasingCurve and https://easings.net/.
7 *
8 * Source of the click/release defaults:
9 * /workspace/click-tween/settings.h (clickTime, releaseTime, easing names)
10 * /workspace/click-tween/clicktween.cpp (press scale 0.8, release scale 1.0)
11 * /workspace/click-tween/README.md
12 */
13
14 /** Qt QEasingCurve default overshoot for InBack / OutBack / InOutBack. */
15 var BACK_OVERSHOOT = 1.70158;
16
17 /** Qt QEasingCurve default period and amplitude for Elastic curves. */
18 var ELASTIC_PERIOD = 0.3;
19 var ELASTIC_AMPLITUDE = 1.0;
20
21 function clamp01 (t)
22 {
23 if (t <= 0)
24 { return 0; }
25 if (t >= 1)
26 { return 1; }
27 return t;
28 }
29
30 /** easeOutBack: overshoots the end value, then settles. Qt / easings.net. */
31 function easeOutBack (t)
32 {
33 t = clamp01(t);
34 var c1 = BACK_OVERSHOOT;
35 var c3 = c1 + 1;
36 var u = t - 1;
37 return 1 + c3 * u * u * u + c1 * u * u;
38 }
39
40 /**
41 * easeOutElastic: decaying sine overshoot past the end value.
42 * Qt default amplitude 1, period 0.3 (equivalent to easings.net).
43 */
44 function easeOutElastic (t)
45 {
46 t = clamp01(t);
47 if (t === 0 || t === 1)
48 { return t; }
49 var p = ELASTIC_PERIOD;
50 var s = p / 4;
51 return Math.pow(2, -10 * t) * Math.sin((t - s) * (2 * Math.PI) / p) + 1;
52 }
53
54 function tween (from, to, t, ease)
55 {
56 return from + (to - from) * ease(clamp01(t));
57 }
58
59 /**
60 * DEFAULT settings of Tim's KWin Click Tween
61 * (git.timfalken.com/timfa/click-tween).
62 *
63 * Press: shrink to 80% in 150 ms with easeOutBack, stay at 80% while held.
64 * Release: grow back to 100% in 720 ms with easeOutElastic.
65 * Mid-animation release starts from the current scale, like QVariantAnimation.
66 */
67 var CLICK_TWEEN = {
68 pressScale: 0.8,
69 releaseScale: 1.0,
70 pressDuration: 0.150,
71 releaseDuration: 0.720,
72 pressEase: easeOutBack,
73 releaseEase: easeOutElastic,
74 backOvershoot: BACK_OVERSHOOT,
75 elasticPeriod: ELASTIC_PERIOD,
76 elasticAmplitude: ELASTIC_AMPLITUDE,
77 source: 'click-tween settings.h + clicktween.cpp (Qt QEasingCurve defaults)'
78 };
79
80 /**
81 * Visual landing bounce, u in 0..1. Subtle squash with a slight stretch
82 * on the other axis and a tiny upward rebound (in tiles, visual only).
83 */
84 function bouncePose (u, squash)
85 {
86 if (u <= 0 || u >= 1)
87 { return { sx: 1, sy: 1, dy: 0 }; }
88 var wave = Math.sin(Math.PI * u);
89 return {
90 sx: 1 + squash * 0.6 * wave,
91 sy: 1 - squash * wave,
92 dy: 0.07 * wave * (1 - u)
93 };
94 }
95
96 var Easing = {
97 BACK_OVERSHOOT: BACK_OVERSHOOT,
98 ELASTIC_PERIOD: ELASTIC_PERIOD,
99 ELASTIC_AMPLITUDE: ELASTIC_AMPLITUDE,
100 easeOutBack: easeOutBack,
101 easeOutElastic: easeOutElastic,
102 tween: tween,
103 CLICK_TWEEN: CLICK_TWEEN,
104 clamp01: clamp01,
105 bouncePose: bouncePose
106 };
107
108 if (typeof module !== 'undefined' && module.exports)
109 { module.exports = Easing; }
110 else if (typeof globalThis !== 'undefined')
111 { globalThis.Easing = Easing; }
@@ -0,0 +1,111 @@
1'use strict';
2
3/**
4 * Easing curves matching Qt QEasingCurve defaults (the same values Tim's
5 * KWin Click Tween effect uses). Formulas and default parameters come from
6 * Qt 6's QEasingCurve and https://easings.net/.
7 *
8 * Source of the click/release defaults:
9 * /workspace/click-tween/settings.h (clickTime, releaseTime, easing names)
10 * /workspace/click-tween/clicktween.cpp (press scale 0.8, release scale 1.0)
11 * /workspace/click-tween/README.md
12 */
13
14/** Qt QEasingCurve default overshoot for InBack / OutBack / InOutBack. */
15var BACK_OVERSHOOT = 1.70158;
16
17/** Qt QEasingCurve default period and amplitude for Elastic curves. */
18var ELASTIC_PERIOD = 0.3;
19var ELASTIC_AMPLITUDE = 1.0;
20
21function clamp01 (t)
22{
23 if (t <= 0)
24 { return 0; }
25 if (t >= 1)
26 { return 1; }
27 return t;
28}
29
30/** easeOutBack: overshoots the end value, then settles. Qt / easings.net. */
31function easeOutBack (t)
32{
33 t = clamp01(t);
34 var c1 = BACK_OVERSHOOT;
35 var c3 = c1 + 1;
36 var u = t - 1;
37 return 1 + c3 * u * u * u + c1 * u * u;
38}
39
40/**
41 * easeOutElastic: decaying sine overshoot past the end value.
42 * Qt default amplitude 1, period 0.3 (equivalent to easings.net).
43 */
44function easeOutElastic (t)
45{
46 t = clamp01(t);
47 if (t === 0 || t === 1)
48 { return t; }
49 var p = ELASTIC_PERIOD;
50 var s = p / 4;
51 return Math.pow(2, -10 * t) * Math.sin((t - s) * (2 * Math.PI) / p) + 1;
52}
53
54function tween (from, to, t, ease)
55{
56 return from + (to - from) * ease(clamp01(t));
57}
58
59/**
60 * DEFAULT settings of Tim's KWin Click Tween
61 * (git.timfalken.com/timfa/click-tween).
62 *
63 * Press: shrink to 80% in 150 ms with easeOutBack, stay at 80% while held.
64 * Release: grow back to 100% in 720 ms with easeOutElastic.
65 * Mid-animation release starts from the current scale, like QVariantAnimation.
66 */
67var CLICK_TWEEN = {
68 pressScale: 0.8,
69 releaseScale: 1.0,
70 pressDuration: 0.150,
71 releaseDuration: 0.720,
72 pressEase: easeOutBack,
73 releaseEase: easeOutElastic,
74 backOvershoot: BACK_OVERSHOOT,
75 elasticPeriod: ELASTIC_PERIOD,
76 elasticAmplitude: ELASTIC_AMPLITUDE,
77 source: 'click-tween settings.h + clicktween.cpp (Qt QEasingCurve defaults)'
78};
79
80/**
81 * Visual landing bounce, u in 0..1. Subtle squash with a slight stretch
82 * on the other axis and a tiny upward rebound (in tiles, visual only).
83 */
84function bouncePose (u, squash)
85{
86 if (u <= 0 || u >= 1)
87 { return { sx: 1, sy: 1, dy: 0 }; }
88 var wave = Math.sin(Math.PI * u);
89 return {
90 sx: 1 + squash * 0.6 * wave,
91 sy: 1 - squash * wave,
92 dy: 0.07 * wave * (1 - u)
93 };
94}
95
96var Easing = {
97 BACK_OVERSHOOT: BACK_OVERSHOOT,
98 ELASTIC_PERIOD: ELASTIC_PERIOD,
99 ELASTIC_AMPLITUDE: ELASTIC_AMPLITUDE,
100 easeOutBack: easeOutBack,
101 easeOutElastic: easeOutElastic,
102 tween: tween,
103 CLICK_TWEEN: CLICK_TWEEN,
104 clamp01: clamp01,
105 bouncePose: bouncePose
106};
107
108if (typeof module !== 'undefined' && module.exports)
109{ module.exports = Easing; }
110else if (typeof globalThis !== 'undefined')
111{ globalThis.Easing = Easing; }
src/gameCore.js +426 −60
@@ -22,6 +22,8 @@ var STATE_MANUAL = 'manual';
22 22 var ALIGN_EPS = 0.15;
23 23 var SUBSTEP = 1 / 120;
24 24 var DRAG_LAUNCH_SLACK = 0.65;
25 // Upward pull (tiles past the press point) that launches an already-topmost block.
26 var LAUNCH_PULL = 0.35;
25 27
26 28 function UnionFind ()
27 29 {
@@ -71,6 +73,7 @@ function GameCore (planet, rng)
71 73 }
72 74
73 75 GameCore.COLOR_GRAY = COLOR_GRAY;
76 GameCore.LAUNCH_PULL = LAUNCH_PULL;
74 77 GameCore.STATE_STILL = STATE_STILL;
75 78 GameCore.STATE_FALLING = STATE_FALLING;
76 79 GameCore.STATE_FLYING = STATE_FLYING;
@@ -98,7 +101,9 @@ GameCore.prototype.createBlock = function (col, y, color, state)
98 101 pushedClusters: null,
99 102 manualTarget: 0,
100 103 manualDecel: 0,
101 manualPhase: null
104 manualPhase: null,
105 bouncing: false,
106 bounceAge: 0
102 107 };
103 108 this.blocks.push(block);
104 109 return block;
@@ -236,6 +241,199 @@ GameCore.prototype.lockedColumnCount = function ()
236 241 return n;
237 242 };
238 243
244 GameCore.prototype.startBounce = function (block)
245 {
246 if (!block)
247 { return; }
248 block.bouncing = true;
249 block.bounceAge = 0;
250 };
251
252 GameCore.prototype.advanceBounces = function (dt)
253 {
254 var duration = this.planet.bounceDuration;
255 for (var i = 0; i < this.blocks.length; i++)
256 {
257 var block = this.blocks[i];
258 if (!block.bouncing)
259 { continue; }
260 block.bounceAge += dt;
261 if (duration <= 0 || block.bounceAge >= duration)
262 {
263 block.bouncing = false;
264 block.bounceAge = duration;
265 }
266 }
267 };
268
269 /**
270 * True if `block` rests on the floor or on a solid (still / settling /
271 * locked) block immediately below it in the same column.
272 */
273 GameCore.prototype.hasSupport = function (block)
274 {
275 if (block.y <= 1e-9)
276 { return true; }
277 for (var i = 0; i < this.blocks.length; i++)
278 {
279 var other = this.blocks[i];
280 if (other === block || other.col !== block.col)
281 { continue; }
282 if (!this.isGrounded(other))
283 { continue; }
284 if (Math.abs((other.y + 1) - block.y) < ALIGN_EPS)
285 { return true; }
286 }
287 return false;
288 };
289
290 /** Highest flying block in this column whose top is at or below `block.y + 1`. */
291 GameCore.prototype.highestFlyingBelow = function (block)
292 {
293 var best = null;
294 for (var i = 0; i < this.blocks.length; i++)
295 {
296 var other = this.blocks[i];
297 if (other === block || other.col !== block.col)
298 { continue; }
299 if (other.state !== STATE_FLYING || other.clusterId == null)
300 { continue; }
301 var cluster = this.clusters[other.clusterId];
302 if (!cluster || cluster.phase === 'landed')
303 { continue; }
304 // The falling block is at or above this flyer (or already overlapping).
305 if (block.y + 1e-9 < other.y)
306 { continue; }
307 if (!best || other.y > best.y)
308 { best = other; }
309 }
310 return best;
311 };
312
313 GameCore.prototype.highestFallingBelow = function (block)
314 {
315 var best = null;
316 for (var i = 0; i < this.blocks.length; i++)
317 {
318 var other = this.blocks[i];
319 if (other === block || other.col !== block.col)
320 { continue; }
321 if (other.state !== STATE_FALLING)
322 { continue; }
323 if (other.y > block.y - 1e-9)
324 { continue; }
325 if (!best || other.y > best.y)
326 { best = other; }
327 }
328 return best;
329 };
330
331 /**
332 * Make an unsupported still block start falling from rest, so it eases
333 * into fallSpeed under normal gravity. Skips the block being dragged.
334 */
335 GameCore.prototype.releaseUnsupported = function ()
336 {
337 for (var i = 0; i < this.blocks.length; i++)
338 {
339 var block = this.blocks[i];
340 if (block.state !== STATE_STILL)
341 { continue; }
342 if (this.drag && this.drag.blockId === block.id)
343 { continue; }
344 if (this.hasSupport(block))
345 { continue; }
346 block.state = STATE_FALLING;
347 block.vy = 0;
348 block.flame = false;
349 this.leaveCluster(block);
350 }
351 };
352
353 GameCore.prototype.accelerateFall = function (block, dt)
354 {
355 var target = -this.planet.fallSpeed;
356 if (block.vy > target)
357 { block.vy = Math.max(target, block.vy - this.planet.fallAccel * dt); }
358 else
359 { block.vy = target; }
360 };
361
362 GameCore.prototype.landFallingBlock = function (block)
363 {
364 block.vy = 0;
365 block.flame = false;
366 this.startBounce(block);
367 if (block.color === COLOR_GRAY)
368 {
369 block.state = STATE_SETTLING;
370 block.settleTime = 0;
371 }
372 else
373 { block.state = STATE_STILL; }
374 };
375
376 /**
377 * Sit `block` on top of the flying cluster that `flyer` belongs to, and
378 * carry it along as cargo (no flame). Returns true if attached.
379 */
380 GameCore.prototype.attachToFlyingCluster = function (block, flyer)
381 {
382 var cluster = this.clusters[flyer.clusterId];
383 if (!cluster || cluster.phase === 'landed')
384 { return false; }
385 var roof = flyer.y + 1;
386 for (var i = 0; i < this.blocks.length; i++)
387 {
388 var other = this.blocks[i];
389 if (other === block || other.col !== block.col)
390 { continue; }
391 if (other.clusterId !== cluster.id)
392 { continue; }
393 if (other.y + 1 > roof)
394 { roof = other.y + 1; }
395 }
396 block.y = roof;
397 block.state = STATE_FLYING;
398 block.clusterId = cluster.id;
399 block.vy = cluster.vy;
400 block.flame = false;
401 block.settleTime = 0;
402 return true;
403 };
404
405 GameCore.prototype.catchFallingOntoCluster = function (cluster, members)
406 {
407 if (!cluster || cluster.phase === 'landed' || cluster.phase === 'hold')
408 { return; }
409 // Snapshot falling blocks; attaching mutates state.
410 var falling = [];
411 for (var i = 0; i < this.blocks.length; i++)
412 {
413 if (this.blocks[i].state === STATE_FALLING)
414 { falling.push(this.blocks[i]); }
415 }
416 for (var i = 0; i < falling.length; i++)
417 {
418 var block = falling[i];
419 var flyer = null;
420 for (var m = 0; m < members.length; m++)
421 {
422 var other = members[m];
423 if (other.col !== block.col)
424 { continue; }
425 // Overlap or rest on this member's top.
426 if (block.y < other.y + 1 + 1e-9 && block.y + 1 > other.y - 1e-9)
427 {
428 if (!flyer || other.y > flyer.y)
429 { flyer = other; }
430 }
431 }
432 if (flyer)
433 { this.attachToFlyingCluster(block, flyer); }
434 }
435 };
436
239 437 GameCore.prototype.tick = function (dt)
240 438 {
241 439 if (this.state === 'gameover')
@@ -265,7 +463,9 @@ GameCore.prototype.tick = function (dt)
265 463 left -= step;
266 464 }
267 465
466 this.releaseUnsupported();
268 467 this.advanceSettle(dt);
468 this.advanceBounces(dt);
269 469 if (!this.drag)
270 470 { this.resolveMatches(); }
271 471 this.checkLocks();
@@ -313,24 +513,42 @@ GameCore.prototype.trySpawn = function ()
313 513 { return null; }
314 514 var col = eligible[Math.floor(this.rng() * eligible.length) % eligible.length];
315 515 var color = this.randomColor();
316 return this.createBlock(col, this.height, color, STATE_FALLING);
516 var block = this.createBlock(col, this.height, color, STATE_FALLING);
517 block.vy = -this.planet.fallSpeed;
518 return block;
317 519 };
318 520
319 521 GameCore.prototype.integrateFalling = function (dt)
320 522 {
321 var speed = this.planet.fallSpeed;
523 var falling = [];
322 524 for (var i = 0; i < this.blocks.length; i++)
323 525 {
324 var block = this.blocks[i];
526 if (this.blocks[i].state === STATE_FALLING)
527 { falling.push(this.blocks[i]); }
528 }
529 // Lowest first, so a stack of falling blocks rests on itself.
530 falling.sort(function (a, b) { return a.y - b.y; });
531 for (var i = 0; i < falling.length; i++)
532 {
533 var block = falling[i];
325 534 if (block.state !== STATE_FALLING)
326 535 { continue; }
536 this.accelerateFall(block, dt);
537 var nextY = block.y + block.vy * dt;
538 var flyer = this.highestFlyingBelow(block);
539 if (flyer && nextY <= flyer.y + 1 + 1e-9)
540 {
541 if (this.attachToFlyingCluster(block, flyer))
542 { continue; }
543 }
327 544 var top = this.stackTop(block.col);
328 var nextY = block.y - speed * dt;
545 var below = this.highestFallingBelow(block);
546 if (below && below.y + 1 > top)
547 { top = below.y + 1; }
329 548 if (nextY <= top)
330 549 {
331 550 block.y = top;
332 block.state = STATE_STILL;
333 block.vy = 0;
551 this.landFallingBlock(block);
334 552 }
335 553 else
336 554 { block.y = nextY; }
@@ -353,7 +571,8 @@ GameCore.prototype.clusterMembers = function (clusterId)
353 571 * Advance a jump (cluster or manual) by dt. Uses exact kinematics so a
354 572 * jump of height H peaks at exactly H after riseTime. Returns dy.
355 573 * Mutates body.vy and body.phase ('up' / 'down'). body.decel is the
356 * upward deceleration; falling uses planet.fallSpeed.
574 * upward deceleration. After the apex, vy eases from 0 to -fallSpeed
575 * at planet.fallAccel, then stays at terminal fallSpeed.
357 576 */
358 577 GameCore.prototype.advanceJump = function (body, dt)
359 578 {
@@ -386,8 +605,35 @@ GameCore.prototype.advanceJump = function (body, dt)
386 605 }
387 606 if (body.phase === 'down' && left > 0)
388 607 {
389 body.vy = -this.planet.fallSpeed;
390 dy += body.vy * left;
608 var target = -this.planet.fallSpeed;
609 var accel = this.planet.fallAccel;
610 if (accel < 1e-12)
611 {
612 body.vy = target;
613 dy += body.vy * left;
614 }
615 else if (body.vy > target + 1e-12)
616 {
617 var tReach = (body.vy - target) / accel;
618 if (tReach <= left + 1e-15)
619 {
620 dy += (body.vy + target) * 0.5 * tReach;
621 body.vy = target;
622 left -= tReach;
623 dy += body.vy * left;
624 }
625 else
626 {
627 var vyNew = body.vy - accel * left;
628 dy += (body.vy + vyNew) * 0.5 * left;
629 body.vy = vyNew;
630 }
631 }
632 else
633 {
634 body.vy = target;
635 dy += body.vy * left;
636 }
391 637 }
392 638 return dy;
393 639 };
@@ -416,14 +662,18 @@ GameCore.prototype.integrateClusters = function (dt)
416 662 members[i].vy = cluster.vy;
417 663 }
418 664
665 this.catchFallingOntoCluster(cluster, members);
666
419 667 if (cluster.phase === 'down')
420 { this.tryLandCluster(cluster, members); }
668 { this.tryLandCluster(cluster, this.clusterMembers(cluster.id)); }
421 669 }
422 670 };
423 671
424 672 GameCore.prototype.tryLandCluster = function (cluster, members)
425 673 {
426 var self = this;
674 if (!members.length)
675 { return; }
676 var shift = 0;
427 677 var hit = false;
428 678 for (var i = 0; i < members.length; i++)
429 679 {
@@ -433,63 +683,109 @@ GameCore.prototype.tryLandCluster = function (cluster, members)
433 683 return other.clusterId === cluster.id;
434 684 });
435 685 if (block.y <= top + 1e-9)
436 { hit = true; }
686 {
687 hit = true;
688 var need = top - block.y;
689 if (need > shift)
690 { shift = need; }
691 }
437 692 }
438 693 if (!hit)
439 694 { return; }
695 // Lift the whole rigid body so the deepest contact sits flush.
696 for (var i = 0; i < members.length; i++)
697 { members[i].y += shift; }
440 698 this.landCluster(cluster, members);
441 699 };
442 700
701 /**
702 * Land as a rigid group: relative positions are kept, so part of the
703 * cluster may hang above a gap. Grey members start the 3s settle timer;
704 * coloured cargo stays put with them until every grey has recolored.
705 * Members that actually rest on the floor or on another block bounce.
706 */
443 707 GameCore.prototype.landCluster = function (cluster, members)
444 708 {
445 var byCol = Object.create(null);
446 709 for (var i = 0; i < members.length; i++)
447 710 {
448 711 var block = members[i];
449 if (!byCol[block.col])
450 { byCol[block.col] = []; }
451 byCol[block.col].push(block);
712 block.vy = 0;
713 block.flame = false;
714 block.clusterId = cluster.id;
715 if (block.color === COLOR_GRAY)
716 {
717 block.state = STATE_SETTLING;
718 block.settleTime = 0;
719 }
720 else
721 {
722 // Cargo stays in the rigid group (not matchable) until release.
723 block.state = STATE_SETTLING;
724 block.settleTime = 0;
725 }
726 if (this.hasSupport(block))
727 { this.startBounce(block); }
452 728 }
453 var cols = Object.keys(byCol);
454 for (var c = 0; c < cols.length; c++)
729 cluster.phase = 'landed';
730 cluster.vy = 0;
731 };
732
733 /**
734 * After every grey in a landed cluster has recolored, let the group go.
735 * Unsupported blocks fall individually from rest; supported ones stay.
736 */
737 GameCore.prototype.releaseLandedCluster = function (cluster)
738 {
739 var members = this.clusterMembers(cluster.id);
740 var releasing = Object.create(null);
741 for (var i = 0; i < members.length; i++)
742 { releasing[members[i].id] = true; }
743
744 for (var i = 0; i < members.length; i++)
455 745 {
456 var col = +cols[c];
457 var list = byCol[col];
458 list.sort(function (a, b) { return a.y - b.y; });
459 var self = this;
460 var top = this.stackTop(col, function (other)
746 var block = members[i];
747 if (block.color === COLOR_GRAY)
461 748 {
462 return other.clusterId === cluster.id;
463 });
464 for (var i = 0; i < list.length; i++)
749 block.color = this.randomColor();
750 block.settleTime = 0;
751 }
752 block.flame = false;
753 this.leaveCluster(block);
754 // Support from outside the group (floor or a foreign block). Fellow
755 // members that will also fall do not count, so a hanging stack
756 // drops together without the top one staying put.
757 var supported = this.hasSupportOutside(block, releasing);
758 if (supported)
465 759 {
466 var block = list[i];
467 block.y = top;
760 block.state = STATE_STILL;
761 block.vy = 0;
762 }
763 else
764 {
765 block.state = STATE_FALLING;
468 766 block.vy = 0;
469 block.flame = false;
470 top = block.y + 1;
471 if (block.color === COLOR_GRAY)
472 {
473 block.state = STATE_SETTLING;
474 block.settleTime = 0;
475 }
476 else
477 {
478 block.state = STATE_STILL;
479 block.clusterId = null;
480 }
481 767 }
482 768 }
483 cluster.phase = 'landed';
484 cluster.vy = 0;
485 var remaining = 0;
769 delete this.clusters[cluster.id];
770 };
771
772 GameCore.prototype.hasSupportOutside = function (block, ignoreIds)
773 {
774 if (block.y <= 1e-9)
775 { return true; }
486 776 for (var i = 0; i < this.blocks.length; i++)
487 777 {
488 if (this.blocks[i].clusterId === cluster.id)
489 { remaining++; }
778 var other = this.blocks[i];
779 if (other === block || other.col !== block.col)
780 { continue; }
781 if (ignoreIds && ignoreIds[other.id])
782 { continue; }
783 if (!this.isGrounded(other))
784 { continue; }
785 if (Math.abs((other.y + 1) - block.y) < ALIGN_EPS)
786 { return true; }
490 787 }
491 if (remaining === 0)
492 { delete this.clusters[cluster.id]; }
788 return false;
493 789 };
494 790
495 791 GameCore.prototype.integrateManual = function (dt)
@@ -526,8 +822,11 @@ GameCore.prototype.integrateManual = function (dt)
526 822
527 823 if (block.manualPhase === 'down')
528 824 {
825 var proxy = { phase: 'down', vy: block.vy, decel: 0 };
826 var dy = this.advanceJump(proxy, dt);
827 block.vy = proxy.vy;
828 var nextY = block.y + dy;
529 829 var top = this.stackTop(block.col);
530 var nextY = block.y - this.planet.fallSpeed * dt;
531 830 if (nextY <= top)
532 831 {
533 832 block.y = top;
@@ -535,11 +834,11 @@ GameCore.prototype.integrateManual = function (dt)
535 834 block.vy = 0;
536 835 block.manualPhase = null;
537 836 block.flame = false;
837 this.startBounce(block);
538 838 }
539 839 else
540 840 {
541 841 block.y = Math.min(nextY, this.height - 1);
542 block.vy = -this.planet.fallSpeed;
543 842 }
544 843 }
545 844 }
@@ -698,15 +997,64 @@ GameCore.prototype.advanceSettle = function (dt)
698 997 var block = this.blocks[i];
699 998 if (block.state !== STATE_SETTLING)
700 999 { continue; }
701 block.settleTime += dt;
702 if (block.settleTime >= this.settleTime)
1000 var inLanded = block.clusterId != null
1001 && this.clusters[block.clusterId]
1002 && this.clusters[block.clusterId].phase === 'landed';
1003 if (block.color === COLOR_GRAY)
703 1004 {
704 block.color = this.randomColor();
705 block.state = STATE_STILL;
706 block.settleTime = 0;
707 block.flame = false;
1005 block.settleTime += dt;
1006 if (block.settleTime >= this.settleTime)
1007 {
1008 block.color = this.randomColor();
1009 block.settleTime = 0;
1010 block.flame = false;
1011 if (inLanded)
1012 {
1013 // Stay in the rigid group; releaseLandedCluster runs below.
1014 block.state = STATE_SETTLING;
1015 }
1016 else
1017 {
1018 this.leaveCluster(block);
1019 if (this.hasSupport(block))
1020 {
1021 block.state = STATE_STILL;
1022 block.vy = 0;
1023 }
1024 else
1025 {
1026 block.state = STATE_FALLING;
1027 block.vy = 0;
1028 }
1029 }
1030 }
1031 }
1032 else if (!inLanded)
1033 {
1034 // Coloured settling that is not in a landed cluster (shouldn't
1035 // normally happen): just become still or fall.
708 1036 this.leaveCluster(block);
1037 block.state = this.hasSupport(block) ? STATE_STILL : STATE_FALLING;
1038 if (block.state === STATE_FALLING)
1039 { block.vy = 0; }
1040 }
1041 }
1042
1043 var ids = Object.keys(this.clusters);
1044 for (var n = 0; n < ids.length; n++)
1045 {
1046 var cluster = this.clusters[ids[n]];
1047 if (!cluster || cluster.phase !== 'landed')
1048 { continue; }
1049 var members = this.clusterMembers(cluster.id);
1050 var greySettling = false;
1051 for (var i = 0; i < members.length; i++)
1052 {
1053 if (members[i].color === COLOR_GRAY && members[i].state === STATE_SETTLING)
1054 { greySettling = true; }
709 1055 }
1056 if (!greySettling)
1057 { this.releaseLandedCluster(cluster); }
710 1058 }
711 1059 };
712 1060
@@ -1020,7 +1368,15 @@ GameCore.prototype.beginDrag = function (col, y)
1020 1368 var block = this.blockAt(col, row);
1021 1369 if (!block || block.state !== STATE_STILL || block.color < 0)
1022 1370 { return false; }
1023 this.drag = { blockId: block.id, pointerY: y, launchIntent: false };
1371 var top = this.columnStackTopRow(col);
1372 var startedAsTop = Math.abs(block.y - top) < ALIGN_EPS;
1373 this.drag = {
1374 blockId: block.id,
1375 pointerY: y,
1376 startY: y,
1377 launchIntent: false,
1378 startedAsTop: startedAsTop
1379 };
1024 1380 return true;
1025 1381 };
1026 1382
@@ -1042,9 +1398,19 @@ GameCore.prototype.moveDrag = function (y)
1042 1398 this.drag.pointerY = y;
1043 1399 this.swapToward(block, y);
1044 1400 var top = this.columnStackTopRow(block.col);
1045 // The top block occupies [top, top+1). Launch only when the pointer
1046 // is pulled into the empty space above the stack.
1047 this.drag.launchIntent = (Math.abs(block.y - top) < ALIGN_EPS && y > top + 1 + 0.25);
1401 var isTop = Math.abs(block.y - top) < ALIGN_EPS;
1402 if (this.drag.startedAsTop)
1403 {
1404 // Already the topmost block: pulling upward past its own position
1405 // (LAUNCH_PULL tiles above the press point) starts a manual jump.
1406 this.drag.launchIntent = isTop && (y > this.drag.startY + LAUNCH_PULL);
1407 }
1408 else
1409 {
1410 // Started mid-stack: swap first, and only launch once the pointer
1411 // is pulled into the empty space above the (new) top.
1412 this.drag.launchIntent = isTop && (y > top + 1 + 0.25);
1413 }
1048 1414 };
1049 1415
1050 1416 GameCore.prototype.endDrag = function ()
@@ -22,6 +22,8 @@ var STATE_MANUAL = 'manual';
22var ALIGN_EPS = 0.15;
22var ALIGN_EPS = 0.15;
23var SUBSTEP = 1 / 120;
23var SUBSTEP = 1 / 120;
24var DRAG_LAUNCH_SLACK = 0.65;
24var DRAG_LAUNCH_SLACK = 0.65;
25// Upward pull (tiles past the press point) that launches an already-topmost block.
26var LAUNCH_PULL = 0.35;
25
27
26function UnionFind ()
28function UnionFind ()
27{
29{
@@ -71,6 +73,7 @@ function GameCore (planet, rng)
71}
73}
72
74
73GameCore.COLOR_GRAY = COLOR_GRAY;
75GameCore.COLOR_GRAY = COLOR_GRAY;
76GameCore.LAUNCH_PULL = LAUNCH_PULL;
74GameCore.STATE_STILL = STATE_STILL;
77GameCore.STATE_STILL = STATE_STILL;
75GameCore.STATE_FALLING = STATE_FALLING;
78GameCore.STATE_FALLING = STATE_FALLING;
76GameCore.STATE_FLYING = STATE_FLYING;
79GameCore.STATE_FLYING = STATE_FLYING;
@@ -98,7 +101,9 @@ GameCore.prototype.createBlock = function (col, y, color, state)
98 pushedClusters: null,
101 pushedClusters: null,
99 manualTarget: 0,
102 manualTarget: 0,
100 manualDecel: 0,
103 manualDecel: 0,
101 manualPhase: null
104 manualPhase: null,
105 bouncing: false,
106 bounceAge: 0
102 };
107 };
103 this.blocks.push(block);
108 this.blocks.push(block);
104 return block;
109 return block;
@@ -236,6 +241,199 @@ GameCore.prototype.lockedColumnCount = function ()
236 return n;
241 return n;
237};
242};
238
243
244GameCore.prototype.startBounce = function (block)
245{
246 if (!block)
247 { return; }
248 block.bouncing = true;
249 block.bounceAge = 0;
250};
251
252GameCore.prototype.advanceBounces = function (dt)
253{
254 var duration = this.planet.bounceDuration;
255 for (var i = 0; i < this.blocks.length; i++)
256 {
257 var block = this.blocks[i];
258 if (!block.bouncing)
259 { continue; }
260 block.bounceAge += dt;
261 if (duration <= 0 || block.bounceAge >= duration)
262 {
263 block.bouncing = false;
264 block.bounceAge = duration;
265 }
266 }
267};
268
269/**
270 * True if `block` rests on the floor or on a solid (still / settling /
271 * locked) block immediately below it in the same column.
272 */
273GameCore.prototype.hasSupport = function (block)
274{
275 if (block.y <= 1e-9)
276 { return true; }
277 for (var i = 0; i < this.blocks.length; i++)
278 {
279 var other = this.blocks[i];
280 if (other === block || other.col !== block.col)
281 { continue; }
282 if (!this.isGrounded(other))
283 { continue; }
284 if (Math.abs((other.y + 1) - block.y) < ALIGN_EPS)
285 { return true; }
286 }
287 return false;
288};
289
290/** Highest flying block in this column whose top is at or below `block.y + 1`. */
291GameCore.prototype.highestFlyingBelow = function (block)
292{
293 var best = null;
294 for (var i = 0; i < this.blocks.length; i++)
295 {
296 var other = this.blocks[i];
297 if (other === block || other.col !== block.col)
298 { continue; }
299 if (other.state !== STATE_FLYING || other.clusterId == null)
300 { continue; }
301 var cluster = this.clusters[other.clusterId];
302 if (!cluster || cluster.phase === 'landed')
303 { continue; }
304 // The falling block is at or above this flyer (or already overlapping).
305 if (block.y + 1e-9 < other.y)
306 { continue; }
307 if (!best || other.y > best.y)
308 { best = other; }
309 }
310 return best;
311};
312
313GameCore.prototype.highestFallingBelow = function (block)
314{
315 var best = null;
316 for (var i = 0; i < this.blocks.length; i++)
317 {
318 var other = this.blocks[i];
319 if (other === block || other.col !== block.col)
320 { continue; }
321 if (other.state !== STATE_FALLING)
322 { continue; }
323 if (other.y > block.y - 1e-9)
324 { continue; }
325 if (!best || other.y > best.y)
326 { best = other; }
327 }
328 return best;
329};
330
331/**
332 * Make an unsupported still block start falling from rest, so it eases
333 * into fallSpeed under normal gravity. Skips the block being dragged.
334 */
335GameCore.prototype.releaseUnsupported = function ()
336{
337 for (var i = 0; i < this.blocks.length; i++)
338 {
339 var block = this.blocks[i];
340 if (block.state !== STATE_STILL)
341 { continue; }
342 if (this.drag && this.drag.blockId === block.id)
343 { continue; }
344 if (this.hasSupport(block))
345 { continue; }
346 block.state = STATE_FALLING;
347 block.vy = 0;
348 block.flame = false;
349 this.leaveCluster(block);
350 }
351};
352
353GameCore.prototype.accelerateFall = function (block, dt)
354{
355 var target = -this.planet.fallSpeed;
356 if (block.vy > target)
357 { block.vy = Math.max(target, block.vy - this.planet.fallAccel * dt); }
358 else
359 { block.vy = target; }
360};
361
362GameCore.prototype.landFallingBlock = function (block)
363{
364 block.vy = 0;
365 block.flame = false;
366 this.startBounce(block);
367 if (block.color === COLOR_GRAY)
368 {
369 block.state = STATE_SETTLING;
370 block.settleTime = 0;
371 }
372 else
373 { block.state = STATE_STILL; }
374};
375
376/**
377 * Sit `block` on top of the flying cluster that `flyer` belongs to, and
378 * carry it along as cargo (no flame). Returns true if attached.
379 */
380GameCore.prototype.attachToFlyingCluster = function (block, flyer)
381{
382 var cluster = this.clusters[flyer.clusterId];
383 if (!cluster || cluster.phase === 'landed')
384 { return false; }
385 var roof = flyer.y + 1;
386 for (var i = 0; i < this.blocks.length; i++)
387 {
388 var other = this.blocks[i];
389 if (other === block || other.col !== block.col)
390 { continue; }
391 if (other.clusterId !== cluster.id)
392 { continue; }
393 if (other.y + 1 > roof)
394 { roof = other.y + 1; }
395 }
396 block.y = roof;
397 block.state = STATE_FLYING;
398 block.clusterId = cluster.id;
399 block.vy = cluster.vy;
400 block.flame = false;
401 block.settleTime = 0;
402 return true;
403};
404
405GameCore.prototype.catchFallingOntoCluster = function (cluster, members)
406{
407 if (!cluster || cluster.phase === 'landed' || cluster.phase === 'hold')
408 { return; }
409 // Snapshot falling blocks; attaching mutates state.
410 var falling = [];
411 for (var i = 0; i < this.blocks.length; i++)
412 {
413 if (this.blocks[i].state === STATE_FALLING)
414 { falling.push(this.blocks[i]); }
415 }
416 for (var i = 0; i < falling.length; i++)
417 {
418 var block = falling[i];
419 var flyer = null;
420 for (var m = 0; m < members.length; m++)
421 {
422 var other = members[m];
423 if (other.col !== block.col)
424 { continue; }
425 // Overlap or rest on this member's top.
426 if (block.y < other.y + 1 + 1e-9 && block.y + 1 > other.y - 1e-9)
427 {
428 if (!flyer || other.y > flyer.y)
429 { flyer = other; }
430 }
431 }
432 if (flyer)
433 { this.attachToFlyingCluster(block, flyer); }
434 }
435};
436
239GameCore.prototype.tick = function (dt)
437GameCore.prototype.tick = function (dt)
240{
438{
241 if (this.state === 'gameover')
439 if (this.state === 'gameover')
@@ -265,7 +463,9 @@ GameCore.prototype.tick = function (dt)
265 left -= step;
463 left -= step;
266 }
464 }
267
465
466 this.releaseUnsupported();
268 this.advanceSettle(dt);
467 this.advanceSettle(dt);
468 this.advanceBounces(dt);
269 if (!this.drag)
469 if (!this.drag)
270 { this.resolveMatches(); }
470 { this.resolveMatches(); }
271 this.checkLocks();
471 this.checkLocks();
@@ -313,24 +513,42 @@ GameCore.prototype.trySpawn = function ()
313 { return null; }
513 { return null; }
314 var col = eligible[Math.floor(this.rng() * eligible.length) % eligible.length];
514 var col = eligible[Math.floor(this.rng() * eligible.length) % eligible.length];
315 var color = this.randomColor();
515 var color = this.randomColor();
316 return this.createBlock(col, this.height, color, STATE_FALLING);
516 var block = this.createBlock(col, this.height, color, STATE_FALLING);
517 block.vy = -this.planet.fallSpeed;
518 return block;
317};
519};
318
520
319GameCore.prototype.integrateFalling = function (dt)
521GameCore.prototype.integrateFalling = function (dt)
320{
522{
321 var speed = this.planet.fallSpeed;
523 var falling = [];
322 for (var i = 0; i < this.blocks.length; i++)
524 for (var i = 0; i < this.blocks.length; i++)
323 {
525 {
324 var block = this.blocks[i];
526 if (this.blocks[i].state === STATE_FALLING)
527 { falling.push(this.blocks[i]); }
528 }
529 // Lowest first, so a stack of falling blocks rests on itself.
530 falling.sort(function (a, b) { return a.y - b.y; });
531 for (var i = 0; i < falling.length; i++)
532 {
533 var block = falling[i];
325 if (block.state !== STATE_FALLING)
534 if (block.state !== STATE_FALLING)
326 { continue; }
535 { continue; }
536 this.accelerateFall(block, dt);
537 var nextY = block.y + block.vy * dt;
538 var flyer = this.highestFlyingBelow(block);
539 if (flyer && nextY <= flyer.y + 1 + 1e-9)
540 {
541 if (this.attachToFlyingCluster(block, flyer))
542 { continue; }
543 }
327 var top = this.stackTop(block.col);
544 var top = this.stackTop(block.col);
328 var nextY = block.y - speed * dt;
545 var below = this.highestFallingBelow(block);
546 if (below && below.y + 1 > top)
547 { top = below.y + 1; }
329 if (nextY <= top)
548 if (nextY <= top)
330 {
549 {
331 block.y = top;
550 block.y = top;
332 block.state = STATE_STILL;
551 this.landFallingBlock(block);
333 block.vy = 0;
334 }
552 }
335 else
553 else
336 { block.y = nextY; }
554 { block.y = nextY; }
@@ -353,7 +571,8 @@ GameCore.prototype.clusterMembers = function (clusterId)
353 * Advance a jump (cluster or manual) by dt. Uses exact kinematics so a
571 * Advance a jump (cluster or manual) by dt. Uses exact kinematics so a
354 * jump of height H peaks at exactly H after riseTime. Returns dy.
572 * jump of height H peaks at exactly H after riseTime. Returns dy.
355 * Mutates body.vy and body.phase ('up' / 'down'). body.decel is the
573 * Mutates body.vy and body.phase ('up' / 'down'). body.decel is the
356 * upward deceleration; falling uses planet.fallSpeed.
574 * upward deceleration. After the apex, vy eases from 0 to -fallSpeed
575 * at planet.fallAccel, then stays at terminal fallSpeed.
357 */
576 */
358GameCore.prototype.advanceJump = function (body, dt)
577GameCore.prototype.advanceJump = function (body, dt)
359{
578{
@@ -386,8 +605,35 @@ GameCore.prototype.advanceJump = function (body, dt)
386 }
605 }
387 if (body.phase === 'down' && left > 0)
606 if (body.phase === 'down' && left > 0)
388 {
607 {
389 body.vy = -this.planet.fallSpeed;
608 var target = -this.planet.fallSpeed;
390 dy += body.vy * left;
609 var accel = this.planet.fallAccel;
610 if (accel < 1e-12)
611 {
612 body.vy = target;
613 dy += body.vy * left;
614 }
615 else if (body.vy > target + 1e-12)
616 {
617 var tReach = (body.vy - target) / accel;
618 if (tReach <= left + 1e-15)
619 {
620 dy += (body.vy + target) * 0.5 * tReach;
621 body.vy = target;
622 left -= tReach;
623 dy += body.vy * left;
624 }
625 else
626 {
627 var vyNew = body.vy - accel * left;
628 dy += (body.vy + vyNew) * 0.5 * left;
629 body.vy = vyNew;
630 }
631 }
632 else
633 {
634 body.vy = target;
635 dy += body.vy * left;
636 }
391 }
637 }
392 return dy;
638 return dy;
393};
639};
@@ -416,14 +662,18 @@ GameCore.prototype.integrateClusters = function (dt)
416 members[i].vy = cluster.vy;
662 members[i].vy = cluster.vy;
417 }
663 }
418
664
665 this.catchFallingOntoCluster(cluster, members);
666
419 if (cluster.phase === 'down')
667 if (cluster.phase === 'down')
420 { this.tryLandCluster(cluster, members); }
668 { this.tryLandCluster(cluster, this.clusterMembers(cluster.id)); }
421 }
669 }
422};
670};
423
671
424GameCore.prototype.tryLandCluster = function (cluster, members)
672GameCore.prototype.tryLandCluster = function (cluster, members)
425{
673{
426 var self = this;
674 if (!members.length)
675 { return; }
676 var shift = 0;
427 var hit = false;
677 var hit = false;
428 for (var i = 0; i < members.length; i++)
678 for (var i = 0; i < members.length; i++)
429 {
679 {
@@ -433,63 +683,109 @@ GameCore.prototype.tryLandCluster = function (cluster, members)
433 return other.clusterId === cluster.id;
683 return other.clusterId === cluster.id;
434 });
684 });
435 if (block.y <= top + 1e-9)
685 if (block.y <= top + 1e-9)
436 { hit = true; }
686 {
687 hit = true;
688 var need = top - block.y;
689 if (need > shift)
690 { shift = need; }
691 }
437 }
692 }
438 if (!hit)
693 if (!hit)
439 { return; }
694 { return; }
695 // Lift the whole rigid body so the deepest contact sits flush.
696 for (var i = 0; i < members.length; i++)
697 { members[i].y += shift; }
440 this.landCluster(cluster, members);
698 this.landCluster(cluster, members);
441};
699};
442
700
701/**
702 * Land as a rigid group: relative positions are kept, so part of the
703 * cluster may hang above a gap. Grey members start the 3s settle timer;
704 * coloured cargo stays put with them until every grey has recolored.
705 * Members that actually rest on the floor or on another block bounce.
706 */
443GameCore.prototype.landCluster = function (cluster, members)
707GameCore.prototype.landCluster = function (cluster, members)
444{
708{
445 var byCol = Object.create(null);
446 for (var i = 0; i < members.length; i++)
709 for (var i = 0; i < members.length; i++)
447 {
710 {
448 var block = members[i];
711 var block = members[i];
449 if (!byCol[block.col])
712 block.vy = 0;
450 { byCol[block.col] = []; }
713 block.flame = false;
451 byCol[block.col].push(block);
714 block.clusterId = cluster.id;
715 if (block.color === COLOR_GRAY)
716 {
717 block.state = STATE_SETTLING;
718 block.settleTime = 0;
719 }
720 else
721 {
722 // Cargo stays in the rigid group (not matchable) until release.
723 block.state = STATE_SETTLING;
724 block.settleTime = 0;
725 }
726 if (this.hasSupport(block))
727 { this.startBounce(block); }
452 }
728 }
453 var cols = Object.keys(byCol);
729 cluster.phase = 'landed';
454 for (var c = 0; c < cols.length; c++)
730 cluster.vy = 0;
731};
732
733/**
734 * After every grey in a landed cluster has recolored, let the group go.
735 * Unsupported blocks fall individually from rest; supported ones stay.
736 */
737GameCore.prototype.releaseLandedCluster = function (cluster)
738{
739 var members = this.clusterMembers(cluster.id);
740 var releasing = Object.create(null);
741 for (var i = 0; i < members.length; i++)
742 { releasing[members[i].id] = true; }
743
744 for (var i = 0; i < members.length; i++)
455 {
745 {
456 var col = +cols[c];
746 var block = members[i];
457 var list = byCol[col];
747 if (block.color === COLOR_GRAY)
458 list.sort(function (a, b) { return a.y - b.y; });
459 var self = this;
460 var top = this.stackTop(col, function (other)
461 {
748 {
462 return other.clusterId === cluster.id;
749 block.color = this.randomColor();
463 });
750 block.settleTime = 0;
464 for (var i = 0; i < list.length; i++)
751 }
752 block.flame = false;
753 this.leaveCluster(block);
754 // Support from outside the group (floor or a foreign block). Fellow
755 // members that will also fall do not count, so a hanging stack
756 // drops together without the top one staying put.
757 var supported = this.hasSupportOutside(block, releasing);
758 if (supported)
465 {
759 {
466 var block = list[i];
760 block.state = STATE_STILL;
467 block.y = top;
761 block.vy = 0;
762 }
763 else
764 {
765 block.state = STATE_FALLING;
468 block.vy = 0;
766 block.vy = 0;
469 block.flame = false;
470 top = block.y + 1;
471 if (block.color === COLOR_GRAY)
472 {
473 block.state = STATE_SETTLING;
474 block.settleTime = 0;
475 }
476 else
477 {
478 block.state = STATE_STILL;
479 block.clusterId = null;
480 }
481 }
767 }
482 }
768 }
483 cluster.phase = 'landed';
769 delete this.clusters[cluster.id];
484 cluster.vy = 0;
770};
485 var remaining = 0;
771
772GameCore.prototype.hasSupportOutside = function (block, ignoreIds)
773{
774 if (block.y <= 1e-9)
775 { return true; }
486 for (var i = 0; i < this.blocks.length; i++)
776 for (var i = 0; i < this.blocks.length; i++)
487 {
777 {
488 if (this.blocks[i].clusterId === cluster.id)
778 var other = this.blocks[i];
489 { remaining++; }
779 if (other === block || other.col !== block.col)
780 { continue; }
781 if (ignoreIds && ignoreIds[other.id])
782 { continue; }
783 if (!this.isGrounded(other))
784 { continue; }
785 if (Math.abs((other.y + 1) - block.y) < ALIGN_EPS)
786 { return true; }
490 }
787 }
491 if (remaining === 0)
788 return false;
492 { delete this.clusters[cluster.id]; }
493};
789};
494
790
495GameCore.prototype.integrateManual = function (dt)
791GameCore.prototype.integrateManual = function (dt)
@@ -526,8 +822,11 @@ GameCore.prototype.integrateManual = function (dt)
526
822
527 if (block.manualPhase === 'down')
823 if (block.manualPhase === 'down')
528 {
824 {
825 var proxy = { phase: 'down', vy: block.vy, decel: 0 };
826 var dy = this.advanceJump(proxy, dt);
827 block.vy = proxy.vy;
828 var nextY = block.y + dy;
529 var top = this.stackTop(block.col);
829 var top = this.stackTop(block.col);
530 var nextY = block.y - this.planet.fallSpeed * dt;
531 if (nextY <= top)
830 if (nextY <= top)
532 {
831 {
533 block.y = top;
832 block.y = top;
@@ -535,11 +834,11 @@ GameCore.prototype.integrateManual = function (dt)
535 block.vy = 0;
834 block.vy = 0;
536 block.manualPhase = null;
835 block.manualPhase = null;
537 block.flame = false;
836 block.flame = false;
837 this.startBounce(block);
538 }
838 }
539 else
839 else
540 {
840 {
541 block.y = Math.min(nextY, this.height - 1);
841 block.y = Math.min(nextY, this.height - 1);
542 block.vy = -this.planet.fallSpeed;
543 }
842 }
544 }
843 }
545 }
844 }
@@ -698,15 +997,64 @@ GameCore.prototype.advanceSettle = function (dt)
698 var block = this.blocks[i];
997 var block = this.blocks[i];
699 if (block.state !== STATE_SETTLING)
998 if (block.state !== STATE_SETTLING)
700 { continue; }
999 { continue; }
701 block.settleTime += dt;
1000 var inLanded = block.clusterId != null
702 if (block.settleTime >= this.settleTime)
1001 && this.clusters[block.clusterId]
1002 && this.clusters[block.clusterId].phase === 'landed';
1003 if (block.color === COLOR_GRAY)
703 {
1004 {
704 block.color = this.randomColor();
1005 block.settleTime += dt;
705 block.state = STATE_STILL;
1006 if (block.settleTime >= this.settleTime)
706 block.settleTime = 0;
1007 {
707 block.flame = false;
1008 block.color = this.randomColor();
1009 block.settleTime = 0;
1010 block.flame = false;
1011 if (inLanded)
1012 {
1013 // Stay in the rigid group; releaseLandedCluster runs below.
1014 block.state = STATE_SETTLING;
1015 }
1016 else
1017 {
1018 this.leaveCluster(block);
1019 if (this.hasSupport(block))
1020 {
1021 block.state = STATE_STILL;
1022 block.vy = 0;
1023 }
1024 else
1025 {
1026 block.state = STATE_FALLING;
1027 block.vy = 0;
1028 }
1029 }
1030 }
1031 }
1032 else if (!inLanded)
1033 {
1034 // Coloured settling that is not in a landed cluster (shouldn't
1035 // normally happen): just become still or fall.
708 this.leaveCluster(block);
1036 this.leaveCluster(block);
1037 block.state = this.hasSupport(block) ? STATE_STILL : STATE_FALLING;
1038 if (block.state === STATE_FALLING)
1039 { block.vy = 0; }
1040 }
1041 }
1042
1043 var ids = Object.keys(this.clusters);
1044 for (var n = 0; n < ids.length; n++)
1045 {
1046 var cluster = this.clusters[ids[n]];
1047 if (!cluster || cluster.phase !== 'landed')
1048 { continue; }
1049 var members = this.clusterMembers(cluster.id);
1050 var greySettling = false;
1051 for (var i = 0; i < members.length; i++)
1052 {
1053 if (members[i].color === COLOR_GRAY && members[i].state === STATE_SETTLING)
1054 { greySettling = true; }
709 }
1055 }
1056 if (!greySettling)
1057 { this.releaseLandedCluster(cluster); }
710 }
1058 }
711};
1059};
712
1060
@@ -1020,7 +1368,15 @@ GameCore.prototype.beginDrag = function (col, y)
1020 var block = this.blockAt(col, row);
1368 var block = this.blockAt(col, row);
1021 if (!block || block.state !== STATE_STILL || block.color < 0)
1369 if (!block || block.state !== STATE_STILL || block.color < 0)
1022 { return false; }
1370 { return false; }
1023 this.drag = { blockId: block.id, pointerY: y, launchIntent: false };
1371 var top = this.columnStackTopRow(col);
1372 var startedAsTop = Math.abs(block.y - top) < ALIGN_EPS;
1373 this.drag = {
1374 blockId: block.id,
1375 pointerY: y,
1376 startY: y,
1377 launchIntent: false,
1378 startedAsTop: startedAsTop
1379 };
1024 return true;
1380 return true;
1025};
1381};
1026
1382
@@ -1042,9 +1398,19 @@ GameCore.prototype.moveDrag = function (y)
1042 this.drag.pointerY = y;
1398 this.drag.pointerY = y;
1043 this.swapToward(block, y);
1399 this.swapToward(block, y);
1044 var top = this.columnStackTopRow(block.col);
1400 var top = this.columnStackTopRow(block.col);
1045 // The top block occupies [top, top+1). Launch only when the pointer
1401 var isTop = Math.abs(block.y - top) < ALIGN_EPS;
1046 // is pulled into the empty space above the stack.
1402 if (this.drag.startedAsTop)
1047 this.drag.launchIntent = (Math.abs(block.y - top) < ALIGN_EPS && y > top + 1 + 0.25);
1403 {
1404 // Already the topmost block: pulling upward past its own position
1405 // (LAUNCH_PULL tiles above the press point) starts a manual jump.
1406 this.drag.launchIntent = isTop && (y > this.drag.startY + LAUNCH_PULL);
1407 }
1408 else
1409 {
1410 // Started mid-stack: swap first, and only launch once the pointer
1411 // is pulled into the empty space above the (new) top.
1412 this.drag.launchIntent = isTop && (y > top + 1 + 0.25);
1413 }
1048};
1414};
1049
1415
1050GameCore.prototype.endDrag = function ()
1416GameCore.prototype.endDrag = function ()
src/main.js +138 −14
@@ -41,7 +41,8 @@ var app = {
41 41 flames: Object.create(null),
42 42 cells: [],
43 43 pointerId: null,
44 gameOverShown: false
44 gameOverShown: false,
45 selectTween: null
45 46 };
46 47
47 48 window.onload = function ()
@@ -87,6 +88,7 @@ function startPlay ()
87 88 app.flames = Object.create(null);
88 89 app.cells = [];
89 90 app.pointerId = null;
91 app.selectTween = null;
90 92
91 93 layout();
92 94 app.scene = new Scene(app.fieldX, app.fieldY, app.fieldW, app.fieldH);
@@ -114,6 +116,7 @@ function returnToMenu ()
114 116 app.sprites = Object.create(null);
115 117 app.flames = Object.create(null);
116 118 app.cells = [];
119 app.selectTween = null;
117 120
118 121 hideEl('hud');
119 122 hideEl('game-over');
@@ -212,6 +215,7 @@ function syncSprites ()
212 215 }
213 216 obj.renderer.sprite = spriteFor(block);
214 217 placeTile(obj, block.col, block.y);
218 applyBlockVisual(obj, block);
215 219 obj.renderer.visible = true;
216 220 obj.renderer.alpha = 1;
217 221
@@ -251,6 +255,96 @@ function syncSprites ()
251 255 }
252 256 }
253 257
258 function applyBlockVisual (obj, block)
259 {
260 var t = app.tile;
261 var sx = 1;
262 var sy = 1;
263 var dy = 0;
264 if (block.bouncing && app.planet && app.planet.bounceDuration > 0
265 && typeof Easing !== 'undefined' && Easing.bouncePose)
266 {
267 var u = block.bounceAge / app.planet.bounceDuration;
268 var pose = Easing.bouncePose(u, app.planet.bounceSquash);
269 sx = pose.sx;
270 sy = pose.sy;
271 dy = pose.dy;
272 }
273 var sel = 1;
274 var tw = app.selectTween;
275 if (tw && tw.blockId === block.id && tw.phase !== 'idle')
276 { sel = tw.scale; }
277 obj.transform.size = { x: t * sx * sel, y: t * sy * sel };
278 if (dy)
279 { obj.transform.position.y -= dy * t; }
280 }
281
282 function clickTween ()
283 {
284 return (typeof Easing !== 'undefined' && Easing.CLICK_TWEEN) ? Easing.CLICK_TWEEN : null;
285 }
286
287 function startPressTween (blockId)
288 {
289 var c = clickTween();
290 if (!c)
291 { return; }
292 var from = (app.selectTween && app.selectTween.phase !== 'idle') ? app.selectTween.scale : 1;
293 app.selectTween = {
294 blockId: blockId,
295 from: from,
296 to: c.pressScale,
297 t: 0,
298 duration: c.pressDuration,
299 ease: c.pressEase,
300 scale: from,
301 phase: 'press'
302 };
303 }
304
305 function startReleaseTween ()
306 {
307 var c = clickTween();
308 var tw = app.selectTween;
309 if (!c || !tw || tw.phase === 'idle')
310 { return; }
311 app.selectTween = {
312 blockId: tw.blockId,
313 from: tw.scale,
314 to: c.releaseScale,
315 t: 0,
316 duration: c.releaseDuration,
317 ease: c.releaseEase,
318 scale: tw.scale,
319 phase: 'release'
320 };
321 }
322
323 function updateSelectTween (dt)
324 {
325 var tw = app.selectTween;
326 if (!tw || tw.phase === 'idle' || tw.phase === 'hold')
327 { return; }
328 tw.t += dt;
329 var u = tw.duration > 0 ? tw.t / tw.duration : 1;
330 if (u >= 1)
331 {
332 tw.scale = tw.to;
333 tw.t = tw.duration;
334 if (tw.phase === 'press')
335 { tw.phase = 'hold'; }
336 else
337 {
338 tw.phase = 'idle';
339 tw.scale = 1;
340 tw.blockId = null;
341 }
342 return;
343 }
344 var ease = tw.ease || (typeof Easing !== 'undefined' && Easing.easeOutBack);
345 tw.scale = ease ? Easing.tween(tw.from, tw.to, u, ease) : tw.from + (tw.to - tw.from) * u;
346 }
347
254 348 function refreshHud ()
255 349 {
256 350 if (!app.core)
@@ -291,6 +385,7 @@ function tickView (dt)
291 385 }
292 386
293 387 app.core.tick(dt);
388 updateSelectTween(dt);
294 389 syncSprites();
295 390 refreshHud();
296 391
@@ -306,31 +401,51 @@ function tickView (dt)
306 401 }
307 402
308 403 /* ---------- pointer input (mouse + touch) --------------------------- */
404 /*
405 * Both mouse and touch use Pointer Events. After pointerdown we listen
406 * on window, so a drag that leaves the canvas (needed to launch a
407 * block at the top of a full column) still reaches moveDrag. We do
408 * not treat lostpointercapture as the end of a drag: on some touch
409 * browsers that fires mid-gesture and would cancel a launch.
410 */
309 411
310 412 var boundCanvas = null;
413 var windowListening = false;
414
415 function addWindowPointer ()
416 {
417 if (windowListening)
418 { return; }
419 window.addEventListener('pointermove', onPointerMove, true);
420 window.addEventListener('pointerup', onPointerUp, true);
421 window.addEventListener('pointercancel', onPointerUp, true);
422 windowListening = true;
423 }
424
425 function removeWindowPointer ()
426 {
427 if (!windowListening)
428 { return; }
429 window.removeEventListener('pointermove', onPointerMove, true);
430 window.removeEventListener('pointerup', onPointerUp, true);
431 window.removeEventListener('pointercancel', onPointerUp, true);
432 windowListening = false;
433 }
311 434
312 435 function bindPointer (canvas)
313 436 {
314 437 unbindPointer();
315 438 boundCanvas = canvas;
316 439 canvas.addEventListener('pointerdown', onPointerDown);
317 canvas.addEventListener('pointermove', onPointerMove);
318 canvas.addEventListener('pointerup', onPointerUp);
319 canvas.addEventListener('pointercancel', onPointerUp);
320 canvas.addEventListener('lostpointercapture', onPointerUp);
321 440 canvas.style.touchAction = 'none';
322 441 canvas.style.cursor = 'pointer';
323 442 }
324 443
325 444 function unbindPointer ()
326 445 {
327 if (!boundCanvas)
328 { return; }
329 boundCanvas.removeEventListener('pointerdown', onPointerDown);
330 boundCanvas.removeEventListener('pointermove', onPointerMove);
331 boundCanvas.removeEventListener('pointerup', onPointerUp);
332 boundCanvas.removeEventListener('pointercancel', onPointerUp);
333 boundCanvas.removeEventListener('lostpointercapture', onPointerUp);
446 removeWindowPointer();
447 if (boundCanvas)
448 { boundCanvas.removeEventListener('pointerdown', onPointerDown); }
334 449 boundCanvas = null;
335 450 app.pointerId = null;
336 451 }
@@ -361,9 +476,10 @@ function onPointerDown (e)
361 476 try
362 477 { boundCanvas.setPointerCapture(e.pointerId); }
363 478 catch (err) { /* ignore */ }
479 addWindowPointer();
364 480 var pos = fieldFromEvent(e);
365 if (pos)
366 { app.core.beginDrag(pos.col, pos.y); }
481 if (pos && app.core.beginDrag(pos.col, pos.y) && app.core.drag)
482 { startPressTween(app.core.drag.blockId); }
367 483 }
368 484
369 485 function onPointerMove (e)
@@ -387,6 +503,14 @@ function onPointerUp (e)
387 503 if (e)
388 504 { e.preventDefault(); }
389 505 app.pointerId = null;
506 removeWindowPointer();
507 if (boundCanvas)
508 {
509 try
510 { boundCanvas.releasePointerCapture(e && e.pointerId); }
511 catch (err) { /* ignore */ }
512 }
513 startReleaseTween();
390 514 if (app.core)
391 515 { app.core.endDrag(); }
392 516 }
@@ -41,7 +41,8 @@ var app = {
41 flames: Object.create(null),
41 flames: Object.create(null),
42 cells: [],
42 cells: [],
43 pointerId: null,
43 pointerId: null,
44 gameOverShown: false
44 gameOverShown: false,
45 selectTween: null
45};
46};
46
47
47window.onload = function ()
48window.onload = function ()
@@ -87,6 +88,7 @@ function startPlay ()
87 app.flames = Object.create(null);
88 app.flames = Object.create(null);
88 app.cells = [];
89 app.cells = [];
89 app.pointerId = null;
90 app.pointerId = null;
91 app.selectTween = null;
90
92
91 layout();
93 layout();
92 app.scene = new Scene(app.fieldX, app.fieldY, app.fieldW, app.fieldH);
94 app.scene = new Scene(app.fieldX, app.fieldY, app.fieldW, app.fieldH);
@@ -114,6 +116,7 @@ function returnToMenu ()
114 app.sprites = Object.create(null);
116 app.sprites = Object.create(null);
115 app.flames = Object.create(null);
117 app.flames = Object.create(null);
116 app.cells = [];
118 app.cells = [];
119 app.selectTween = null;
117
120
118 hideEl('hud');
121 hideEl('hud');
119 hideEl('game-over');
122 hideEl('game-over');
@@ -212,6 +215,7 @@ function syncSprites ()
212 }
215 }
213 obj.renderer.sprite = spriteFor(block);
216 obj.renderer.sprite = spriteFor(block);
214 placeTile(obj, block.col, block.y);
217 placeTile(obj, block.col, block.y);
218 applyBlockVisual(obj, block);
215 obj.renderer.visible = true;
219 obj.renderer.visible = true;
216 obj.renderer.alpha = 1;
220 obj.renderer.alpha = 1;
217
221
@@ -251,6 +255,96 @@ function syncSprites ()
251 }
255 }
252}
256}
253
257
258function applyBlockVisual (obj, block)
259{
260 var t = app.tile;
261 var sx = 1;
262 var sy = 1;
263 var dy = 0;
264 if (block.bouncing && app.planet && app.planet.bounceDuration > 0
265 && typeof Easing !== 'undefined' && Easing.bouncePose)
266 {
267 var u = block.bounceAge / app.planet.bounceDuration;
268 var pose = Easing.bouncePose(u, app.planet.bounceSquash);
269 sx = pose.sx;
270 sy = pose.sy;
271 dy = pose.dy;
272 }
273 var sel = 1;
274 var tw = app.selectTween;
275 if (tw && tw.blockId === block.id && tw.phase !== 'idle')
276 { sel = tw.scale; }
277 obj.transform.size = { x: t * sx * sel, y: t * sy * sel };
278 if (dy)
279 { obj.transform.position.y -= dy * t; }
280}
281
282function clickTween ()
283{
284 return (typeof Easing !== 'undefined' && Easing.CLICK_TWEEN) ? Easing.CLICK_TWEEN : null;
285}
286
287function startPressTween (blockId)
288{
289 var c = clickTween();
290 if (!c)
291 { return; }
292 var from = (app.selectTween && app.selectTween.phase !== 'idle') ? app.selectTween.scale : 1;
293 app.selectTween = {
294 blockId: blockId,
295 from: from,
296 to: c.pressScale,
297 t: 0,
298 duration: c.pressDuration,
299 ease: c.pressEase,
300 scale: from,
301 phase: 'press'
302 };
303}
304
305function startReleaseTween ()
306{
307 var c = clickTween();
308 var tw = app.selectTween;
309 if (!c || !tw || tw.phase === 'idle')
310 { return; }
311 app.selectTween = {
312 blockId: tw.blockId,
313 from: tw.scale,
314 to: c.releaseScale,
315 t: 0,
316 duration: c.releaseDuration,
317 ease: c.releaseEase,
318 scale: tw.scale,
319 phase: 'release'
320 };
321}
322
323function updateSelectTween (dt)
324{
325 var tw = app.selectTween;
326 if (!tw || tw.phase === 'idle' || tw.phase === 'hold')
327 { return; }
328 tw.t += dt;
329 var u = tw.duration > 0 ? tw.t / tw.duration : 1;
330 if (u >= 1)
331 {
332 tw.scale = tw.to;
333 tw.t = tw.duration;
334 if (tw.phase === 'press')
335 { tw.phase = 'hold'; }
336 else
337 {
338 tw.phase = 'idle';
339 tw.scale = 1;
340 tw.blockId = null;
341 }
342 return;
343 }
344 var ease = tw.ease || (typeof Easing !== 'undefined' && Easing.easeOutBack);
345 tw.scale = ease ? Easing.tween(tw.from, tw.to, u, ease) : tw.from + (tw.to - tw.from) * u;
346}
347
254function refreshHud ()
348function refreshHud ()
255{
349{
256 if (!app.core)
350 if (!app.core)
@@ -291,6 +385,7 @@ function tickView (dt)
291 }
385 }
292
386
293 app.core.tick(dt);
387 app.core.tick(dt);
388 updateSelectTween(dt);
294 syncSprites();
389 syncSprites();
295 refreshHud();
390 refreshHud();
296
391
@@ -306,31 +401,51 @@ function tickView (dt)
306}
401}
307
402
308/* ---------- pointer input (mouse + touch) --------------------------- */
403/* ---------- pointer input (mouse + touch) --------------------------- */
404/*
405 * Both mouse and touch use Pointer Events. After pointerdown we listen
406 * on window, so a drag that leaves the canvas (needed to launch a
407 * block at the top of a full column) still reaches moveDrag. We do
408 * not treat lostpointercapture as the end of a drag: on some touch
409 * browsers that fires mid-gesture and would cancel a launch.
410 */
309
411
310var boundCanvas = null;
412var boundCanvas = null;
413var windowListening = false;
414
415function addWindowPointer ()
416{
417 if (windowListening)
418 { return; }
419 window.addEventListener('pointermove', onPointerMove, true);
420 window.addEventListener('pointerup', onPointerUp, true);
421 window.addEventListener('pointercancel', onPointerUp, true);
422 windowListening = true;
423}
424
425function removeWindowPointer ()
426{
427 if (!windowListening)
428 { return; }
429 window.removeEventListener('pointermove', onPointerMove, true);
430 window.removeEventListener('pointerup', onPointerUp, true);
431 window.removeEventListener('pointercancel', onPointerUp, true);
432 windowListening = false;
433}
311
434
312function bindPointer (canvas)
435function bindPointer (canvas)
313{
436{
314 unbindPointer();
437 unbindPointer();
315 boundCanvas = canvas;
438 boundCanvas = canvas;
316 canvas.addEventListener('pointerdown', onPointerDown);
439 canvas.addEventListener('pointerdown', onPointerDown);
317 canvas.addEventListener('pointermove', onPointerMove);
318 canvas.addEventListener('pointerup', onPointerUp);
319 canvas.addEventListener('pointercancel', onPointerUp);
320 canvas.addEventListener('lostpointercapture', onPointerUp);
321 canvas.style.touchAction = 'none';
440 canvas.style.touchAction = 'none';
322 canvas.style.cursor = 'pointer';
441 canvas.style.cursor = 'pointer';
323}
442}
324
443
325function unbindPointer ()
444function unbindPointer ()
326{
445{
327 if (!boundCanvas)
446 removeWindowPointer();
328 { return; }
447 if (boundCanvas)
329 boundCanvas.removeEventListener('pointerdown', onPointerDown);
448 { boundCanvas.removeEventListener('pointerdown', onPointerDown); }
330 boundCanvas.removeEventListener('pointermove', onPointerMove);
331 boundCanvas.removeEventListener('pointerup', onPointerUp);
332 boundCanvas.removeEventListener('pointercancel', onPointerUp);
333 boundCanvas.removeEventListener('lostpointercapture', onPointerUp);
334 boundCanvas = null;
449 boundCanvas = null;
335 app.pointerId = null;
450 app.pointerId = null;
336}
451}
@@ -361,9 +476,10 @@ function onPointerDown (e)
361 try
476 try
362 { boundCanvas.setPointerCapture(e.pointerId); }
477 { boundCanvas.setPointerCapture(e.pointerId); }
363 catch (err) { /* ignore */ }
478 catch (err) { /* ignore */ }
479 addWindowPointer();
364 var pos = fieldFromEvent(e);
480 var pos = fieldFromEvent(e);
365 if (pos)
481 if (pos && app.core.beginDrag(pos.col, pos.y) && app.core.drag)
366 { app.core.beginDrag(pos.col, pos.y); }
482 { startPressTween(app.core.drag.blockId); }
367}
483}
368
484
369function onPointerMove (e)
485function onPointerMove (e)
@@ -387,6 +503,14 @@ function onPointerUp (e)
387 if (e)
503 if (e)
388 { e.preventDefault(); }
504 { e.preventDefault(); }
389 app.pointerId = null;
505 app.pointerId = null;
506 removeWindowPointer();
507 if (boundCanvas)
508 {
509 try
510 { boundCanvas.releasePointerCapture(e && e.pointerId); }
511 catch (err) { /* ignore */ }
512 }
513 startReleaseTween();
390 if (app.core)
514 if (app.core)
391 { app.core.endDrag(); }
515 { app.core.endDrag(); }
392}
516}
src/planet.js +8 −1
@@ -58,7 +58,14 @@ function createPlanet (opts)
58 58 riseTime: riseTime,
59 59 colors: colors,
60 60 baseJumpHeight: FIELD_HEIGHT / jumpsToClear,
61 fallSpeed: FIELD_HEIGHT / fallTime
61 fallSpeed: FIELD_HEIGHT / fallTime,
62 // Time to ease from vy=0 at the apex to terminal fallSpeed.
63 // Shorter when air resistance is low (small fallTime).
64 apexEaseTime: 0.15 * fallTime,
65 fallAccel: (FIELD_HEIGHT / fallTime) / (0.15 * fallTime),
66 // Visual landing bounce: faster at low air resistance. Stage-3 params.
67 bounceDuration: 0.12 * fallTime,
68 bounceSquash: 0.16
62 69 };
63 70 return planet;
64 71 }
@@ -58,7 +58,14 @@ function createPlanet (opts)
58 riseTime: riseTime,
58 riseTime: riseTime,
59 colors: colors,
59 colors: colors,
60 baseJumpHeight: FIELD_HEIGHT / jumpsToClear,
60 baseJumpHeight: FIELD_HEIGHT / jumpsToClear,
61 fallSpeed: FIELD_HEIGHT / fallTime
61 fallSpeed: FIELD_HEIGHT / fallTime,
62 // Time to ease from vy=0 at the apex to terminal fallSpeed.
63 // Shorter when air resistance is low (small fallTime).
64 apexEaseTime: 0.15 * fallTime,
65 fallAccel: (FIELD_HEIGHT / fallTime) / (0.15 * fallTime),
66 // Visual landing bounce: faster at low air resistance. Stage-3 params.
67 bounceDuration: 0.12 * fallTime,
68 bounceSquash: 0.16
62 };
69 };
63 return planet;
70 return planet;
64}
71}
test/easing.test.js added +87 −0
@@ -0,0 +1,87 @@
1 'use strict';
2
3 const { describe, it } = require('node:test');
4 const assert = require('node:assert/strict');
5 const Easing = require('../src/easing.js');
6 const Planet = require('../src/planet.js');
7
8 describe('Click-tween defaults (KWin Click Tween)', () =>
9 {
10 it('matches Tim\'s default scale, durations and Qt easing parameters', () =>
11 {
12 const c = Easing.CLICK_TWEEN;
13 assert.equal(c.pressScale, 0.8);
14 assert.equal(c.releaseScale, 1.0);
15 assert.equal(c.pressDuration, 0.150);
16 assert.equal(c.releaseDuration, 0.720);
17 assert.equal(c.backOvershoot, 1.70158);
18 assert.equal(c.elasticPeriod, 0.3);
19 assert.equal(c.elasticAmplitude, 1.0);
20 assert.equal(c.pressEase, Easing.easeOutBack);
21 assert.equal(c.releaseEase, Easing.easeOutElastic);
22 });
23
24 it('easeOutBack starts at 0, ends at 1, and overshoots past 1 mid-way', () =>
25 {
26 assert.ok(Math.abs(Easing.easeOutBack(0)) < 1e-12);
27 assert.ok(Math.abs(Easing.easeOutBack(1) - 1) < 1e-12);
28 let max = 0;
29 for (let i = 0; i <= 100; i++)
30 {
31 const v = Easing.easeOutBack(i / 100);
32 if (v > max)
33 { max = v; }
34 }
35 assert.ok(max > 1.01, 'OutBack overshoots, max=' + max);
36 // Qt / Penner default 1.70158 peaks around 1.1.
37 assert.ok(max < 1.2, 'overshoot is the Qt default, max=' + max);
38 });
39
40 it('easeOutElastic ends at 1 and oscillates around the end value', () =>
41 {
42 assert.equal(Easing.easeOutElastic(0), 0);
43 assert.equal(Easing.easeOutElastic(1), 1);
44 const mid = Easing.easeOutElastic(0.3);
45 // Decaying sine: not monotonic; some samples exceed 1.
46 let above = false;
47 let below = false;
48 for (let i = 1; i < 40; i++)
49 {
50 const v = Easing.easeOutElastic(i / 40);
51 if (v > 1.01)
52 { above = true; }
53 if (v < 0.99 && i > 10)
54 { below = true; }
55 }
56 assert.ok(above, 'elastic overshoots above 1');
57 assert.ok(below, 'elastic undershoots as it decays');
58 assert.ok(typeof mid === 'number');
59 });
60
61 it('tween from 1.0 to 0.8 with easeOutBack overshoots below 0.8 then settles', () =>
62 {
63 const c = Easing.CLICK_TWEEN;
64 assert.ok(Math.abs(Easing.tween(1, 0.8, 0, c.pressEase) - 1) < 1e-12);
65 assert.ok(Math.abs(Easing.tween(1, 0.8, 1, c.pressEase) - 0.8) < 1e-12);
66 let min = 1;
67 for (let i = 0; i <= 100; i++)
68 {
69 const v = Easing.tween(1, 0.8, i / 100, c.pressEase);
70 if (v < min)
71 { min = v; }
72 }
73 assert.ok(min < 0.8 - 0.005, 'press overshoots below 0.8, min=' + min);
74 });
75 });
76
77 describe('Planet apex-ease and bounce parameters', () =>
78 {
79 it('derives faster ease and bounce from lower fallTime (low air resistance)', () =>
80 {
81 const terra = Planet.defaultPlanet();
82 assert.ok(Math.abs(terra.apexEaseTime - 0.15 * 3) < 1e-12);
83 assert.ok(Math.abs(terra.bounceDuration - 0.12 * 3) < 1e-12);
84 assert.equal(terra.bounceSquash, 0.16);
85 assert.ok(Math.abs(terra.fallAccel - terra.fallSpeed / terra.apexEaseTime) < 1e-9);
86 });
87 });
@@ -0,0 +1,87 @@
1'use strict';
2
3const { describe, it } = require('node:test');
4const assert = require('node:assert/strict');
5const Easing = require('../src/easing.js');
6const Planet = require('../src/planet.js');
7
8describe('Click-tween defaults (KWin Click Tween)', () =>
9{
10 it('matches Tim\'s default scale, durations and Qt easing parameters', () =>
11 {
12 const c = Easing.CLICK_TWEEN;
13 assert.equal(c.pressScale, 0.8);
14 assert.equal(c.releaseScale, 1.0);
15 assert.equal(c.pressDuration, 0.150);
16 assert.equal(c.releaseDuration, 0.720);
17 assert.equal(c.backOvershoot, 1.70158);
18 assert.equal(c.elasticPeriod, 0.3);
19 assert.equal(c.elasticAmplitude, 1.0);
20 assert.equal(c.pressEase, Easing.easeOutBack);
21 assert.equal(c.releaseEase, Easing.easeOutElastic);
22 });
23
24 it('easeOutBack starts at 0, ends at 1, and overshoots past 1 mid-way', () =>
25 {
26 assert.ok(Math.abs(Easing.easeOutBack(0)) < 1e-12);
27 assert.ok(Math.abs(Easing.easeOutBack(1) - 1) < 1e-12);
28 let max = 0;
29 for (let i = 0; i <= 100; i++)
30 {
31 const v = Easing.easeOutBack(i / 100);
32 if (v > max)
33 { max = v; }
34 }
35 assert.ok(max > 1.01, 'OutBack overshoots, max=' + max);
36 // Qt / Penner default 1.70158 peaks around 1.1.
37 assert.ok(max < 1.2, 'overshoot is the Qt default, max=' + max);
38 });
39
40 it('easeOutElastic ends at 1 and oscillates around the end value', () =>
41 {
42 assert.equal(Easing.easeOutElastic(0), 0);
43 assert.equal(Easing.easeOutElastic(1), 1);
44 const mid = Easing.easeOutElastic(0.3);
45 // Decaying sine: not monotonic; some samples exceed 1.
46 let above = false;
47 let below = false;
48 for (let i = 1; i < 40; i++)
49 {
50 const v = Easing.easeOutElastic(i / 40);
51 if (v > 1.01)
52 { above = true; }
53 if (v < 0.99 && i > 10)
54 { below = true; }
55 }
56 assert.ok(above, 'elastic overshoots above 1');
57 assert.ok(below, 'elastic undershoots as it decays');
58 assert.ok(typeof mid === 'number');
59 });
60
61 it('tween from 1.0 to 0.8 with easeOutBack overshoots below 0.8 then settles', () =>
62 {
63 const c = Easing.CLICK_TWEEN;
64 assert.ok(Math.abs(Easing.tween(1, 0.8, 0, c.pressEase) - 1) < 1e-12);
65 assert.ok(Math.abs(Easing.tween(1, 0.8, 1, c.pressEase) - 0.8) < 1e-12);
66 let min = 1;
67 for (let i = 0; i <= 100; i++)
68 {
69 const v = Easing.tween(1, 0.8, i / 100, c.pressEase);
70 if (v < min)
71 { min = v; }
72 }
73 assert.ok(min < 0.8 - 0.005, 'press overshoots below 0.8, min=' + min);
74 });
75});
76
77describe('Planet apex-ease and bounce parameters', () =>
78{
79 it('derives faster ease and bounce from lower fallTime (low air resistance)', () =>
80 {
81 const terra = Planet.defaultPlanet();
82 assert.ok(Math.abs(terra.apexEaseTime - 0.15 * 3) < 1e-12);
83 assert.ok(Math.abs(terra.bounceDuration - 0.12 * 3) < 1e-12);
84 assert.equal(terra.bounceSquash, 0.16);
85 assert.ok(Math.abs(terra.fallAccel - terra.fallSpeed / terra.apexEaseTime) < 1e-9);
86 });
87});
test/falling-cluster.test.js added +235 −0
@@ -0,0 +1,235 @@
1 'use strict';
2
3 const { describe, it } = require('node:test');
4 const assert = require('node:assert/strict');
5 const { makeGame, placeRow, almost, GameCore, Planet } = require('./helpers.js');
6
7 function flyingGrayRow (game, y, cols)
8 {
9 const cluster = {
10 id: game.nextClusterId++,
11 jumpHeight: 3,
12 vy: -game.planet.fallSpeed,
13 decel: 0,
14 phase: 'down'
15 };
16 game.clusters[cluster.id] = cluster;
17 const members = [];
18 for (const col of cols)
19 {
20 const b = game.createBlock(col, y, GameCore.COLOR_GRAY, 'flying');
21 b.clusterId = cluster.id;
22 b.vy = cluster.vy;
23 b.flame = true;
24 members.push(b);
25 }
26 return { cluster, members };
27 }
28
29 describe('Falling blocks land on flying clusters', () =>
30 {
31 it('a falling spawn lands on a flying cluster and flies along as cargo', () =>
32 {
33 const g = makeGame({ noSpawn: true, planetOpts: { jumpsToClear: 2, fallTime: 3, riseTime: 1.5 } });
34 const { cluster, members } = flyingGrayRow(g, 6, [2, 3, 4]);
35 // Freeze ascent/descent so the falling block can meet them cleanly,
36 // then unfreeze so they move together.
37 cluster.phase = 'hold';
38 cluster.vy = 0;
39 const falling = g.createBlock(3, 10, 1, 'falling');
40 falling.vy = -g.planet.fallSpeed;
41 // Fall from 10 onto 6+1=7: distance 3, at fallSpeed 13/3 ≈ 4.33 → ~0.7s
42 g.step(1.0, 1 / 120);
43 assert.equal(falling.state, 'flying', 'should have attached, state=' + falling.state + ' y=' + falling.y);
44 assert.equal(falling.clusterId, cluster.id);
45 assert.equal(falling.flame, false, 'cargo has no flame');
46 assert.equal(falling.color, 1, 'keeps its color');
47 assert.ok(almost(falling.y, members[1].y + 1, 0.05), 'sits on top, y=' + falling.y + ' flyer=' + members[1].y);
48
49 // Now let the cluster descend: cargo must move with it, same dy.
50 cluster.phase = 'down';
51 cluster.vy = 0; // will ease into fallSpeed
52 const yCargo = falling.y;
53 const yFlyer = members[1].y;
54 g.step(0.4, 1 / 120);
55 assert.equal(falling.clusterId, cluster.id);
56 assert.equal(falling.state, 'flying');
57 assert.ok(almost(falling.y - members[1].y, yCargo - yFlyer, 0.05),
58 'relative offset kept: cargo=' + falling.y + ' flyer=' + members[1].y);
59 assert.ok(falling.y < yCargo, 'must have moved down with the cluster');
60 assert.ok(almost(falling.vy, members[1].vy, 1e-9), 'same vy');
61 });
62
63 it('a falling block does not pass through a descending or rising cluster', () =>
64 {
65 const g = makeGame({ noSpawn: true });
66 const { cluster } = flyingGrayRow(g, 5, [1]);
67 cluster.phase = 'down';
68 cluster.vy = -g.planet.fallSpeed;
69 const falling = g.createBlock(1, 8, 2, 'falling');
70 falling.vy = -g.planet.fallSpeed;
71 g.step(2.0, 1 / 120);
72 assert.notEqual(falling.state, 'falling');
73 assert.ok(falling.state === 'flying' || falling.state === 'settling' || falling.state === 'still',
74 'must not still be falling through, state=' + falling.state + ' y=' + falling.y);
75 // Never went below the flyer without joining (flyer may have landed).
76 const flyer = g.blocks.find((b) => b.color === GameCore.COLOR_GRAY);
77 if (falling.state === 'flying' && flyer)
78 { assert.ok(falling.y >= flyer.y - 1e-6, 'cargo not below its flyer'); }
79 });
80
81 it('a rising cluster that meets a falling block picks it up', () =>
82 {
83 const g = makeGame({ noSpawn: true });
84 const { cluster, members } = flyingGrayRow(g, 3, [5]);
85 cluster.phase = 'up';
86 cluster.jumpHeight = 6;
87 cluster.vy = Planet.launchVelocity(g.planet, 6);
88 cluster.decel = Planet.launchDeceleration(g.planet, 6);
89 members[0].vy = cluster.vy;
90 const falling = g.createBlock(5, 7, 3, 'falling');
91 falling.vy = -g.planet.fallSpeed;
92 g.step(0.8, 1 / 120);
93 assert.equal(falling.state, 'flying', 'picked up, state=' + falling.state + ' y=' + falling.y);
94 assert.equal(falling.clusterId, cluster.id);
95 assert.ok(falling.y >= members[0].y, 'sits at or above the flyer, cargo=' + falling.y + ' flyer=' + members[0].y);
96 });
97 });
98
99 describe('Rigid grey landing', () =>
100 {
101 it('keeps relative positions, so part of the group can hang above a gap', () =>
102 {
103 const g = makeGame({ noSpawn: true, planetOpts: { jumpsToClear: 4, fallTime: 2, riseTime: 0.5 } });
104 // Horizontal match on a pedestal in col 1 only: cols 0 and 2 will hang.
105 g.place(1, 0, 4); // pedestal
106 placeRow(g, 1, [0, 1, 2], 0);
107 g.resolveMatches();
108 assert.ok(g.blocks.some((b) => b.state === 'flying'));
109 let landed = false;
110 for (let i = 0; i < 3000; i++)
111 {
112 g.tick(1 / 120);
113 const greys = g.blocks.filter((b) => b.color === GameCore.COLOR_GRAY);
114 if (greys.length >= 3 && greys.every((b) => b.state === 'settling'))
115 {
116 landed = true;
117 break;
118 }
119 }
120 assert.ok(landed, 'should have landed rigid\n' + g.snapshot().picture);
121 const at = (col) => g.blocks.find((b) => b.col === col && b.color === GameCore.COLOR_GRAY);
122 const a = at(0);
123 const b = at(1);
124 const c = at(2);
125 assert.ok(a && b && c, 'all three greys present');
126 // The middle one rests on the pedestal (y=1). The sides hang at the same y.
127 assert.ok(almost(b.y, 1, 0.05), 'middle sits on pedestal, y=' + b.y);
128 assert.ok(almost(a.y, b.y, 0.05), 'left hangs at the same height, y=' + a.y);
129 assert.ok(almost(c.y, b.y, 0.05), 'right hangs at the same height, y=' + c.y);
130 assert.equal(g.blockAt(0, 0), null, 'gap under the left hang remains');
131 assert.equal(g.blockAt(2, 0), null, 'gap under the right hang remains');
132 // They stay there through the settle wait.
133 g.step(2.9, 1 / 60);
134 assert.ok(almost(a.y, 1, 0.05) && a.state === 'settling');
135 });
136
137 it('after conversion, hanging blocks fall individually and supported ones stay', () =>
138 {
139 const g = makeGame({
140 noSpawn: true,
141 planetOpts: { jumpsToClear: 4, fallTime: 2, riseTime: 0.5 },
142 seed: 7
143 });
144 g.place(1, 0, 4);
145 placeRow(g, 1, [0, 1, 2], 0);
146 g.resolveMatches();
147 for (let i = 0; i < 3000; i++)
148 {
149 g.tick(1 / 120);
150 const greys = g.blocks.filter((b) => b.color === GameCore.COLOR_GRAY);
151 if (greys.length >= 3 && greys.every((b) => b.state === 'settling'))
152 { break; }
153 }
154 const left = g.blocks.find((b) => b.col === 0 && b.color === GameCore.COLOR_GRAY);
155 const mid = g.blocks.find((b) => b.col === 1 && b.color === GameCore.COLOR_GRAY);
156 const right = g.blocks.find((b) => b.col === 2 && b.color === GameCore.COLOR_GRAY);
157 const leftY = left.y;
158 g.step(3.0, 1 / 120);
159 // Conversion happens at 3s; take a short step so the fall is visible
160 // but not finished (from rest, Terra-like ease is not instant).
161 g.step(0.25, 1 / 120);
162 assert.ok(mid.color >= 0 && mid.state === 'still', 'supported middle stays, state=' + mid.state);
163 assert.ok(almost(mid.y, 1, 0.05), 'middle stays on the pedestal, y=' + mid.y);
164 assert.equal(mid.clusterId, null);
165 // Hanging sides fall from rest — they must not teleport to the floor.
166 assert.equal(left.state, 'falling', 'left should still be falling after 0.25s, state=' + left.state + ' y=' + left.y);
167 assert.ok(left.y < leftY - 0.05, 'left has started falling smoothly, y=' + left.y + ' from ' + leftY);
168 assert.ok(left.y > 0.25, 'must not have teleported to the floor, y=' + left.y);
169 assert.ok(Math.abs(left.vy) <= g.planet.fallSpeed + 1e-6);
170 assert.ok(right.state === 'falling' || (right.state === 'still' && almost(right.y, 0, 0.05)),
171 'right falls, state=' + right.state);
172 // Give them time to land individually.
173 g.step(g.planet.fallTime + 0.5, 1 / 60);
174 assert.equal(left.state, 'still');
175 assert.ok(almost(left.y, 0, 0.05), 'left lands on the floor, y=' + left.y);
176 assert.equal(right.state, 'still');
177 assert.ok(almost(right.y, 0, 0.05));
178 });
179 });
180
181 describe('Landing bounce planet parameter', () =>
182 {
183 it('sets bouncing on a landed block, faster at low air resistance', () =>
184 {
185 const slow = Planet.createPlanet({ fallTime: 5, jumpsToClear: 2, riseTime: 1.5 });
186 const fast = Planet.createPlanet({ fallTime: 1, jumpsToClear: 2, riseTime: 1.5 });
187 assert.ok(fast.bounceDuration < slow.bounceDuration,
188 'low air (fallTime=1) must bounce faster: ' + fast.bounceDuration + ' vs ' + slow.bounceDuration);
189 assert.ok(almost(fast.bounceDuration, 0.12 * 1, 1e-9));
190 assert.ok(almost(slow.bounceDuration, 0.12 * 5, 1e-9));
191 assert.equal(fast.bounceSquash, 0.16);
192 assert.ok(fast.apexEaseTime < slow.apexEaseTime);
193 assert.ok(fast.fallAccel > slow.fallAccel, 'low air eases into fall faster');
194
195 const g = makeGame({ noSpawn: true, planetOpts: { fallTime: 3 } });
196 const block = g.createBlock(0, 5, 1, 'falling');
197 block.vy = -g.planet.fallSpeed;
198 let landed = false;
199 for (let i = 0; i < 2000; i++)
200 {
201 g.tick(1 / 120);
202 if (block.state === 'still')
203 {
204 landed = true;
205 break;
206 }
207 }
208 assert.ok(landed, 'should have landed');
209 assert.ok(almost(block.y, 0, 0.05));
210 assert.equal(block.bouncing, true);
211 assert.ok(block.bounceAge >= 0 && block.bounceAge < g.planet.bounceDuration,
212 'bounce just started, age=' + block.bounceAge);
213 g.step(g.planet.bounceDuration + 0.05, 1 / 60);
214 assert.equal(block.bouncing, false);
215 });
216
217 it('a rigid cluster bounce only on members that actually rest on something', () =>
218 {
219 const g = makeGame({ noSpawn: true, planetOpts: { jumpsToClear: 4, fallTime: 2, riseTime: 0.5 } });
220 g.place(1, 0, 4);
221 placeRow(g, 1, [0, 1, 2], 0);
222 g.resolveMatches();
223 for (let i = 0; i < 3000; i++)
224 {
225 g.tick(1 / 120);
226 const greys = g.blocks.filter((b) => b.color === GameCore.COLOR_GRAY);
227 if (greys.length >= 3 && greys.every((b) => b.state === 'settling'))
228 { break; }
229 }
230 const left = g.blocks.find((b) => b.col === 0 && b.color === GameCore.COLOR_GRAY);
231 const mid = g.blocks.find((b) => b.col === 1 && b.color === GameCore.COLOR_GRAY);
232 assert.equal(mid.bouncing, true, 'the member on the pedestal bounces');
233 assert.equal(left.bouncing, false, 'the hanging member does not bounce');
234 });
235 });
@@ -0,0 +1,235 @@
1'use strict';
2
3const { describe, it } = require('node:test');
4const assert = require('node:assert/strict');
5const { makeGame, placeRow, almost, GameCore, Planet } = require('./helpers.js');
6
7function flyingGrayRow (game, y, cols)
8{
9 const cluster = {
10 id: game.nextClusterId++,
11 jumpHeight: 3,
12 vy: -game.planet.fallSpeed,
13 decel: 0,
14 phase: 'down'
15 };
16 game.clusters[cluster.id] = cluster;
17 const members = [];
18 for (const col of cols)
19 {
20 const b = game.createBlock(col, y, GameCore.COLOR_GRAY, 'flying');
21 b.clusterId = cluster.id;
22 b.vy = cluster.vy;
23 b.flame = true;
24 members.push(b);
25 }
26 return { cluster, members };
27}
28
29describe('Falling blocks land on flying clusters', () =>
30{
31 it('a falling spawn lands on a flying cluster and flies along as cargo', () =>
32 {
33 const g = makeGame({ noSpawn: true, planetOpts: { jumpsToClear: 2, fallTime: 3, riseTime: 1.5 } });
34 const { cluster, members } = flyingGrayRow(g, 6, [2, 3, 4]);
35 // Freeze ascent/descent so the falling block can meet them cleanly,
36 // then unfreeze so they move together.
37 cluster.phase = 'hold';
38 cluster.vy = 0;
39 const falling = g.createBlock(3, 10, 1, 'falling');
40 falling.vy = -g.planet.fallSpeed;
41 // Fall from 10 onto 6+1=7: distance 3, at fallSpeed 13/3 ≈ 4.33 → ~0.7s
42 g.step(1.0, 1 / 120);
43 assert.equal(falling.state, 'flying', 'should have attached, state=' + falling.state + ' y=' + falling.y);
44 assert.equal(falling.clusterId, cluster.id);
45 assert.equal(falling.flame, false, 'cargo has no flame');
46 assert.equal(falling.color, 1, 'keeps its color');
47 assert.ok(almost(falling.y, members[1].y + 1, 0.05), 'sits on top, y=' + falling.y + ' flyer=' + members[1].y);
48
49 // Now let the cluster descend: cargo must move with it, same dy.
50 cluster.phase = 'down';
51 cluster.vy = 0; // will ease into fallSpeed
52 const yCargo = falling.y;
53 const yFlyer = members[1].y;
54 g.step(0.4, 1 / 120);
55 assert.equal(falling.clusterId, cluster.id);
56 assert.equal(falling.state, 'flying');
57 assert.ok(almost(falling.y - members[1].y, yCargo - yFlyer, 0.05),
58 'relative offset kept: cargo=' + falling.y + ' flyer=' + members[1].y);
59 assert.ok(falling.y < yCargo, 'must have moved down with the cluster');
60 assert.ok(almost(falling.vy, members[1].vy, 1e-9), 'same vy');
61 });
62
63 it('a falling block does not pass through a descending or rising cluster', () =>
64 {
65 const g = makeGame({ noSpawn: true });
66 const { cluster } = flyingGrayRow(g, 5, [1]);
67 cluster.phase = 'down';
68 cluster.vy = -g.planet.fallSpeed;
69 const falling = g.createBlock(1, 8, 2, 'falling');
70 falling.vy = -g.planet.fallSpeed;
71 g.step(2.0, 1 / 120);
72 assert.notEqual(falling.state, 'falling');
73 assert.ok(falling.state === 'flying' || falling.state === 'settling' || falling.state === 'still',
74 'must not still be falling through, state=' + falling.state + ' y=' + falling.y);
75 // Never went below the flyer without joining (flyer may have landed).
76 const flyer = g.blocks.find((b) => b.color === GameCore.COLOR_GRAY);
77 if (falling.state === 'flying' && flyer)
78 { assert.ok(falling.y >= flyer.y - 1e-6, 'cargo not below its flyer'); }
79 });
80
81 it('a rising cluster that meets a falling block picks it up', () =>
82 {
83 const g = makeGame({ noSpawn: true });
84 const { cluster, members } = flyingGrayRow(g, 3, [5]);
85 cluster.phase = 'up';
86 cluster.jumpHeight = 6;
87 cluster.vy = Planet.launchVelocity(g.planet, 6);
88 cluster.decel = Planet.launchDeceleration(g.planet, 6);
89 members[0].vy = cluster.vy;
90 const falling = g.createBlock(5, 7, 3, 'falling');
91 falling.vy = -g.planet.fallSpeed;
92 g.step(0.8, 1 / 120);
93 assert.equal(falling.state, 'flying', 'picked up, state=' + falling.state + ' y=' + falling.y);
94 assert.equal(falling.clusterId, cluster.id);
95 assert.ok(falling.y >= members[0].y, 'sits at or above the flyer, cargo=' + falling.y + ' flyer=' + members[0].y);
96 });
97});
98
99describe('Rigid grey landing', () =>
100{
101 it('keeps relative positions, so part of the group can hang above a gap', () =>
102 {
103 const g = makeGame({ noSpawn: true, planetOpts: { jumpsToClear: 4, fallTime: 2, riseTime: 0.5 } });
104 // Horizontal match on a pedestal in col 1 only: cols 0 and 2 will hang.
105 g.place(1, 0, 4); // pedestal
106 placeRow(g, 1, [0, 1, 2], 0);
107 g.resolveMatches();
108 assert.ok(g.blocks.some((b) => b.state === 'flying'));
109 let landed = false;
110 for (let i = 0; i < 3000; i++)
111 {
112 g.tick(1 / 120);
113 const greys = g.blocks.filter((b) => b.color === GameCore.COLOR_GRAY);
114 if (greys.length >= 3 && greys.every((b) => b.state === 'settling'))
115 {
116 landed = true;
117 break;
118 }
119 }
120 assert.ok(landed, 'should have landed rigid\n' + g.snapshot().picture);
121 const at = (col) => g.blocks.find((b) => b.col === col && b.color === GameCore.COLOR_GRAY);
122 const a = at(0);
123 const b = at(1);
124 const c = at(2);
125 assert.ok(a && b && c, 'all three greys present');
126 // The middle one rests on the pedestal (y=1). The sides hang at the same y.
127 assert.ok(almost(b.y, 1, 0.05), 'middle sits on pedestal, y=' + b.y);
128 assert.ok(almost(a.y, b.y, 0.05), 'left hangs at the same height, y=' + a.y);
129 assert.ok(almost(c.y, b.y, 0.05), 'right hangs at the same height, y=' + c.y);
130 assert.equal(g.blockAt(0, 0), null, 'gap under the left hang remains');
131 assert.equal(g.blockAt(2, 0), null, 'gap under the right hang remains');
132 // They stay there through the settle wait.
133 g.step(2.9, 1 / 60);
134 assert.ok(almost(a.y, 1, 0.05) && a.state === 'settling');
135 });
136
137 it('after conversion, hanging blocks fall individually and supported ones stay', () =>
138 {
139 const g = makeGame({
140 noSpawn: true,
141 planetOpts: { jumpsToClear: 4, fallTime: 2, riseTime: 0.5 },
142 seed: 7
143 });
144 g.place(1, 0, 4);
145 placeRow(g, 1, [0, 1, 2], 0);
146 g.resolveMatches();
147 for (let i = 0; i < 3000; i++)
148 {
149 g.tick(1 / 120);
150 const greys = g.blocks.filter((b) => b.color === GameCore.COLOR_GRAY);
151 if (greys.length >= 3 && greys.every((b) => b.state === 'settling'))
152 { break; }
153 }
154 const left = g.blocks.find((b) => b.col === 0 && b.color === GameCore.COLOR_GRAY);
155 const mid = g.blocks.find((b) => b.col === 1 && b.color === GameCore.COLOR_GRAY);
156 const right = g.blocks.find((b) => b.col === 2 && b.color === GameCore.COLOR_GRAY);
157 const leftY = left.y;
158 g.step(3.0, 1 / 120);
159 // Conversion happens at 3s; take a short step so the fall is visible
160 // but not finished (from rest, Terra-like ease is not instant).
161 g.step(0.25, 1 / 120);
162 assert.ok(mid.color >= 0 && mid.state === 'still', 'supported middle stays, state=' + mid.state);
163 assert.ok(almost(mid.y, 1, 0.05), 'middle stays on the pedestal, y=' + mid.y);
164 assert.equal(mid.clusterId, null);
165 // Hanging sides fall from rest — they must not teleport to the floor.
166 assert.equal(left.state, 'falling', 'left should still be falling after 0.25s, state=' + left.state + ' y=' + left.y);
167 assert.ok(left.y < leftY - 0.05, 'left has started falling smoothly, y=' + left.y + ' from ' + leftY);
168 assert.ok(left.y > 0.25, 'must not have teleported to the floor, y=' + left.y);
169 assert.ok(Math.abs(left.vy) <= g.planet.fallSpeed + 1e-6);
170 assert.ok(right.state === 'falling' || (right.state === 'still' && almost(right.y, 0, 0.05)),
171 'right falls, state=' + right.state);
172 // Give them time to land individually.
173 g.step(g.planet.fallTime + 0.5, 1 / 60);
174 assert.equal(left.state, 'still');
175 assert.ok(almost(left.y, 0, 0.05), 'left lands on the floor, y=' + left.y);
176 assert.equal(right.state, 'still');
177 assert.ok(almost(right.y, 0, 0.05));
178 });
179});
180
181describe('Landing bounce planet parameter', () =>
182{
183 it('sets bouncing on a landed block, faster at low air resistance', () =>
184 {
185 const slow = Planet.createPlanet({ fallTime: 5, jumpsToClear: 2, riseTime: 1.5 });
186 const fast = Planet.createPlanet({ fallTime: 1, jumpsToClear: 2, riseTime: 1.5 });
187 assert.ok(fast.bounceDuration < slow.bounceDuration,
188 'low air (fallTime=1) must bounce faster: ' + fast.bounceDuration + ' vs ' + slow.bounceDuration);
189 assert.ok(almost(fast.bounceDuration, 0.12 * 1, 1e-9));
190 assert.ok(almost(slow.bounceDuration, 0.12 * 5, 1e-9));
191 assert.equal(fast.bounceSquash, 0.16);
192 assert.ok(fast.apexEaseTime < slow.apexEaseTime);
193 assert.ok(fast.fallAccel > slow.fallAccel, 'low air eases into fall faster');
194
195 const g = makeGame({ noSpawn: true, planetOpts: { fallTime: 3 } });
196 const block = g.createBlock(0, 5, 1, 'falling');
197 block.vy = -g.planet.fallSpeed;
198 let landed = false;
199 for (let i = 0; i < 2000; i++)
200 {
201 g.tick(1 / 120);
202 if (block.state === 'still')
203 {
204 landed = true;
205 break;
206 }
207 }
208 assert.ok(landed, 'should have landed');
209 assert.ok(almost(block.y, 0, 0.05));
210 assert.equal(block.bouncing, true);
211 assert.ok(block.bounceAge >= 0 && block.bounceAge < g.planet.bounceDuration,
212 'bounce just started, age=' + block.bounceAge);
213 g.step(g.planet.bounceDuration + 0.05, 1 / 60);
214 assert.equal(block.bouncing, false);
215 });
216
217 it('a rigid cluster bounce only on members that actually rest on something', () =>
218 {
219 const g = makeGame({ noSpawn: true, planetOpts: { jumpsToClear: 4, fallTime: 2, riseTime: 0.5 } });
220 g.place(1, 0, 4);
221 placeRow(g, 1, [0, 1, 2], 0);
222 g.resolveMatches();
223 for (let i = 0; i < 3000; i++)
224 {
225 g.tick(1 / 120);
226 const greys = g.blocks.filter((b) => b.color === GameCore.COLOR_GRAY);
227 if (greys.length >= 3 && greys.every((b) => b.state === 'settling'))
228 { break; }
229 }
230 const left = g.blocks.find((b) => b.col === 0 && b.color === GameCore.COLOR_GRAY);
231 const mid = g.blocks.find((b) => b.col === 1 && b.color === GameCore.COLOR_GRAY);
232 assert.equal(mid.bouncing, true, 'the member on the pedestal bounces');
233 assert.equal(left.bouncing, false, 'the hanging member does not bounce');
234 });
235});
test/match.test.js +13 −2
@@ -146,7 +146,7 @@ describe('Match detection and launch', () =>
146 146
147 147 describe('Launch physics', () =>
148 148 {
149 it('reaches the jump height in riseTime, then floats down at constant speed', () =>
149 it('reaches the jump height in riseTime, then eases into a constant descent', () =>
150 150 {
151 151 const g = makeGame({ noSpawn: true });
152 152 placeRow(g, 0, [0, 1, 2], 0);
@@ -157,7 +157,18 @@ describe('Launch physics', () =>
157 157 g.step(T, 1 / 240);
158 158 const apex = g.blocks[0].y;
159 159 assert.ok(Math.abs(apex - (startY + H)) < 0.08, 'apex y=' + apex + ' expected ' + (startY + H));
160 assert.equal(g.clusters[g.blocks[0].clusterId].phase, 'down');
160 const cluster = g.clusters[g.blocks[0].clusterId];
161 assert.equal(cluster.phase, 'down');
162 // Just after the apex, speed is still below terminal fallSpeed.
163 const ease = g.planet.apexEaseTime;
164 assert.ok(ease > 0.1, 'apexEaseTime=' + ease);
165 g.step(ease * 0.4, 1 / 240);
166 const midVy = Math.abs(g.blocks[0].vy);
167 assert.ok(midVy > 0.2, 'should have started descending, vy=' + g.blocks[0].vy);
168 assert.ok(midVy < g.planet.fallSpeed - 0.3, 'should still be easing, vy=' + g.blocks[0].vy + ' fall=' + g.planet.fallSpeed);
169 // After the ease, descent is at constant fallSpeed.
170 g.step(ease * 0.6 + 0.05, 1 / 240);
171 assert.ok(Math.abs(Math.abs(g.blocks[0].vy) - g.planet.fallSpeed) < 0.08, 'terminal vy=' + g.blocks[0].vy);
161 172 const y1 = g.blocks[0].y;
162 173 g.step(0.2, 1 / 120);
163 174 const y2 = g.blocks[0].y;
@@ -146,7 +146,7 @@ describe('Match detection and launch', () =>
146
146
147describe('Launch physics', () =>
147describe('Launch physics', () =>
148{
148{
149 it('reaches the jump height in riseTime, then floats down at constant speed', () =>
149 it('reaches the jump height in riseTime, then eases into a constant descent', () =>
150 {
150 {
151 const g = makeGame({ noSpawn: true });
151 const g = makeGame({ noSpawn: true });
152 placeRow(g, 0, [0, 1, 2], 0);
152 placeRow(g, 0, [0, 1, 2], 0);
@@ -157,7 +157,18 @@ describe('Launch physics', () =>
157 g.step(T, 1 / 240);
157 g.step(T, 1 / 240);
158 const apex = g.blocks[0].y;
158 const apex = g.blocks[0].y;
159 assert.ok(Math.abs(apex - (startY + H)) < 0.08, 'apex y=' + apex + ' expected ' + (startY + H));
159 assert.ok(Math.abs(apex - (startY + H)) < 0.08, 'apex y=' + apex + ' expected ' + (startY + H));
160 assert.equal(g.clusters[g.blocks[0].clusterId].phase, 'down');
160 const cluster = g.clusters[g.blocks[0].clusterId];
161 assert.equal(cluster.phase, 'down');
162 // Just after the apex, speed is still below terminal fallSpeed.
163 const ease = g.planet.apexEaseTime;
164 assert.ok(ease > 0.1, 'apexEaseTime=' + ease);
165 g.step(ease * 0.4, 1 / 240);
166 const midVy = Math.abs(g.blocks[0].vy);
167 assert.ok(midVy > 0.2, 'should have started descending, vy=' + g.blocks[0].vy);
168 assert.ok(midVy < g.planet.fallSpeed - 0.3, 'should still be easing, vy=' + g.blocks[0].vy + ' fall=' + g.planet.fallSpeed);
169 // After the ease, descent is at constant fallSpeed.
170 g.step(ease * 0.6 + 0.05, 1 / 240);
171 assert.ok(Math.abs(Math.abs(g.blocks[0].vy) - g.planet.fallSpeed) < 0.08, 'terminal vy=' + g.blocks[0].vy);
161 const y1 = g.blocks[0].y;
172 const y1 = g.blocks[0].y;
162 g.step(0.2, 1 / 120);
173 g.step(0.2, 1 / 120);
163 const y2 = g.blocks[0].y;
174 const y2 = g.blocks[0].y;
test/points.test.js +21 −2
@@ -63,7 +63,7 @@ describe('Points, landing and recolor', () =>
63 63 }
64 64 });
65 65
66 it('carried colored blocks land as still blocks and do not wait 3 seconds', () =>
66 it('carried colored blocks keep their color and stay in the rigid group until greys convert', () =>
67 67 {
68 68 const g = makeGame({
69 69 noSpawn: true,
@@ -72,10 +72,29 @@ describe('Points, landing and recolor', () =>
72 72 placeRow(g, 0, [0, 1, 2], 0);
73 73 const carried = g.place(1, 1, 4);
74 74 g.resolveMatches();
75 g.step(4, 1 / 120);
75 // Land (jump is short) then sit mid-settle.
76 let landed = false;
77 for (let i = 0; i < 2000; i++)
78 {
79 g.tick(1 / 120);
80 if (carried.state === 'settling' && g.clusters[carried.clusterId]
81 && g.clusters[carried.clusterId].phase === 'landed')
82 {
83 landed = true;
84 break;
85 }
86 }
87 assert.ok(landed, 'cargo should land with the rigid group, state=' + carried.state);
88 assert.equal(carried.color, 4, 'cargo does not recolor');
89 assert.ok(carried.clusterId != null, 'cargo stays in the group');
90 g.step(2.9, 1 / 60);
91 assert.equal(carried.color, 4);
92 assert.equal(carried.state, 'settling');
93 g.step(0.2, 1 / 60);
76 94 assert.equal(carried.color, 4);
77 95 assert.equal(carried.state, 'still');
78 96 assert.equal(carried.clusterId, null);
97 assert.equal(carried.y, 1);
79 98 });
80 99
81 100 it('spawn drops a random color into a random open column every second', () =>
@@ -63,7 +63,7 @@ describe('Points, landing and recolor', () =>
63 }
63 }
64 });
64 });
65
65
66 it('carried colored blocks land as still blocks and do not wait 3 seconds', () =>
66 it('carried colored blocks keep their color and stay in the rigid group until greys convert', () =>
67 {
67 {
68 const g = makeGame({
68 const g = makeGame({
69 noSpawn: true,
69 noSpawn: true,
@@ -72,10 +72,29 @@ describe('Points, landing and recolor', () =>
72 placeRow(g, 0, [0, 1, 2], 0);
72 placeRow(g, 0, [0, 1, 2], 0);
73 const carried = g.place(1, 1, 4);
73 const carried = g.place(1, 1, 4);
74 g.resolveMatches();
74 g.resolveMatches();
75 g.step(4, 1 / 120);
75 // Land (jump is short) then sit mid-settle.
76 let landed = false;
77 for (let i = 0; i < 2000; i++)
78 {
79 g.tick(1 / 120);
80 if (carried.state === 'settling' && g.clusters[carried.clusterId]
81 && g.clusters[carried.clusterId].phase === 'landed')
82 {
83 landed = true;
84 break;
85 }
86 }
87 assert.ok(landed, 'cargo should land with the rigid group, state=' + carried.state);
88 assert.equal(carried.color, 4, 'cargo does not recolor');
89 assert.ok(carried.clusterId != null, 'cargo stays in the group');
90 g.step(2.9, 1 / 60);
91 assert.equal(carried.color, 4);
92 assert.equal(carried.state, 'settling');
93 g.step(0.2, 1 / 60);
76 assert.equal(carried.color, 4);
94 assert.equal(carried.color, 4);
77 assert.equal(carried.state, 'still');
95 assert.equal(carried.state, 'still');
78 assert.equal(carried.clusterId, null);
96 assert.equal(carried.clusterId, null);
97 assert.equal(carried.y, 1);
79 });
98 });
80
99
81 it('spawn drops a random color into a random open column every second', () =>
100 it('spawn drops a random color into a random open column every second', () =>
test/swap.test.js +68 −0
@@ -117,3 +117,71 @@ describe('Vertical swapping', () =>
117 117 g.endDrag();
118 118 });
119 119 });
120
121 describe('Manual launch of the already-topmost block', () =>
122 {
123 it('dragging the top block upward past its own position starts a manual jump', () =>
124 {
125 const g = makeGame({ noSpawn: true });
126 // A single block is already the topmost (and only) block of its column.
127 const block = g.place(0, 0, 2);
128 // Grab at the visual centre (y=0.5), then pull just past its position —
129 // well short of the old "empty space above the cell" threshold (1.25).
130 assert.ok(g.beginDrag(0, 0.5));
131 assert.equal(g.drag.startedAsTop, true);
132 g.moveDrag(0.5 + 0.4);
133 assert.ok(0.9 < 0 + 1 + 0.25, 'this pull would have failed the old threshold');
134 assert.equal(g.drag.launchIntent, true, 'pull of 0.4 tiles past the press point must launch');
135 g.endDrag();
136 assert.equal(block.state, 'manual');
137 assert.equal(block.manualPhase, 'up');
138 assert.ok(block.vy > 0);
139 g.step(g.planet.riseTime, 1 / 240);
140 assert.ok(Math.abs(block.y - (g.height - 1)) < 0.08, 'jumps to just under the top, y=' + block.y);
141 assert.ok(block.y <= g.height - 1 + 1e-9);
142 });
143
144 it('a short upward twitch below LAUNCH_PULL does not launch', () =>
145 {
146 const g = makeGame({ noSpawn: true });
147 const block = g.place(3, 0, 1);
148 assert.ok(g.beginDrag(3, 0.5));
149 g.moveDrag(0.5 + 0.2);
150 assert.ok(0.2 < g.constructor.LAUNCH_PULL || 0.2 < 0.35);
151 assert.equal(g.drag.launchIntent, false);
152 g.endDrag();
153 assert.equal(block.state, 'still');
154 assert.equal(block.y, 0);
155 });
156
157 it('dragging a mid-stack block up to the top still swaps instead of launching', () =>
158 {
159 const g = makeGame({ noSpawn: true });
160 const bottom = g.place(1, 0, 0);
161 g.place(1, 1, 1);
162 g.place(1, 2, 2);
163 assert.ok(g.beginDrag(1, 0.3));
164 assert.equal(g.drag.startedAsTop, false);
165 // Pointer is past the top cell centre but not into the empty space.
166 g.moveDrag(2.4);
167 assert.equal(bottom.y, 2, 'swapped to the top');
168 assert.equal(g.drag.launchIntent, false, 'must not launch a mid-stack rearrange');
169 g.endDrag();
170 assert.equal(bottom.state, 'still');
171 assert.equal(bottom.y, 2);
172 });
173
174 it('after a mid-stack block becomes the top, a further pull into empty space still launches', () =>
175 {
176 const g = makeGame({ noSpawn: true });
177 const bottom = g.place(2, 0, 4);
178 g.place(2, 1, 3);
179 assert.ok(g.beginDrag(2, 0.2));
180 assert.equal(g.drag.startedAsTop, false);
181 g.moveDrag(1 + 1 + 0.4);
182 assert.equal(bottom.y, 1);
183 assert.equal(g.drag.launchIntent, true);
184 g.endDrag();
185 assert.equal(bottom.state, 'manual');
186 });
187 });
@@ -117,3 +117,71 @@ describe('Vertical swapping', () =>
117 g.endDrag();
117 g.endDrag();
118 });
118 });
119});
119});
120
121describe('Manual launch of the already-topmost block', () =>
122{
123 it('dragging the top block upward past its own position starts a manual jump', () =>
124 {
125 const g = makeGame({ noSpawn: true });
126 // A single block is already the topmost (and only) block of its column.
127 const block = g.place(0, 0, 2);
128 // Grab at the visual centre (y=0.5), then pull just past its position —
129 // well short of the old "empty space above the cell" threshold (1.25).
130 assert.ok(g.beginDrag(0, 0.5));
131 assert.equal(g.drag.startedAsTop, true);
132 g.moveDrag(0.5 + 0.4);
133 assert.ok(0.9 < 0 + 1 + 0.25, 'this pull would have failed the old threshold');
134 assert.equal(g.drag.launchIntent, true, 'pull of 0.4 tiles past the press point must launch');
135 g.endDrag();
136 assert.equal(block.state, 'manual');
137 assert.equal(block.manualPhase, 'up');
138 assert.ok(block.vy > 0);
139 g.step(g.planet.riseTime, 1 / 240);
140 assert.ok(Math.abs(block.y - (g.height - 1)) < 0.08, 'jumps to just under the top, y=' + block.y);
141 assert.ok(block.y <= g.height - 1 + 1e-9);
142 });
143
144 it('a short upward twitch below LAUNCH_PULL does not launch', () =>
145 {
146 const g = makeGame({ noSpawn: true });
147 const block = g.place(3, 0, 1);
148 assert.ok(g.beginDrag(3, 0.5));
149 g.moveDrag(0.5 + 0.2);
150 assert.ok(0.2 < g.constructor.LAUNCH_PULL || 0.2 < 0.35);
151 assert.equal(g.drag.launchIntent, false);
152 g.endDrag();
153 assert.equal(block.state, 'still');
154 assert.equal(block.y, 0);
155 });
156
157 it('dragging a mid-stack block up to the top still swaps instead of launching', () =>
158 {
159 const g = makeGame({ noSpawn: true });
160 const bottom = g.place(1, 0, 0);
161 g.place(1, 1, 1);
162 g.place(1, 2, 2);
163 assert.ok(g.beginDrag(1, 0.3));
164 assert.equal(g.drag.startedAsTop, false);
165 // Pointer is past the top cell centre but not into the empty space.
166 g.moveDrag(2.4);
167 assert.equal(bottom.y, 2, 'swapped to the top');
168 assert.equal(g.drag.launchIntent, false, 'must not launch a mid-stack rearrange');
169 g.endDrag();
170 assert.equal(bottom.state, 'still');
171 assert.equal(bottom.y, 2);
172 });
173
174 it('after a mid-stack block becomes the top, a further pull into empty space still launches', () =>
175 {
176 const g = makeGame({ noSpawn: true });
177 const bottom = g.place(2, 0, 4);
178 g.place(2, 1, 3);
179 assert.ok(g.beginDrag(2, 0.2));
180 assert.equal(g.drag.startedAsTop, false);
181 g.moveDrag(1 + 1 + 0.4);
182 assert.equal(bottom.y, 1);
183 assert.equal(g.drag.launchIntent, true);
184 g.endDrag();
185 assert.equal(bottom.state, 'manual');
186 });
187});