Compare commits
No commits in common. "4644b8e3af25e6fc734631e973b57549b7836c0b" and "7602da4cbeb8e5f1cc4112fad56178f70c809d68" have entirely different histories.
4644b8e3af
...
7602da4cbe
|
|
@ -99,7 +99,6 @@ export default class MexicanTrainGame extends Phaser.Scene {
|
||||||
|
|
||||||
this.trackGfx = this.add.graphics().setDepth(DEPTH.tile);
|
this.trackGfx = this.add.graphics().setDepth(DEPTH.tile);
|
||||||
this.bandGfx = this.add.graphics().setDepth(DEPTH.band);
|
this.bandGfx = this.add.graphics().setDepth(DEPTH.band);
|
||||||
this.railGfx = this.add.graphics().setDepth(DEPTH.spine);
|
|
||||||
this.spineGfx = this.add.graphics().setDepth(DEPTH.spine);
|
this.spineGfx = this.add.graphics().setDepth(DEPTH.spine);
|
||||||
this.hubGfx = this.add.graphics().setDepth(DEPTH.hub);
|
this.hubGfx = this.add.graphics().setDepth(DEPTH.hub);
|
||||||
this.markerGfx = this.add.graphics().setDepth(DEPTH.tileFx);
|
this.markerGfx = this.add.graphics().setDepth(DEPTH.tileFx);
|
||||||
|
|
@ -203,7 +202,6 @@ export default class MexicanTrainGame extends Phaser.Scene {
|
||||||
// ─── Render ───────────────────────────────────────────────────────────
|
// ─── Render ───────────────────────────────────────────────────────────
|
||||||
refresh() {
|
refresh() {
|
||||||
this.paintBands();
|
this.paintBands();
|
||||||
this.paintRails();
|
|
||||||
this.paintSpineAndHub();
|
this.paintSpineAndHub();
|
||||||
this.paintTracks();
|
this.paintTracks();
|
||||||
this.paintMarkers();
|
this.paintMarkers();
|
||||||
|
|
@ -216,7 +214,6 @@ export default class MexicanTrainGame extends Phaser.Scene {
|
||||||
`Round ${this.gs.round + 1} • Engine ${hub}-${hub} • First to ${this.gs.target} ends it — lowest score wins`,
|
`Round ${this.gs.round + 1} • Engine ${hub}-${hub} • First to ${this.gs.target} ends it — lowest score wins`,
|
||||||
);
|
);
|
||||||
this.updateBoneyard();
|
this.updateBoneyard();
|
||||||
this.updateScoreBadges();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
paintBands() {
|
paintBands() {
|
||||||
|
|
@ -227,33 +224,11 @@ export default class MexicanTrainGame extends Phaser.Scene {
|
||||||
for (let i = 0; i < rows; i++) {
|
for (let i = 0; i < rows; i++) {
|
||||||
const y = this.rowY(i);
|
const y = this.rowY(i);
|
||||||
const active = i < this.gs.players.length && i === this.gs.current;
|
const active = i < this.gs.players.length && i === this.gs.current;
|
||||||
g.fillStyle(0x0c1a10, active ? 0.55 : 0.92);
|
g.fillStyle(active ? COLORS.accent : COLORS.panel, active ? 0.16 : 0.5);
|
||||||
g.fillRoundedRect(TRACKS_LEFT - 8, y - gap / 2 + 4, TRACKS_RIGHT - TRACKS_LEFT + 16, gap - 8, 10);
|
g.fillRoundedRect(TRACKS_LEFT - 8, y - gap / 2 + 4, TRACKS_RIGHT - TRACKS_LEFT + 16, gap - 8, 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
paintRails() {
|
|
||||||
const g = this.railGfx;
|
|
||||||
g.clear();
|
|
||||||
const rows = this.gs.players.length + 1;
|
|
||||||
const railOff = 11; // px from lane center to each rail
|
|
||||||
const tieHalf = 15; // tie extends 4px beyond each rail
|
|
||||||
const tieStep = 22; // horizontal spacing between ties
|
|
||||||
|
|
||||||
for (let i = 0; i < rows; i++) {
|
|
||||||
const y = this.rowY(i);
|
|
||||||
// Ties (wood) — drawn first so rails appear on top
|
|
||||||
g.lineStyle(4, 0x4a3018, 0.55);
|
|
||||||
for (let x = TRACKS_LEFT; x <= TRACKS_RIGHT; x += tieStep) {
|
|
||||||
g.lineBetween(x, y - tieHalf, x, y + tieHalf);
|
|
||||||
}
|
|
||||||
// Rails (metal)
|
|
||||||
g.lineStyle(2.5, 0x908060, 0.7);
|
|
||||||
g.lineBetween(TRACKS_LEFT, y - railOff, TRACKS_RIGHT, y - railOff);
|
|
||||||
g.lineBetween(TRACKS_LEFT, y + railOff, TRACKS_RIGHT, y + railOff);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
paintSpineAndHub() {
|
paintSpineAndHub() {
|
||||||
const g = this.spineGfx;
|
const g = this.spineGfx;
|
||||||
g.clear();
|
g.clear();
|
||||||
|
|
@ -277,62 +252,29 @@ export default class MexicanTrainGame extends Phaser.Scene {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the horizontal half-width a tile occupies when painted.
|
|
||||||
tileHalfW(tile) {
|
|
||||||
return tile.left === tile.right ? TRACK_HALF / 2 : TRACK_HALF;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns { start, positions[] } for the visible slice of a train.
|
|
||||||
// Positions are the x-centres of each visible tile (index start..end).
|
|
||||||
computeTrackLayout(key) {
|
|
||||||
const tiles = this.gs.trains[key].tiles;
|
|
||||||
if (tiles.length === 0) return { start: 0, positions: [] };
|
|
||||||
const GAP = 6;
|
|
||||||
const TRUNC = 16; // px reserved for the "+N«" truncation mark
|
|
||||||
const avail = TRACKS_RIGHT - TRACKS_LEFT;
|
|
||||||
|
|
||||||
// Walk backwards to find the first tile that still fits.
|
|
||||||
let accumulated = 0;
|
|
||||||
let start = tiles.length;
|
|
||||||
for (let t = tiles.length - 1; t >= 0; t--) {
|
|
||||||
const addW = (start < tiles.length ? GAP : 0) + this.tileHalfW(tiles[t]) * 2;
|
|
||||||
if (accumulated + addW > avail - (t > 0 ? TRUNC : 0)) break;
|
|
||||||
accumulated += addW;
|
|
||||||
start = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build centre-x positions for each visible tile.
|
|
||||||
const positions = [];
|
|
||||||
let x = TRACKS_LEFT + (start > 0 ? TRUNC : 0) + this.tileHalfW(tiles[start]);
|
|
||||||
for (let t = start; t < tiles.length; t++) {
|
|
||||||
positions.push(x);
|
|
||||||
if (t < tiles.length - 1) {
|
|
||||||
x += this.tileHalfW(tiles[t]) + GAP + this.tileHalfW(tiles[t + 1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return { start, positions };
|
|
||||||
}
|
|
||||||
|
|
||||||
paintTracks() {
|
paintTracks() {
|
||||||
const g = this.trackGfx;
|
const g = this.trackGfx;
|
||||||
g.clear();
|
g.clear();
|
||||||
const rows = this.gs.players.length + 1;
|
const rows = this.gs.players.length + 1;
|
||||||
|
const maxTiles = Math.floor((TRACKS_RIGHT - TRACKS_LEFT) / TRACK_PITCH);
|
||||||
for (let i = 0; i < rows; i++) {
|
for (let i = 0; i < rows; i++) {
|
||||||
const key = this.rowKeyFor(i);
|
const key = this.rowKeyFor(i);
|
||||||
const y = this.rowY(i);
|
const y = this.rowY(i);
|
||||||
const tiles = this.gs.trains[key].tiles;
|
const tiles = this.gs.trains[key].tiles;
|
||||||
if (tiles.length === 0) { this.clearTruncMark(i); continue; }
|
const start = Math.max(0, tiles.length - maxTiles);
|
||||||
|
let drawX = TRACKS_LEFT + TRACK_HALF;
|
||||||
const { start, positions } = this.computeTrackLayout(key);
|
if (start > 0) {
|
||||||
if (start > 0) this.maybeTruncMark(i, start); else this.clearTruncMark(i);
|
this.maybeTruncMark(i, start);
|
||||||
|
drawX += 8;
|
||||||
for (let ti = 0; ti < positions.length; ti++) {
|
} else {
|
||||||
const t = start + ti;
|
this.clearTruncMark(i);
|
||||||
|
}
|
||||||
|
for (let t = start; t < tiles.length; t++) {
|
||||||
const tile = tiles[t];
|
const tile = tiles[t];
|
||||||
const isDouble = tile.left === tile.right;
|
|
||||||
const isOpenDouble = this.gs.openDouble?.train === key && t === tiles.length - 1;
|
const isOpenDouble = this.gs.openDouble?.train === key && t === tiles.length - 1;
|
||||||
const border = isOpenDouble ? COLORS.danger : (isDouble ? COLORS.gold : COLORS.accent);
|
const border = isOpenDouble ? COLORS.danger : (tile.left === tile.right ? COLORS.gold : COLORS.accent);
|
||||||
this.paintDomino(g, positions[ti], y, TRACK_HALF, tile.left, tile.right, isDouble, border);
|
this.paintDomino(g, drawX, y, TRACK_HALF, tile.left, tile.right, false, border);
|
||||||
|
drawX += TRACK_PITCH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -363,10 +305,7 @@ export default class MexicanTrainGame extends Phaser.Scene {
|
||||||
if (!this.gs.trains[key].marker) continue;
|
if (!this.gs.trains[key].marker) continue;
|
||||||
const y = this.rowY(i);
|
const y = this.rowY(i);
|
||||||
const tiles = this.gs.trains[key].tiles;
|
const tiles = this.gs.trains[key].tiles;
|
||||||
const { positions } = this.computeTrackLayout(key);
|
const x = TRACKS_LEFT + TRACK_HALF + Math.min(tiles.length, Math.floor((TRACKS_RIGHT - TRACKS_LEFT) / TRACK_PITCH)) * TRACK_PITCH + 6;
|
||||||
const lastPos = positions.length ? positions[positions.length - 1] : TRACKS_LEFT;
|
|
||||||
const lastHW = tiles.length ? this.tileHalfW(tiles[tiles.length - 1]) : TRACK_HALF;
|
|
||||||
const x = lastPos + lastHW + 6;
|
|
||||||
// little open-train flag
|
// little open-train flag
|
||||||
g.fillStyle(COLORS.danger, 1);
|
g.fillStyle(COLORS.danger, 1);
|
||||||
g.fillCircle(x, y, 9);
|
g.fillCircle(x, y, 9);
|
||||||
|
|
@ -438,49 +377,6 @@ export default class MexicanTrainGame extends Phaser.Scene {
|
||||||
this.updateHandDots();
|
this.updateHandDots();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateScoreBadges() {
|
|
||||||
const scores = this.gs.players.map(p => p.score);
|
|
||||||
if (scores.every(s => s === 0)) {
|
|
||||||
this._scoreBadgeCtrs?.forEach(c => c.destroy());
|
|
||||||
this._scoreBadgeCtrs = [];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const changed = !this._lastBadgeScores || scores.some((s, i) => s !== this._lastBadgeScores[i]);
|
|
||||||
if (!changed) return;
|
|
||||||
this._lastBadgeScores = [...scores];
|
|
||||||
|
|
||||||
this._scoreBadgeCtrs?.forEach(c => c.destroy());
|
|
||||||
this._scoreBadgeCtrs = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < this.gs.players.length; i++) {
|
|
||||||
const score = scores[i];
|
|
||||||
const x = PORTRAIT_X + Math.round(PORTRAIT_R * 0.85);
|
|
||||||
const y = this.rowY(i) - Math.round(PORTRAIT_R * 0.85);
|
|
||||||
const borderColor = score > 75 ? COLORS.danger
|
|
||||||
: score > 50 ? 0xe07030
|
|
||||||
: score > 25 ? COLORS.accent
|
|
||||||
: COLORS.gold;
|
|
||||||
|
|
||||||
const c = this.add.container(x, y).setDepth(DEPTH.portrait + 2).setScale(0.1);
|
|
||||||
const g = this.add.graphics();
|
|
||||||
g.fillStyle(0x1e1a30, 1);
|
|
||||||
g.fillCircle(0, 0, 22);
|
|
||||||
g.lineStyle(2.5, borderColor, 1);
|
|
||||||
g.strokeCircle(0, 0, 22);
|
|
||||||
g.lineStyle(1.5, 0xffffff, 0.25);
|
|
||||||
g.strokeCircle(0, 0, 17);
|
|
||||||
|
|
||||||
const fontSize = score >= 100 ? '11px' : '14px';
|
|
||||||
const t = this.add.text(0, 0, String(score), {
|
|
||||||
fontFamily: '"Julius Sans One"', fontSize, color: COLORS.textHex, fontStyle: 'bold',
|
|
||||||
}).setOrigin(0.5);
|
|
||||||
|
|
||||||
c.add([g, t]);
|
|
||||||
this._scoreBadgeCtrs.push(c);
|
|
||||||
this.tweens.add({ targets: c, scale: 1, duration: 260, ease: 'Back.Out' });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateHandDots() {
|
updateHandDots() {
|
||||||
if (!this._handDotGfx) return;
|
if (!this._handDotGfx) return;
|
||||||
const n = this.gs.players.length;
|
const n = this.gs.players.length;
|
||||||
|
|
@ -711,19 +607,15 @@ export default class MexicanTrainGame extends Phaser.Scene {
|
||||||
// ─── Effects ──────────────────────────────────────────────────────────
|
// ─── Effects ──────────────────────────────────────────────────────────
|
||||||
flashTrainEnd(key) {
|
flashTrainEnd(key) {
|
||||||
const rows = this.gs.players.length + 1;
|
const rows = this.gs.players.length + 1;
|
||||||
const i = key === MEXICAN ? rows - 1 : Number(key);
|
let i = key === MEXICAN ? rows - 1 : Number(key);
|
||||||
const y = this.rowY(i);
|
const y = this.rowY(i);
|
||||||
const tiles = this.gs.trains[key].tiles;
|
const tiles = this.gs.trains[key].tiles;
|
||||||
if (!tiles.length) return;
|
const maxTiles = Math.floor((TRACKS_RIGHT - TRACKS_LEFT) / TRACK_PITCH);
|
||||||
const { positions } = this.computeTrackLayout(key);
|
const shown = Math.min(tiles.length, maxTiles);
|
||||||
const x = positions[positions.length - 1];
|
const x = TRACKS_LEFT + TRACK_HALF + (shown - 1) * TRACK_PITCH;
|
||||||
const lastTile = tiles[tiles.length - 1];
|
|
||||||
const isLastDouble = lastTile.left === lastTile.right;
|
|
||||||
const fw = isLastDouble ? TRACK_HALF : TRACK_TILE_W;
|
|
||||||
const fh = isLastDouble ? TRACK_TILE_W : TRACK_HALF;
|
|
||||||
const fx = this.add.graphics().setDepth(DEPTH.tileFx);
|
const fx = this.add.graphics().setDepth(DEPTH.tileFx);
|
||||||
fx.lineStyle(4, COLORS.gold, 1);
|
fx.lineStyle(4, COLORS.gold, 1);
|
||||||
fx.strokeRoundedRect(x - fw / 2 - 3, y - fh / 2 - 3, fw + 6, fh + 6, 6);
|
fx.strokeRoundedRect(x - TRACK_TILE_W / 2 - 3, y - TRACK_HALF / 2 - 3, TRACK_TILE_W + 6, TRACK_HALF + 6, 6);
|
||||||
this.tweens.add({ targets: fx, alpha: { from: 1, to: 0 }, duration: 500, onComplete: () => fx.destroy() });
|
this.tweens.add({ targets: fx, alpha: { from: 1, to: 0 }, duration: 500, onComplete: () => fx.destroy() });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -732,18 +624,14 @@ export default class MexicanTrainGame extends Phaser.Scene {
|
||||||
const i = key === MEXICAN ? rows - 1 : Number(key);
|
const i = key === MEXICAN ? rows - 1 : Number(key);
|
||||||
const y = this.rowY(i);
|
const y = this.rowY(i);
|
||||||
const tiles = this.gs.trains[key].tiles;
|
const tiles = this.gs.trains[key].tiles;
|
||||||
if (tiles.length === 0) return { x: TRACKS_LEFT + TRACK_HALF, y };
|
const maxTiles = Math.floor((TRACKS_RIGHT - TRACKS_LEFT) / TRACK_PITCH);
|
||||||
const { positions } = this.computeTrackLayout(key);
|
const newIdx = Math.min(tiles.length, maxTiles - 1);
|
||||||
const lastX = positions[positions.length - 1];
|
return { x: TRACKS_LEFT + TRACK_HALF + newIdx * TRACK_PITCH, y };
|
||||||
const lastHW = this.tileHalfW(tiles[tiles.length - 1]);
|
|
||||||
const nextX = Math.min(lastX + lastHW + 6 + TRACK_HALF, TRACKS_RIGHT - TRACK_HALF);
|
|
||||||
return { x: nextX, y };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
animateTilePlay(fromX, fromY, toX, toY, tileA, tileB, onComplete) {
|
animateTilePlay(fromX, fromY, toX, toY, tileA, tileB, onComplete) {
|
||||||
const isDouble = tileA === tileB;
|
|
||||||
const g = this.add.graphics().setDepth(DEPTH.tileFx + 2);
|
const g = this.add.graphics().setDepth(DEPTH.tileFx + 2);
|
||||||
this.paintDomino(g, 0, 0, TRACK_HALF, tileA, tileB, isDouble, COLORS.accent);
|
this.paintDomino(g, 0, 0, TRACK_HALF, tileA, tileB, false, COLORS.accent);
|
||||||
g.setPosition(fromX, fromY);
|
g.setPosition(fromX, fromY);
|
||||||
this.tweens.add({
|
this.tweens.add({
|
||||||
targets: g,
|
targets: g,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue