948 lines
39 KiB
JavaScript
948 lines
39 KiB
JavaScript
// SlotsAbyssal — Abyssal Treasures props for the attract kit (SlotsAttract.js).
|
||
//
|
||
// Star of the show: Marina, a fully procedural mermaid puppet. Every part is
|
||
// baked on canvas at 2× ("baked units", BU) in the cartoon style of her
|
||
// symbol, then assembled in a Container scaled by 0.5 × rig scale:
|
||
// tail + hair strands → Phaser Ropes whose points are re-solved each frame
|
||
// (travelling waves, curl, buoyant drift)
|
||
// fin → rides the tail tip at the last segment's angle
|
||
// head / torso / arms → images; arms pivot at the shoulders, head tilts,
|
||
// eyes blink, mouth sings
|
||
// She sits on a giant clam in the right gutter, waves, points at pearl wilds,
|
||
// sings on every cascade, twirls on big wins, and in attract mode swims laps
|
||
// across the screen and blows heart bubbles.
|
||
//
|
||
// Also here: the pearl-ladder cascade multiplier (left gutter), fish schools,
|
||
// glowing jellyfish, and a manta ray silhouette. Hook contract matches
|
||
// SlotsGoldRush.js / SlotsDragon.js, plus onTumble(i) and onBigMoment().
|
||
|
||
import * as Phaser from 'phaser';
|
||
import { GAME_WIDTH, GAME_HEIGHT } from '../../config.js';
|
||
import { playSound, SFX } from '../../ui/Sounds.js';
|
||
import { canvasTex } from './SlotsAttract.js';
|
||
|
||
const ADD = Phaser.BlendModes.ADD;
|
||
const OL = '#2e1a3a'; // outline ink
|
||
const TAU = Math.PI * 2;
|
||
|
||
// ── Canvas helpers ────────────────────────────────────────────────────────────
|
||
function lin(ctx, x0, y0, x1, y1, stops) {
|
||
const g = ctx.createLinearGradient(x0, y0, x1, y1);
|
||
stops.forEach(([o, c]) => g.addColorStop(o, c));
|
||
return g;
|
||
}
|
||
|
||
// A stroke drawn as outline + fill (cartoon limbs).
|
||
function inkLine(ctx, pts, width, fill, ink = OL, inkW = 5) {
|
||
for (const [w, col] of [[width + inkW * 2, ink], [width, fill]]) {
|
||
ctx.strokeStyle = col; ctx.lineWidth = w; ctx.lineCap = 'round'; ctx.lineJoin = 'round';
|
||
ctx.beginPath();
|
||
pts.forEach(([x, y], i) => (i ? ctx.lineTo(x, y) : ctx.moveTo(x, y)));
|
||
ctx.stroke();
|
||
}
|
||
}
|
||
|
||
function drawHead(ctx, { eyes = 'open', mouth = 'smile' }) {
|
||
const skin = lin(ctx, 0, 60, 0, 230, [[0, '#ffe6d4'], [1, '#f6bfa0']]);
|
||
// Neck.
|
||
ctx.fillStyle = '#f2b896';
|
||
ctx.fillRect(104, 196, 32, 60);
|
||
ctx.strokeStyle = OL; ctx.lineWidth = 5;
|
||
ctx.beginPath(); ctx.moveTo(104, 200); ctx.lineTo(104, 256); ctx.moveTo(136, 200); ctx.lineTo(136, 256); ctx.stroke();
|
||
// Face.
|
||
ctx.fillStyle = skin;
|
||
ctx.beginPath(); ctx.ellipse(120, 140, 78, 88, 0, 0, TAU); ctx.fill();
|
||
ctx.lineWidth = 5; ctx.stroke();
|
||
// Blush.
|
||
ctx.fillStyle = 'rgba(255,120,140,0.32)';
|
||
for (const x of [72, 168]) { ctx.beginPath(); ctx.ellipse(x, 176, 17, 10, 0, 0, TAU); ctx.fill(); }
|
||
// Eyes.
|
||
for (const [x, dir] of [[88, -1], [152, 1]]) {
|
||
if (eyes === 'open') {
|
||
ctx.fillStyle = '#ffffff';
|
||
ctx.beginPath(); ctx.ellipse(x, 142, 19, 23, 0, 0, TAU); ctx.fill();
|
||
ctx.strokeStyle = OL; ctx.lineWidth = 3; ctx.stroke();
|
||
const iris = ctx.createRadialGradient(x, 146, 2, x, 146, 16);
|
||
iris.addColorStop(0, '#7cc8ff'); iris.addColorStop(1, '#1f6fe0');
|
||
ctx.fillStyle = iris;
|
||
ctx.beginPath(); ctx.arc(x, 146, 15, 0, TAU); ctx.fill();
|
||
ctx.fillStyle = '#14204a';
|
||
ctx.beginPath(); ctx.arc(x, 147, 8, 0, TAU); ctx.fill();
|
||
ctx.fillStyle = '#ffffff';
|
||
ctx.beginPath(); ctx.arc(x - 5, 140, 5, 0, TAU); ctx.fill();
|
||
ctx.beginPath(); ctx.arc(x + 5, 152, 2.5, 0, TAU); ctx.fill();
|
||
// Upper lid + lashes.
|
||
ctx.strokeStyle = OL; ctx.lineWidth = 6; ctx.lineCap = 'round';
|
||
ctx.beginPath(); ctx.ellipse(x, 142, 20, 24, 0, Math.PI * 1.12, Math.PI * 1.88); ctx.stroke();
|
||
ctx.lineWidth = 4;
|
||
const ex = x + dir * 18;
|
||
ctx.beginPath(); ctx.moveTo(ex, 130); ctx.lineTo(ex + dir * 10, 122); ctx.stroke();
|
||
ctx.beginPath(); ctx.moveTo(ex - dir * 4, 124); ctx.lineTo(ex + dir * 2, 114); ctx.stroke();
|
||
} else {
|
||
ctx.strokeStyle = OL; ctx.lineWidth = 5; ctx.lineCap = 'round';
|
||
ctx.beginPath(); ctx.arc(x, 138, 17, Math.PI * 0.15, Math.PI * 0.85); ctx.stroke();
|
||
ctx.lineWidth = 3.5;
|
||
ctx.beginPath(); ctx.moveTo(x + dir * 16, 148); ctx.lineTo(x + dir * 25, 152); ctx.stroke();
|
||
}
|
||
// Brows.
|
||
ctx.strokeStyle = '#b07a30'; ctx.lineWidth = 4; ctx.lineCap = 'round';
|
||
ctx.beginPath(); ctx.arc(x, 128, 22, Math.PI * 1.25, Math.PI * 1.75); ctx.stroke();
|
||
}
|
||
// Nose.
|
||
ctx.strokeStyle = '#d08a70'; ctx.lineWidth = 3;
|
||
ctx.beginPath(); ctx.moveTo(118, 164); ctx.quadraticCurveTo(124, 172, 116, 174); ctx.stroke();
|
||
// Mouth.
|
||
if (mouth === 'o') {
|
||
ctx.fillStyle = '#c0304a';
|
||
ctx.beginPath(); ctx.ellipse(120, 196, 10, 13, 0, 0, TAU); ctx.fill();
|
||
ctx.strokeStyle = OL; ctx.lineWidth = 3; ctx.stroke();
|
||
ctx.fillStyle = '#ff8aa0';
|
||
ctx.beginPath(); ctx.ellipse(120, 202, 6, 4, 0, 0, TAU); ctx.fill();
|
||
} else {
|
||
ctx.strokeStyle = '#c0304a'; ctx.lineWidth = 5; ctx.lineCap = 'round';
|
||
ctx.beginPath(); ctx.arc(120, 180, 20, Math.PI * 0.2, Math.PI * 0.8); ctx.stroke();
|
||
}
|
||
// Bangs + side locks.
|
||
const hair = lin(ctx, 0, 30, 0, 230, [[0, '#fff0a8'], [0.4, '#ffd65a'], [1, '#e0a030']]);
|
||
ctx.fillStyle = hair;
|
||
ctx.beginPath();
|
||
ctx.moveTo(34, 160);
|
||
ctx.bezierCurveTo(20, 70, 70, 34, 120, 34);
|
||
ctx.bezierCurveTo(176, 34, 222, 72, 206, 160);
|
||
ctx.quadraticCurveTo(196, 118, 176, 102);
|
||
ctx.quadraticCurveTo(158, 120, 140, 98);
|
||
ctx.quadraticCurveTo(118, 122, 98, 100);
|
||
ctx.quadraticCurveTo(78, 124, 62, 104);
|
||
ctx.quadraticCurveTo(44, 122, 34, 160);
|
||
ctx.closePath();
|
||
ctx.fill();
|
||
ctx.strokeStyle = OL; ctx.lineWidth = 5; ctx.stroke();
|
||
for (const side of [-1, 1]) {
|
||
const x = 120 + side * 80;
|
||
ctx.fillStyle = hair;
|
||
ctx.beginPath();
|
||
ctx.moveTo(x - side * 4, 96);
|
||
ctx.quadraticCurveTo(x + side * 22, 170, x + side * 4, 238);
|
||
ctx.quadraticCurveTo(x - side * 16, 180, x - side * 18, 120);
|
||
ctx.closePath();
|
||
ctx.fill(); ctx.stroke();
|
||
}
|
||
ctx.strokeStyle = 'rgba(176,112,24,0.55)'; ctx.lineWidth = 2.5;
|
||
for (const [x0, y0, x1, y1] of [[70, 60, 60, 100], [100, 44, 96, 96], [140, 44, 142, 94], [170, 60, 178, 100]]) {
|
||
ctx.beginPath(); ctx.moveTo(x0, y0); ctx.quadraticCurveTo((x0 + x1) / 2 + 6, (y0 + y1) / 2, x1, y1); ctx.stroke();
|
||
}
|
||
}
|
||
|
||
function bakeMermaidTextures(scene) {
|
||
canvasTex(scene, 'mm-head-open', 240, 260, (ctx) => drawHead(ctx, { eyes: 'open', mouth: 'smile' }));
|
||
canvasTex(scene, 'mm-head-blink', 240, 260, (ctx) => drawHead(ctx, { eyes: 'closed', mouth: 'smile' }));
|
||
canvasTex(scene, 'mm-head-sing', 240, 260, (ctx) => drawHead(ctx, { eyes: 'open', mouth: 'o' }));
|
||
|
||
// Torso (hips at bottom centre) with shell top and a fin frill at the waist.
|
||
canvasTex(scene, 'mm-torso', 240, 260, (ctx) => {
|
||
ctx.fillStyle = lin(ctx, 0, 0, 0, 260, [[0, '#ffe2d0'], [1, '#f2b896']]);
|
||
ctx.beginPath();
|
||
ctx.moveTo(106, 0); ctx.lineTo(134, 0);
|
||
ctx.quadraticCurveTo(140, 30, 206, 40);
|
||
ctx.quadraticCurveTo(226, 48, 216, 74);
|
||
ctx.quadraticCurveTo(176, 140, 168, 200);
|
||
ctx.quadraticCurveTo(170, 236, 178, 260);
|
||
ctx.lineTo(62, 260);
|
||
ctx.quadraticCurveTo(70, 236, 72, 200);
|
||
ctx.quadraticCurveTo(64, 140, 24, 74);
|
||
ctx.quadraticCurveTo(14, 48, 34, 40);
|
||
ctx.quadraticCurveTo(100, 30, 106, 0);
|
||
ctx.closePath();
|
||
ctx.fill();
|
||
ctx.strokeStyle = OL; ctx.lineWidth = 5; ctx.stroke();
|
||
ctx.fillStyle = 'rgba(200,120,90,0.5)';
|
||
ctx.beginPath(); ctx.ellipse(120, 210, 3.5, 5, 0, 0, TAU); ctx.fill();
|
||
// Shell top.
|
||
ctx.strokeStyle = '#7a2aa8'; ctx.lineWidth = 3;
|
||
ctx.beginPath(); ctx.moveTo(86, 86); ctx.lineTo(108, 10); ctx.moveTo(154, 86); ctx.lineTo(132, 10); ctx.stroke();
|
||
for (const [cx, rot] of [[88, -0.2], [152, 0.2]]) {
|
||
ctx.save();
|
||
ctx.translate(cx, 112); ctx.rotate(rot);
|
||
ctx.fillStyle = lin(ctx, 0, -30, 0, 30, [[0, '#e0a8ff'], [0.5, '#a64ad8'], [1, '#6a1e9a']]);
|
||
ctx.beginPath(); ctx.moveTo(0, 26);
|
||
for (let k = 0; k <= 6; k++) {
|
||
const a = Math.PI * (1.08 + (k / 6) * 0.84);
|
||
ctx.quadraticCurveTo(Math.cos(a - 0.07) * 40, Math.sin(a - 0.07) * 40 + 4, Math.cos(a) * 34, Math.sin(a) * 34 + 2);
|
||
}
|
||
ctx.closePath(); ctx.fill();
|
||
ctx.strokeStyle = OL; ctx.lineWidth = 4; ctx.stroke();
|
||
ctx.strokeStyle = 'rgba(70,10,110,0.55)'; ctx.lineWidth = 2;
|
||
for (let k = 1; k < 6; k++) {
|
||
const a = Math.PI * (1.08 + (k / 6) * 0.84);
|
||
ctx.beginPath(); ctx.moveTo(0, 24); ctx.lineTo(Math.cos(a) * 32, Math.sin(a) * 32 + 2); ctx.stroke();
|
||
}
|
||
ctx.restore();
|
||
}
|
||
ctx.fillStyle = '#ff8ad2';
|
||
ctx.beginPath(); ctx.arc(120, 112, 8, 0, TAU); ctx.fill();
|
||
ctx.strokeStyle = OL; ctx.lineWidth = 3; ctx.stroke();
|
||
// Waist frill where the tail begins.
|
||
ctx.fillStyle = lin(ctx, 0, 226, 0, 260, [[0, '#7affd8'], [1, '#18b090']]);
|
||
ctx.beginPath(); ctx.moveTo(52, 260);
|
||
for (let k = 0; k <= 8; k++) {
|
||
const x = 52 + (k / 8) * 136;
|
||
ctx.quadraticCurveTo(x - 8, 222, x, 234);
|
||
}
|
||
ctx.lineTo(188, 260); ctx.closePath(); ctx.fill();
|
||
ctx.strokeStyle = OL; ctx.lineWidth = 4; ctx.stroke();
|
||
});
|
||
|
||
// One arm hanging down from the shoulder (origin near the top).
|
||
canvasTex(scene, 'mm-arm', 120, 250, (ctx) => {
|
||
inkLine(ctx, [[60, 24], [64, 122]], 34, '#f8cdb2');
|
||
inkLine(ctx, [[64, 122], [58, 200]], 26, '#f6c4a6');
|
||
ctx.fillStyle = '#f6c4a6';
|
||
ctx.beginPath(); ctx.ellipse(58, 214, 17, 22, 0, 0, TAU); ctx.fill();
|
||
ctx.strokeStyle = OL; ctx.lineWidth = 5; ctx.stroke();
|
||
ctx.fillStyle = '#f8cdb2';
|
||
ctx.beginPath(); ctx.arc(60, 26, 18, 0, TAU); ctx.fill();
|
||
});
|
||
|
||
// Back hair volume.
|
||
canvasTex(scene, 'mm-hair-back', 320, 340, (ctx) => {
|
||
ctx.fillStyle = lin(ctx, 0, 0, 0, 340, [[0, '#ffe680'], [1, '#d89422']]);
|
||
ctx.beginPath();
|
||
ctx.moveTo(160, 10);
|
||
ctx.bezierCurveTo(300, 10, 320, 150, 290, 330);
|
||
ctx.quadraticCurveTo(160, 290, 30, 330);
|
||
ctx.bezierCurveTo(0, 150, 20, 10, 160, 10);
|
||
ctx.closePath(); ctx.fill();
|
||
ctx.strokeStyle = OL; ctx.lineWidth = 5; ctx.stroke();
|
||
ctx.strokeStyle = 'rgba(160,96,16,0.45)'; ctx.lineWidth = 3;
|
||
for (let k = 0; k < 9; k++) {
|
||
const x = 50 + k * 28;
|
||
ctx.beginPath(); ctx.moveTo(x, 60); ctx.quadraticCurveTo(x + 12, 190, x - 6, 310); ctx.stroke();
|
||
}
|
||
});
|
||
|
||
// A floating lock of hair (rope texture: root wide on the left, tip right).
|
||
canvasTex(scene, 'mm-hair-strand', 512, 90, (ctx) => {
|
||
ctx.fillStyle = lin(ctx, 0, 0, 0, 90, [[0, '#fff0a0'], [0.5, '#ffd24a'], [1, '#d08a1c']]);
|
||
ctx.beginPath();
|
||
ctx.moveTo(0, 4);
|
||
ctx.bezierCurveTo(180, 0, 380, 26, 508, 42);
|
||
ctx.lineTo(508, 48);
|
||
ctx.bezierCurveTo(380, 70, 180, 90, 0, 86);
|
||
ctx.closePath(); ctx.fill();
|
||
ctx.strokeStyle = OL; ctx.lineWidth = 4; ctx.stroke();
|
||
ctx.strokeStyle = 'rgba(160,96,16,0.5)'; ctx.lineWidth = 2.5;
|
||
for (const y of [26, 45, 64]) {
|
||
ctx.beginPath(); ctx.moveTo(10, y); ctx.bezierCurveTo(200, y, 380, 45, 480, 45); ctx.stroke();
|
||
}
|
||
});
|
||
|
||
// Tail (rope texture: hips wide on the left, tapering to the fin joint).
|
||
canvasTex(scene, 'mm-tail', 1024, 200, (ctx) => {
|
||
const half = (x) => 68 - (x / 1024) * 42;
|
||
ctx.save();
|
||
ctx.beginPath();
|
||
ctx.moveTo(0, 100 - half(0));
|
||
for (let x = 0; x <= 1024; x += 32) ctx.lineTo(x, 100 - half(x));
|
||
for (let x = 1024; x >= 0; x -= 32) ctx.lineTo(x, 100 + half(x));
|
||
ctx.closePath();
|
||
ctx.fillStyle = lin(ctx, 0, 0, 0, 200, [[0, '#5ef0c8'], [0.5, '#22c9a6'], [1, '#0d7a6c']]);
|
||
ctx.fill();
|
||
ctx.clip();
|
||
// Scales.
|
||
ctx.strokeStyle = 'rgba(190,255,235,0.55)'; ctx.lineWidth = 2.5;
|
||
for (let row = 0, y = 10; y < 200; row++, y += 22) {
|
||
for (let x = (row & 1) ? 18 : 0; x < 1024; x += 36) {
|
||
ctx.beginPath(); ctx.arc(x, y, 16, Math.PI * 0.15, Math.PI * 0.85); ctx.stroke();
|
||
}
|
||
}
|
||
ctx.fillStyle = 'rgba(255,255,255,0.18)';
|
||
ctx.fillRect(0, 70, 1024, 22);
|
||
ctx.restore();
|
||
ctx.strokeStyle = OL; ctx.lineWidth = 5;
|
||
ctx.beginPath();
|
||
for (let x = 0; x <= 1024; x += 32) (x ? ctx.lineTo(x, 100 - half(x)) : ctx.moveTo(x, 100 - half(x)));
|
||
ctx.stroke();
|
||
ctx.beginPath();
|
||
for (let x = 0; x <= 1024; x += 32) (x ? ctx.lineTo(x, 100 + half(x)) : ctx.moveTo(x, 100 + half(x)));
|
||
ctx.stroke();
|
||
});
|
||
|
||
// Fluke fin (joint on the left).
|
||
canvasTex(scene, 'mm-fin', 360, 280, (ctx) => {
|
||
ctx.beginPath();
|
||
ctx.moveTo(20, 118);
|
||
ctx.quadraticCurveTo(150, 50, 344, 16);
|
||
ctx.quadraticCurveTo(300, 100, 246, 140);
|
||
ctx.quadraticCurveTo(300, 180, 344, 264);
|
||
ctx.quadraticCurveTo(150, 230, 20, 162);
|
||
ctx.closePath();
|
||
ctx.fillStyle = lin(ctx, 20, 0, 344, 0, [[0, '#22c9a6'], [0.6, '#5ef0c8'], [1, '#c8fff0']]);
|
||
ctx.fill();
|
||
ctx.strokeStyle = OL; ctx.lineWidth = 5; ctx.stroke();
|
||
ctx.strokeStyle = 'rgba(10,110,90,0.5)'; ctx.lineWidth = 2.5;
|
||
for (const [x, y] of [[300, 40], [260, 80], [230, 118], [230, 162], [260, 200], [300, 240]]) {
|
||
ctx.beginPath(); ctx.moveTo(28, 140); ctx.quadraticCurveTo((28 + x) / 2, (140 + y) / 2 + 6, x, y); ctx.stroke();
|
||
}
|
||
});
|
||
|
||
// Giant clam: open lid (behind her) and the bowl (in front of her tail).
|
||
canvasTex(scene, 'mm-clam-back', 380, 250, (ctx) => {
|
||
ctx.beginPath();
|
||
ctx.moveTo(30, 240);
|
||
for (let k = 0; k <= 10; k++) {
|
||
const a = Math.PI * (1 + k / 10);
|
||
const r = 170 + (k & 1 ? 10 : 0);
|
||
ctx.lineTo(190 + Math.cos(a) * r, 240 + Math.sin(a) * r * 1.25);
|
||
}
|
||
ctx.lineTo(350, 240); ctx.closePath();
|
||
ctx.fillStyle = lin(ctx, 0, 20, 0, 240, [[0, '#ffd2f0'], [0.6, '#d68ad8'], [1, '#8a4aa8']]);
|
||
ctx.fill();
|
||
ctx.strokeStyle = OL; ctx.lineWidth = 5; ctx.stroke();
|
||
ctx.strokeStyle = 'rgba(110,40,130,0.45)'; ctx.lineWidth = 3;
|
||
for (let k = 1; k < 10; k++) {
|
||
const a = Math.PI * (1 + k / 10);
|
||
ctx.beginPath(); ctx.moveTo(190, 236); ctx.lineTo(190 + Math.cos(a) * 165, 240 + Math.sin(a) * 205); ctx.stroke();
|
||
}
|
||
});
|
||
canvasTex(scene, 'mm-clam-front', 400, 160, (ctx) => {
|
||
ctx.beginPath();
|
||
ctx.moveTo(10, 24);
|
||
for (let k = 0; k <= 12; k++) ctx.quadraticCurveTo(10 + (k - 0.5) * 31.7, k & 1 ? 8 : 34, 10 + k * 31.7, 24);
|
||
ctx.bezierCurveTo(400, 120, 300, 156, 200, 156);
|
||
ctx.bezierCurveTo(100, 156, 0, 120, 10, 24);
|
||
ctx.closePath();
|
||
ctx.fillStyle = lin(ctx, 0, 10, 0, 156, [[0, '#f6b8f0'], [0.5, '#b866c8'], [1, '#6a2a88']]);
|
||
ctx.fill();
|
||
ctx.strokeStyle = OL; ctx.lineWidth = 5; ctx.stroke();
|
||
ctx.strokeStyle = 'rgba(90,20,110,0.45)'; ctx.lineWidth = 3;
|
||
for (let k = 1; k < 12; k++) {
|
||
const x = 10 + k * 31.7;
|
||
ctx.beginPath(); ctx.moveTo(x, 28); ctx.quadraticCurveTo(x + (200 - x) * 0.3, 100, 200 + (x - 200) * 0.4, 150); ctx.stroke();
|
||
}
|
||
});
|
||
}
|
||
|
||
function bakeSeaLife(scene) {
|
||
// Fish (white → tinted per school; the eye stays dark).
|
||
canvasTex(scene, 'mm-fish', 80, 44, (ctx) => {
|
||
ctx.fillStyle = 'rgba(255,255,255,0.95)';
|
||
ctx.beginPath();
|
||
ctx.moveTo(6, 22); ctx.quadraticCurveTo(26, 2, 56, 14); ctx.lineTo(76, 4); ctx.lineTo(70, 22);
|
||
ctx.lineTo(76, 40); ctx.lineTo(56, 30); ctx.quadraticCurveTo(26, 42, 6, 22);
|
||
ctx.closePath(); ctx.fill();
|
||
ctx.fillStyle = 'rgba(0,0,0,0.18)';
|
||
ctx.beginPath(); ctx.ellipse(32, 15, 20, 5, 0, 0, TAU); ctx.fill();
|
||
ctx.fillStyle = '#10142a';
|
||
ctx.beginPath(); ctx.arc(18, 19, 3.5, 0, TAU); ctx.fill();
|
||
});
|
||
// Jellyfish bell.
|
||
canvasTex(scene, 'mm-jelly', 128, 96, (ctx) => {
|
||
const g = ctx.createRadialGradient(64, 60, 6, 64, 70, 70);
|
||
g.addColorStop(0, 'rgba(255,230,255,0.95)');
|
||
g.addColorStop(0.6, 'rgba(255,140,230,0.55)');
|
||
g.addColorStop(1, 'rgba(180,90,255,0.15)');
|
||
ctx.fillStyle = g;
|
||
ctx.beginPath();
|
||
ctx.moveTo(6, 84); ctx.bezierCurveTo(6, 0, 122, 0, 122, 84);
|
||
for (let k = 6; k >= 0; k--) ctx.quadraticCurveTo(6 + (k + 0.5) * 16.6, 94, 6 + k * 16.6, 84);
|
||
ctx.closePath(); ctx.fill();
|
||
ctx.strokeStyle = 'rgba(255,220,255,0.9)'; ctx.lineWidth = 2; ctx.stroke();
|
||
});
|
||
canvasTex(scene, 'mm-tentacle', 256, 14, (ctx) => {
|
||
ctx.fillStyle = lin(ctx, 0, 0, 256, 0, [[0, 'rgba(255,190,245,0.9)'], [1, 'rgba(200,140,255,0)']]);
|
||
ctx.beginPath(); ctx.moveTo(0, 1); ctx.lineTo(256, 6); ctx.lineTo(256, 8); ctx.lineTo(0, 13); ctx.closePath(); ctx.fill();
|
||
});
|
||
// Manta ray silhouette.
|
||
canvasTex(scene, 'mm-manta', 520, 300, (ctx) => {
|
||
ctx.fillStyle = '#06102a';
|
||
ctx.beginPath();
|
||
ctx.moveTo(260, 40);
|
||
ctx.quadraticCurveTo(300, 60, 516, 120);
|
||
ctx.quadraticCurveTo(330, 150, 290, 210);
|
||
ctx.quadraticCurveTo(270, 240, 262, 298);
|
||
ctx.lineTo(258, 298);
|
||
ctx.quadraticCurveTo(250, 240, 230, 210);
|
||
ctx.quadraticCurveTo(190, 150, 4, 120);
|
||
ctx.quadraticCurveTo(220, 60, 260, 40);
|
||
ctx.closePath(); ctx.fill();
|
||
});
|
||
// Heart (for bubble hearts).
|
||
canvasTex(scene, 'mm-heart', 48, 44, (ctx) => {
|
||
ctx.fillStyle = '#ff6fae';
|
||
ctx.beginPath();
|
||
ctx.moveTo(24, 40);
|
||
ctx.bezierCurveTo(-6, 18, 8, -4, 24, 12);
|
||
ctx.bezierCurveTo(40, -4, 54, 18, 24, 40);
|
||
ctx.fill();
|
||
ctx.fillStyle = 'rgba(255,255,255,0.7)';
|
||
ctx.beginPath(); ctx.ellipse(15, 13, 5, 3, -0.6, 0, TAU); ctx.fill();
|
||
});
|
||
}
|
||
|
||
const vec = (n) => Array.from({ length: n }, () => new Phaser.Math.Vector2());
|
||
|
||
// ── Marina: the mermaid rig ───────────────────────────────────────────────────
|
||
class Mermaid {
|
||
constructor(scene, x, y, depth, scale = 0.9) {
|
||
this.scene = scene;
|
||
this.home = { x, y, depth, scale };
|
||
this.root = { x, y, rot: 0, scale, extraRot: 0 };
|
||
this.depth = depth;
|
||
this.t = 0;
|
||
this.blinkMs = 2500;
|
||
this.blinking = 0;
|
||
this.mouthMs = 0;
|
||
this.swimming = false;
|
||
// Animatable pose (rest values; actions tween these).
|
||
this.pose = {
|
||
armL: 0.3, armR: -0.3, head: 0, bob: 1,
|
||
tailCurl: -2.2, tailAmp: 0.16, tailFreq: 1.8, hairAmp: 0.28, hairFreq: 1.2, hairUp: 0,
|
||
};
|
||
|
||
const c = scene.add.container(x, y).setDepth(depth);
|
||
this.c = c;
|
||
this.strandDefs = [
|
||
{ root: [-96, -150], ang: 0.5, curl: 0.5, len: 40 },
|
||
{ root: [-62, -205], ang: 0.25, curl: 0.35, len: 42 },
|
||
{ root: [0, -222], ang: 0, curl: 0, len: 44 },
|
||
{ root: [62, -205], ang: -0.25, curl: -0.35, len: 42 },
|
||
{ root: [96, -150], ang: -0.5, curl: -0.5, len: 40 },
|
||
];
|
||
this.strands = this.strandDefs.map(() => {
|
||
const r = scene.add.rope(0, 0, 'mm-hair-strand', null, vec(9), true);
|
||
c.add(r);
|
||
return r;
|
||
});
|
||
this.hairBack = scene.add.image(0, -360, 'mm-hair-back');
|
||
this.tail = scene.add.rope(0, 0, 'mm-tail', null, vec(17), true);
|
||
this.fin = scene.add.image(0, 0, 'mm-fin').setOrigin(0.06, 0.5);
|
||
this.torso = scene.add.image(0, 0, 'mm-torso').setOrigin(0.5, 1);
|
||
this.armL = scene.add.image(-90, -214, 'mm-arm').setOrigin(0.5, 0.1).setFlipX(true);
|
||
this.armR = scene.add.image(90, -214, 'mm-arm').setOrigin(0.5, 0.1);
|
||
this.head = scene.add.image(0, -244, 'mm-head-open').setOrigin(0.5, 0.94);
|
||
c.add([this.hairBack, this.tail, this.fin, this.torso, this.armL, this.armR, this.head]);
|
||
this.applyRoot();
|
||
this.solve(0);
|
||
}
|
||
|
||
applyRoot() {
|
||
const r = this.root;
|
||
this.c.setPosition(r.x, r.y);
|
||
this.c.setRotation(r.rot + r.extraRot);
|
||
this.c.setScale(r.scale * 0.5);
|
||
}
|
||
|
||
// Solve the ropes + part transforms for this frame.
|
||
solve(dt) {
|
||
this.t += dt / 1000;
|
||
const P = this.pose;
|
||
const t = this.t;
|
||
|
||
// Tail: a travelling wave on a curled spine.
|
||
const pts = this.tail.points;
|
||
const n = pts.length - 1;
|
||
const seg = 34;
|
||
let x = 0; let y = -12; let a = Math.PI / 2;
|
||
pts[0].set(x, y);
|
||
for (let i = 0; i < n; i++) {
|
||
const s = i / n;
|
||
a = Math.PI / 2 + P.tailCurl * s + P.tailAmp * (0.3 + s) * Math.sin(t * P.tailFreq * TAU / 2 - s * 5);
|
||
x += Math.cos(a) * seg; y += Math.sin(a) * seg;
|
||
pts[i + 1].set(x, y);
|
||
}
|
||
this.tail.setDirty();
|
||
this.fin.setPosition(x, y).setRotation(a);
|
||
|
||
// Head tilt + hair strands rooted on the head.
|
||
const ha = P.head + 0.05 * Math.sin(t * 0.7);
|
||
this.head.setRotation(ha);
|
||
const neckX = 0; const neckY = -244;
|
||
const cos = Math.cos(ha); const sin = Math.sin(ha);
|
||
const hb = { x: neckX + (0 * cos - -116 * sin), y: neckY + (0 * sin + -116 * cos) };
|
||
this.hairBack.setPosition(hb.x, hb.y).setRotation(ha);
|
||
this.strandDefs.forEach((d, k) => {
|
||
const rp = this.strands[k].points;
|
||
const rx = neckX + d.root[0] * cos - d.root[1] * sin;
|
||
const ry = neckY + d.root[0] * sin + d.root[1] * cos;
|
||
let sx = rx; let sy = ry;
|
||
rp[0].set(sx, sy);
|
||
for (let i = 0; i < rp.length - 1; i++) {
|
||
const s = i / (rp.length - 1);
|
||
const ang = Math.PI / 2 + ha + d.ang + d.curl * s * (1 + P.hairUp)
|
||
+ P.hairAmp * s * Math.sin(t * P.hairFreq * TAU / 2 - s * 3 + k);
|
||
sx += Math.cos(ang) * d.len; sy += Math.sin(ang) * d.len;
|
||
rp[i + 1].set(sx, sy);
|
||
}
|
||
this.strands[k].setDirty();
|
||
});
|
||
|
||
// Arms sway a touch around their posed angle.
|
||
this.armL.setRotation(P.armL + 0.06 * Math.sin(t * 1.3));
|
||
this.armR.setRotation(P.armR + 0.06 * Math.sin(t * 1.3 + 1));
|
||
|
||
// Eyes + mouth.
|
||
this.blinkMs -= dt;
|
||
if (this.blinkMs <= 0) { this.blinking = 140; this.blinkMs = 2400 + Math.random() * 2800; }
|
||
if (this.blinking > 0) this.blinking -= dt;
|
||
if (this.mouthMs > 0) this.mouthMs -= dt;
|
||
const key = this.blinking > 0 ? 'mm-head-blink' : this.mouthMs > 0 ? 'mm-head-sing' : 'mm-head-open';
|
||
if (this.head.texture.key !== key) this.head.setTexture(key);
|
||
|
||
// Gentle float while seated.
|
||
if (!this.swimming) {
|
||
this.root.y = this.home.y + P.bob * 7 * Math.sin(t * 1.6);
|
||
this.root.rot = 0.035 * Math.sin(t * 0.9);
|
||
}
|
||
this.applyRoot();
|
||
}
|
||
|
||
// World position of a point in rig space (BU).
|
||
world(px, py) {
|
||
const r = this.root;
|
||
const rot = r.rot + r.extraRot;
|
||
const s = r.scale * 0.5;
|
||
return {
|
||
x: r.x + (px * Math.cos(rot) - py * Math.sin(rot)) * s,
|
||
y: r.y + (px * Math.sin(rot) + py * Math.cos(rot)) * s,
|
||
};
|
||
}
|
||
|
||
say(ms = 700) { this.mouthMs = ms; }
|
||
|
||
tweenPose(props, duration, extra = {}) {
|
||
return this.scene.tweens.add({ targets: this.pose, ...props, duration, ease: 'Sine.inOut', ...extra });
|
||
}
|
||
|
||
wave() {
|
||
if (this.swimming || this.acting) return;
|
||
this.acting = true;
|
||
this.say(500);
|
||
this.scene.tweens.chain({
|
||
targets: this.pose,
|
||
tweens: [
|
||
{ armR: -2.5, head: 0.12, duration: 300, ease: 'Back.out' },
|
||
{ armR: -2.05, duration: 180, yoyo: true, repeat: 3, ease: 'Sine.inOut' },
|
||
{ armR: -0.3, head: 0, duration: 380, ease: 'Sine.inOut' },
|
||
],
|
||
onComplete: () => { this.acting = false; },
|
||
});
|
||
}
|
||
|
||
cheer() {
|
||
if (this.swimming) return;
|
||
this.scene.tweens.killTweensOf(this.pose);
|
||
this.acting = true;
|
||
this.say(900);
|
||
this.scene.tweens.chain({
|
||
targets: this.pose,
|
||
tweens: [
|
||
{ armL: 2.7, armR: -2.7, bob: 3, hairUp: 0.6, duration: 240, ease: 'Back.out' },
|
||
{ armL: 2.4, armR: -2.4, duration: 160, yoyo: true, repeat: 2 },
|
||
{ armL: 0.3, armR: -0.3, bob: 1, hairUp: 0, duration: 400 },
|
||
],
|
||
onComplete: () => { this.acting = false; },
|
||
});
|
||
}
|
||
|
||
// Point the left arm at a world position (the reels are to her left).
|
||
point(tx, ty) {
|
||
if (this.swimming) return;
|
||
const sh = this.world(-90, -214);
|
||
const ang = Math.atan2(ty - sh.y, tx - sh.x) - Math.PI / 2 - this.root.rot;
|
||
this.scene.tweens.killTweensOf(this.pose);
|
||
this.acting = true;
|
||
this.say(600);
|
||
this.scene.tweens.chain({
|
||
targets: this.pose,
|
||
tweens: [
|
||
{ armL: ang, head: -0.15, duration: 260, ease: 'Back.out' },
|
||
{ armL: 0.3, head: 0, duration: 420, delay: 900 },
|
||
],
|
||
onComplete: () => { this.acting = false; },
|
||
});
|
||
}
|
||
|
||
twirl() {
|
||
if (this.swimming) return;
|
||
this.say(900);
|
||
this.scene.tweens.add({ targets: this.root, extraRot: TAU, duration: 900, ease: 'Cubic.inOut',
|
||
onComplete: () => { this.root.extraRot = 0; } });
|
||
this.tweenPose({ hairUp: 1 }, 450, { yoyo: true });
|
||
}
|
||
}
|
||
|
||
// ── Props ─────────────────────────────────────────────────────────────────────
|
||
export class AbyssalProps {
|
||
constructor(stage) {
|
||
this.stage = stage;
|
||
this.scene = stage.scene;
|
||
this.m = stage.m;
|
||
this.A = stage.A;
|
||
this.D = stage.D;
|
||
this.g = stage.g;
|
||
this.view = null;
|
||
this.t = 0;
|
||
this.level = 0;
|
||
this.fish = [];
|
||
this.jellies = [];
|
||
this.waveMs = 6000;
|
||
this.schoolMs = 2000;
|
||
this.mantaMs = 20000;
|
||
this.lapMs = 0;
|
||
this.heartMs = 0;
|
||
this.pointedThisSpin = false;
|
||
bakeMermaidTextures(this.scene);
|
||
bakeSeaLife(this.scene);
|
||
this.buildClamAndMermaid();
|
||
this.buildLadder();
|
||
this.buildJellies();
|
||
}
|
||
|
||
// ── Clam + Marina (right gutter) ───────────────────────────────────────────
|
||
buildClamAndMermaid() {
|
||
const { scene } = this;
|
||
const { cab } = this.g;
|
||
const x = Math.round((cab.x + cab.w + GAME_WIDTH) / 2);
|
||
const clamY = 760;
|
||
const depth = this.D.cab + 3;
|
||
this.clamBack = scene.add.image(x, clamY - 6, 'mm-clam-back').setOrigin(0.5, 1).setDisplaySize(300, 198)
|
||
.setDepth(depth);
|
||
this.pearlGlow = scene.add.image(x - 86, clamY - 52, 'slots-glow').setDisplaySize(130, 130)
|
||
.setTint(0xdff0ff).setBlendMode(ADD).setAlpha(0.45).setDepth(depth + 0.2);
|
||
this.pearl = scene.add.image(x - 86, clamY - 52, 'slots-pearl').setDisplaySize(46, 46).setDepth(depth + 0.25);
|
||
this.mermaid = new Mermaid(scene, x - 8, clamY - 70, depth + 0.1, 0.88);
|
||
this.clamFront = scene.add.image(x, clamY - 40, 'mm-clam-front').setOrigin(0.5, 0).setDisplaySize(316, 126)
|
||
.setDepth(depth + 0.3);
|
||
scene.tweens.add({ targets: this.pearlGlow, alpha: 0.75, duration: 1600, yoyo: true, repeat: -1, ease: 'Sine.inOut' });
|
||
}
|
||
|
||
clamFlash() {
|
||
const { scene } = this;
|
||
scene.tweens.add({ targets: this.pearlGlow, displayWidth: 260, displayHeight: 260, alpha: 1, duration: 200, yoyo: true });
|
||
scene.tweens.add({ targets: this.clamBack, scaleY: this.clamBack.scaleY * 0.9, duration: 120, yoyo: true, repeat: 1 });
|
||
this.stage.sound('pearl');
|
||
}
|
||
|
||
// ── Pearl ladder (left gutter): ×1 ×2 ×4 ×6 ────────────────────────────────
|
||
buildLadder() {
|
||
const { scene } = this;
|
||
const { cab } = this.g;
|
||
const mults = this.m.features.cascade?.multipliers ?? [1, 2, 4, 6];
|
||
const x = Math.round(cab.x / 2); const y = 530;
|
||
const depth = this.D.cab + 3;
|
||
const g = scene.add.graphics().setDepth(depth);
|
||
g.fillStyle(0x041a2e, 0.78);
|
||
g.fillRoundedRect(x - 92, y - 250, 184, 500, 60);
|
||
g.lineStyle(4, 0x59e7ff, 0.9);
|
||
g.strokeRoundedRect(x - 92, y - 250, 184, 500, 60);
|
||
g.lineStyle(2, 0xd9c27a, 0.7);
|
||
g.strokeRoundedRect(x - 84, y - 242, 168, 484, 54);
|
||
// Coral sprigs on the frame.
|
||
const sprig = (bx, by, dir, col) => {
|
||
g.lineStyle(7, col, 1);
|
||
g.lineBetween(bx, by, bx + dir * 26, by - 30);
|
||
g.lineBetween(bx + dir * 14, by - 16, bx + dir * 2, by - 40);
|
||
g.lineBetween(bx + dir * 26, by - 30, bx + dir * 40, by - 44);
|
||
g.fillStyle(col, 1);
|
||
g.fillCircle(bx + dir * 40, by - 44, 5); g.fillCircle(bx + dir * 2, by - 40, 5);
|
||
};
|
||
sprig(x - 88, y + 250, 1, 0xff5fa8);
|
||
sprig(x + 88, y + 250, -1, 0xb07aff);
|
||
sprig(x - 90, y - 160, 1, 0xff8c6a);
|
||
scene.add.text(x, y - 290, 'CASCADE', {
|
||
fontFamily: 'Righteous', fontSize: '34px', color: '#7af0ff', stroke: '#041a2e', strokeThickness: 7,
|
||
}).setOrigin(0.5).setDepth(depth).setShadow(0, 0, '#59e7ff', 14);
|
||
scene.add.text(x, y + 284, 'MULTIPLIER', {
|
||
fontFamily: '"Julius Sans One"', fontSize: '18px', color: '#cfefff', stroke: '#041a2e', strokeThickness: 5,
|
||
}).setOrigin(0.5).setDepth(depth);
|
||
this.ladder = mults.map((mult, i) => {
|
||
const py = y + 180 - i * 120;
|
||
const glow = scene.add.image(x, py, 'slots-glow').setDisplaySize(190, 190).setTint(0x59e7ff)
|
||
.setBlendMode(ADD).setAlpha(0).setDepth(depth + 0.1);
|
||
const pearl = scene.add.image(x, py, 'slots-pearl').setDisplaySize(96, 96).setAlpha(0.35).setDepth(depth + 0.2);
|
||
const label = scene.add.text(x, py + 2, `×${mult}`, {
|
||
fontFamily: 'Righteous', fontSize: '34px', color: '#1a3a5a',
|
||
}).setOrigin(0.5).setDepth(depth + 0.3).setAlpha(0.5);
|
||
return { glow, pearl, label, y: py, x };
|
||
});
|
||
this.setLevel(0, true);
|
||
}
|
||
|
||
setLevel(i, silent = false) {
|
||
const { scene } = this;
|
||
const prev = this.level;
|
||
this.level = i;
|
||
this.ladder.forEach((rung, k) => {
|
||
const on = k === i;
|
||
const passed = k < i;
|
||
rung.pearl.setAlpha(on ? 1 : passed ? 0.7 : 0.35);
|
||
rung.label.setAlpha(on ? 1 : passed ? 0.7 : 0.5).setColor(on ? '#0a2a4a' : '#1a3a5a');
|
||
scene.tweens.add({ targets: rung.glow, alpha: on ? 0.9 : 0, duration: 260 });
|
||
});
|
||
if (silent || i <= prev) return;
|
||
// A light bubble rises from the old rung to the new one, then a sonar ping.
|
||
const from = this.ladder[prev]; const to = this.ladder[i];
|
||
const b = scene.add.image(from.x, from.y, 'slots-bubble').setScale(0.9).setDepth(this.D.cab + 3.5);
|
||
scene.tweens.add({
|
||
targets: b, y: to.y, duration: 380, ease: 'Sine.inOut',
|
||
onComplete: () => {
|
||
b.destroy();
|
||
const ring = scene.add.circle(to.x, to.y, 50).setStrokeStyle(4, 0x7af0ff).setDepth(this.D.cab + 3.5);
|
||
scene.tweens.add({ targets: ring, scale: 2.6, alpha: 0, duration: 650, onComplete: () => ring.destroy() });
|
||
scene.tweens.add({ targets: [to.pearl, to.label], scale: '*=1.25', duration: 150, yoyo: true });
|
||
this.stage.sound('sonar', () => playSound(scene, SFX.SCIFI_PLINK));
|
||
},
|
||
});
|
||
}
|
||
|
||
// ── Sea life ───────────────────────────────────────────────────────────────
|
||
buildJellies() {
|
||
const spots = [[150, 900, 0.9], [60, 600, 0.6], [1870, 380, 0.55]];
|
||
for (const [x, y, s] of spots) this.jellies.push(this.makeJelly(x, y, s));
|
||
}
|
||
|
||
makeJelly(x, y, s) {
|
||
const { scene } = this;
|
||
const depth = this.D.bg + 4.85;
|
||
const glow = scene.add.image(x, y, 'slots-glow').setDisplaySize(220 * s, 220 * s).setTint(0xff8ae8)
|
||
.setBlendMode(ADD).setAlpha(0.35).setDepth(depth);
|
||
const bell = scene.add.image(x, y, 'mm-jelly').setScale(s).setBlendMode(ADD).setDepth(depth + 0.02);
|
||
const tents = [-36, -12, 12, 36].map(() => scene.add.rope(0, 0, 'mm-tentacle', null, vec(8), true)
|
||
.setBlendMode(ADD).setDepth(depth + 0.01));
|
||
return { x, y, s, glow, bell, tents, ph: Math.random() * TAU, vx: (Math.random() - 0.5) * 6 };
|
||
}
|
||
|
||
updateJellies(dt) {
|
||
const sec = dt / 1000;
|
||
for (const j of this.jellies) {
|
||
j.ph += sec * TAU / 2.2;
|
||
const pulse = Math.sin(j.ph);
|
||
const thrust = Math.max(0, pulse);
|
||
j.y -= (8 + thrust * 34) * sec * j.s;
|
||
j.x += j.vx * sec;
|
||
if (j.y < -120) { j.y = GAME_HEIGHT + 120; }
|
||
j.bell.setPosition(j.x, j.y).setScale(j.s * (1 + 0.08 * pulse), j.s * (1 - 0.1 * pulse));
|
||
j.glow.setPosition(j.x, j.y + 8).setAlpha(0.25 + 0.15 * thrust);
|
||
[-36, -12, 12, 36].forEach((ox, k) => {
|
||
const rp = j.tents[k].points;
|
||
let px = j.x + ox * j.s * (1 - 0.1 * pulse); let py = j.y + 36 * j.s;
|
||
rp[0].set(px, py);
|
||
for (let i = 1; i < rp.length; i++) {
|
||
const a = Math.PI / 2 + 0.25 * Math.sin(j.ph - i * 0.6 + k);
|
||
px += Math.cos(a) * 16 * j.s; py += Math.sin(a) * 16 * j.s;
|
||
rp[i].set(px, py);
|
||
}
|
||
j.tents[k].setDirty();
|
||
});
|
||
}
|
||
}
|
||
|
||
spawnSchool() {
|
||
const { scene } = this;
|
||
const colors = [0xffd23f, 0x3aa8ff, 0xff8c2a, 0xb07aff, 0x7affd8];
|
||
const tint = colors[Math.floor(Math.random() * colors.length)];
|
||
const dir = Math.random() < 0.5 ? 1 : -1;
|
||
const y0 = 120 + Math.random() * 760;
|
||
const n = 7 + Math.floor(Math.random() * 8);
|
||
const speed = 90 + Math.random() * 70;
|
||
const scale = 0.5 + Math.random() * 0.4;
|
||
const school = { dir, y0, x: dir > 0 ? -200 : GAME_WIDTH + 200, speed, members: [] };
|
||
for (let i = 0; i < n; i++) {
|
||
const img = scene.add.image(0, 0, 'mm-fish').setTint(tint).setScale(scale)
|
||
.setFlipX(dir > 0).setDepth(this.D.bg + 4.8);
|
||
school.members.push({ img, dx: -dir * (Math.random() * 160), dy: (Math.random() - 0.5) * 110,
|
||
ph: Math.random() * TAU, s: scale });
|
||
}
|
||
this.fish.push(school);
|
||
}
|
||
|
||
updateFish(dt) {
|
||
const sec = dt / 1000;
|
||
for (let k = this.fish.length - 1; k >= 0; k--) {
|
||
const sc = this.fish[k];
|
||
sc.x += sc.dir * sc.speed * sec;
|
||
const yy = sc.y0 + Math.sin(sc.x / 260) * 50;
|
||
for (const f of sc.members) {
|
||
f.ph += sec * 9;
|
||
f.img.setPosition(sc.x + f.dx + Math.sin(f.ph * 0.2) * 12, yy + f.dy + Math.sin(f.ph * 0.15) * 8);
|
||
f.img.setScale(f.s * (1 + 0.05 * Math.sin(f.ph)), f.s);
|
||
}
|
||
if ((sc.dir > 0 && sc.x > GAME_WIDTH + 400) || (sc.dir < 0 && sc.x < -400)) {
|
||
for (const f of sc.members) f.img.destroy();
|
||
this.fish.splice(k, 1);
|
||
}
|
||
}
|
||
}
|
||
|
||
mantaGlide() {
|
||
const { scene } = this;
|
||
const img = scene.add.image(-320, 220, 'mm-manta').setDisplaySize(560, 320).setAlpha(0.32)
|
||
.setDepth(this.D.bg + 4.55).setAngle(8);
|
||
const base = img.scaleY;
|
||
scene.tweens.add({ targets: img, scaleY: base * 0.7, duration: 1400, yoyo: true, repeat: -1, ease: 'Sine.inOut' });
|
||
const carrier = { x: -320 };
|
||
scene.tweens.add({
|
||
targets: carrier, x: GAME_WIDTH + 320, duration: 16000,
|
||
onUpdate: () => { img.x = carrier.x; img.y = 220 + Math.sin(carrier.x / 380) * 60; },
|
||
onComplete: () => { scene.tweens.killTweensOf(img); img.destroy(); },
|
||
});
|
||
}
|
||
|
||
// Bubble with a note or heart inside, floating up from Marina.
|
||
floatBubble(from, kind) {
|
||
const { scene } = this;
|
||
const b = scene.add.image(from.x, from.y, 'slots-bubble').setScale(0.75).setDepth(this.D.ui - 1.4);
|
||
const inner = kind === 'heart'
|
||
? scene.add.image(from.x, from.y, 'mm-heart').setScale(0.7).setDepth(this.D.ui - 1.39)
|
||
: scene.add.text(from.x, from.y, '♪', { fontFamily: 'Righteous', fontSize: '28px', color: '#ffffff' })
|
||
.setOrigin(0.5).setDepth(this.D.ui - 1.39);
|
||
const dx = (kind === 'heart' ? -160 : -40) - Math.random() * 60;
|
||
scene.tweens.add({
|
||
targets: [b, inner], x: from.x + dx, y: from.y - 180 - Math.random() * 60, duration: 2200,
|
||
ease: 'Sine.out', onComplete: () => { b.destroy(); inner.destroy(); },
|
||
});
|
||
scene.tweens.add({ targets: [b, inner], alpha: 0, delay: 1500, duration: 700 });
|
||
}
|
||
|
||
// ── Attract: Marina swims a lap across the screen and back to her clam ─────
|
||
swimLap() {
|
||
const mm = this.mermaid;
|
||
if (mm.swimming) return;
|
||
const { scene } = this;
|
||
mm.swimming = true;
|
||
this.stage.sound('splash');
|
||
scene.tweens.killTweensOf(mm.pose);
|
||
mm.tweenPose({ tailCurl: 0, tailAmp: 0.5, tailFreq: 3.4, armL: 0.08, armR: -0.08, hairUp: 0 }, 500);
|
||
mm.c.setDepth(this.D.ui - 1.5);
|
||
const h = mm.home;
|
||
const curve = new Phaser.Curves.Spline([
|
||
h.x, h.y, h.x - 60, h.y - 260, 1300, 520, 900, 420, 520, 560, 250, 380,
|
||
140, 560, 420, 720, 960, 680, 1400, 620, h.x - 40, h.y - 140, h.x, h.y,
|
||
]);
|
||
const carrier = { t: 0 };
|
||
let last = curve.getPoint(0);
|
||
this.lapTween = scene.tweens.add({
|
||
targets: carrier, t: 1, duration: 11000, ease: 'Sine.inOut',
|
||
onUpdate: () => {
|
||
const p = curve.getPoint(carrier.t);
|
||
const dx = p.x - last.x; const dy = p.y - last.y;
|
||
if (dx * dx + dy * dy > 0.5) {
|
||
const want = Math.atan2(dy, dx) + Math.PI / 2;
|
||
let diff = want - mm.root.rot;
|
||
diff = Math.atan2(Math.sin(diff), Math.cos(diff));
|
||
mm.root.rot += diff * 0.15;
|
||
}
|
||
mm.root.x = p.x; mm.root.y = p.y;
|
||
mm.root.scale = h.scale * (0.78 + 0.22 * Math.abs(carrier.t - 0.5) * 2);
|
||
last = p;
|
||
if (Math.random() < 0.08) this.floatTrailBubble(mm.world(0, 300));
|
||
},
|
||
onComplete: () => this.settleHome(),
|
||
});
|
||
}
|
||
|
||
floatTrailBubble(p) {
|
||
const b = this.scene.add.image(p.x, p.y, 'slots-bubble').setScale(0.2 + Math.random() * 0.2)
|
||
.setDepth(this.D.ui - 1.6);
|
||
this.scene.tweens.add({ targets: b, y: p.y - 120, alpha: 0, duration: 1400, onComplete: () => b.destroy() });
|
||
}
|
||
|
||
comeHome() {
|
||
const mm = this.mermaid;
|
||
if (!mm.swimming) return;
|
||
this.lapTween?.stop();
|
||
const h = mm.home;
|
||
this.scene.tweens.add({ targets: mm.root, x: h.x, y: h.y, scale: h.scale, duration: 700, ease: 'Sine.inOut',
|
||
onComplete: () => this.settleHome() });
|
||
}
|
||
|
||
settleHome() {
|
||
const mm = this.mermaid;
|
||
const h = mm.home;
|
||
mm.root.x = h.x; mm.root.y = h.y; mm.root.scale = h.scale;
|
||
this.scene.tweens.add({ targets: mm.root, rot: 0, duration: 300 });
|
||
mm.tweenPose({ tailCurl: -2.2, tailAmp: 0.16, tailFreq: 1.8, armL: 0.3, armR: -0.3 }, 600);
|
||
mm.c.setDepth(h.depth);
|
||
mm.swimming = false;
|
||
this.lapTween = null;
|
||
}
|
||
|
||
// ── Hooks ──────────────────────────────────────────────────────────────────
|
||
onReels(view) { this.view = view; }
|
||
|
||
onAttract(on) {
|
||
if (on) { this.lapMs = 20000; this.heartMs = 5000; this.mantaMs = Math.max(this.mantaMs, 14000); }
|
||
else this.comeHome();
|
||
}
|
||
|
||
update(dt) {
|
||
this.t += dt / 1000;
|
||
this.mermaid.solve(dt);
|
||
this.updateFish(dt);
|
||
this.updateJellies(dt);
|
||
this.schoolMs += dt;
|
||
this.mantaMs += dt;
|
||
const att = this.stage.attracting;
|
||
if (this.schoolMs >= (att ? 6000 : 10000)) { this.schoolMs = 0; this.spawnSchool(); }
|
||
if (this.mantaMs >= (att ? 22000 : 45000)) { this.mantaMs = 0; this.mantaGlide(); }
|
||
if (this.stage.busy || !this.view) return;
|
||
this.waveMs += dt;
|
||
if (!att && this.waveMs >= 14000) { this.waveMs = 0; this.mermaid.wave(); this.stage.sound('giggle'); }
|
||
if (att) {
|
||
this.lapMs += dt;
|
||
this.heartMs += dt;
|
||
if (this.lapMs >= 24000) { this.lapMs = 0; this.swimLap(); }
|
||
if (this.heartMs >= 9000 && !this.mermaid.swimming) {
|
||
this.heartMs = 0;
|
||
this.mermaid.say(800);
|
||
for (let k = 0; k < 3; k++) {
|
||
this.scene.time.delayedCall(k * 260, () => this.floatBubble(this.mermaid.world(0, -300), 'heart'));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
onSpinStart() {
|
||
this.pointedThisSpin = false;
|
||
this.setLevel(0, true);
|
||
this.comeHome();
|
||
}
|
||
|
||
onReelStop(c) {
|
||
const view = this.view;
|
||
const grid = this.stage.pendingResult?.grid;
|
||
if (!view || !grid) return;
|
||
const wild = this.m.wild?.symbol;
|
||
grid[c].forEach((s, r) => {
|
||
if (s !== wild) return;
|
||
const p = view.cellCenter(c, r);
|
||
this.scene.fx?.bubbleBurst?.(p.x, p.y, 10);
|
||
if (!this.pointedThisSpin) {
|
||
this.pointedThisSpin = true;
|
||
this.clamFlash();
|
||
this.mermaid.point(p.x, p.y);
|
||
}
|
||
});
|
||
}
|
||
|
||
onLanded(result) {
|
||
if (result?.totalWin > 0 && !result.steps?.some((s) => s.type === 'tumble')) this.mermaid.cheer();
|
||
}
|
||
|
||
onTumble(i) {
|
||
this.setLevel(Math.min(i + 1, this.ladder.length - 1));
|
||
this.mermaid.say(600);
|
||
this.floatBubble(this.mermaid.world(0, -300), 'note');
|
||
this.stage.sound('sing');
|
||
if (i >= 1) this.mermaid.cheer();
|
||
}
|
||
|
||
onBigMoment() {
|
||
this.mermaid.twirl();
|
||
const p = this.mermaid.world(0, -200);
|
||
this.scene.fx?.bubbleBurst?.(p.x, p.y, 24);
|
||
}
|
||
|
||
shutdown() {}
|
||
}
|