Compare commits

..

2 Commits

Author SHA1 Message Date
Brian Fertig 72dea52f49 feat(farkel): add header/shelf panels and enhance score display
- Extract header into buildHeader() with black background panel and depth layering
- Add background panel to shelf area with accent border
- Adjust shelf dice positioning to align with new panel
- Show pending +selected score during awaitPick phase in scratch pad
2026-06-06 19:20:38 -06:00
Brian Fertig 6aa331cf97 fix: correct game spelling to "Farkle" and add Catan-style dice animation
- Rename "Farkel" to "Farkle" in UI title and server game registry
- Replace tumble animation with new animateDice method featuring:
  - Dice thrown from elevated position with arc trajectory
  - Random face cycling while airborne
  - Bounce landing with per-die staggered timing
  - Spin and scale animations
  - Squash-bounce effect on final die
- Refactor die rendering to use containers for transform animations
2026-06-06 18:44:25 -06:00
2 changed files with 139 additions and 33 deletions

View File

@ -84,12 +84,7 @@ export default class FarkelGame extends Phaser.Scene {
}
this.gs = createInitialState({ playerCount, names, skills });
this.add.text(TRAY_CX, 56, 'Farkel', {
fontFamily: 'Righteous', fontSize: '60px', color: COLORS.textHex,
}).setOrigin(0.5);
this.statusText = this.add.text(TRAY_CX, 128, '', {
fontFamily: '"Julius Sans One"', fontSize: '26px', color: COLORS.accentHex,
}).setOrigin(0.5);
this.buildHeader();
this.buildTray();
this.buildDice();
@ -116,6 +111,26 @@ export default class FarkelGame extends Phaser.Scene {
}
}
buildHeader() {
const titleText = this.add.text(TRAY_CX, 56, 'Farkle', {
fontFamily: 'Righteous', fontSize: '60px', color: COLORS.textHex,
}).setOrigin(0.5).setDepth(DEPTH.panel + 1);
this.statusText = this.add.text(TRAY_CX, 128, '', {
fontFamily: '"Julius Sans One"', fontSize: '26px', color: COLORS.accentHex,
}).setOrigin(0.5).setDepth(DEPTH.panel + 2);
// Fixed-size panel (wide enough for longest status messages)
const pw = 680;
const ph = 160;
const panel = this.add.graphics().setDepth(DEPTH.panel + 1);
panel.fillStyle(0x000000, 0.75);
panel.fillRoundedRect(TRAY_CX - pw / 2, 10, pw, ph, 12);
panel.lineStyle(3, COLORS.accent, 1);
panel.strokeRoundedRect(TRAY_CX - pw / 2, 10, pw, ph, 12);
this.headerPanel = panel;
this.headerTitle = titleText;
}
buildTray() {
// Felt throwing area.
const g = this.add.graphics().setDepth(DEPTH.panel);
@ -134,18 +149,34 @@ export default class FarkelGame extends Phaser.Scene {
const x = DICE_LEFT + i * (DIE + DIE_GAP);
const y = TRAY_CY;
const g = this.add.graphics().setDepth(DEPTH.die);
const c = this.add.container(x, y, [g]).setDepth(DEPTH.die);
const hit = this.add.zone(x, y, DIE, DIE).setOrigin(0.5).setDepth(DEPTH.dieSel);
hit.setInteractive({ useHandCursor: true });
hit.on('pointerdown', () => this.onDieClick(i));
this.dieEls.push({ g, hit, cx: x, cy: y });
this.dieEls.push({ g, hit, cx: x, cy: y, c });
}
}
buildShelf() {
this.shelfGfx = this.add.graphics().setDepth(DEPTH.die);
this.add.text(TRAY_CX - TRAY_W / 2, SHELF_Y - SDIE / 2 - 24, 'Set aside this turn', {
fontFamily: '"Julius Sans One"', fontSize: '16px', color: COLORS.mutedHex,
}).setOrigin(0, 0.5);
// Background panel for the shelf area
const shelfLeft = TRAY_CX - TRAY_W / 2 + 4;
const shelfW = DICE * (SDIE + SDIE_GAP) + 12;
const shelfH = SDIE + 70;
const shelfX = shelfLeft;
const shelfY = SHELF_Y - SDIE / 2 - 46;
const shelfPanel = this.add.graphics().setDepth(DEPTH.die - 1);
shelfPanel.fillStyle(0x000000, 0.55);
shelfPanel.fillRoundedRect(shelfX, shelfY, shelfW, shelfH, 8);
shelfPanel.lineStyle(2, COLORS.accent, 0.6);
shelfPanel.strokeRoundedRect(shelfX, shelfY, shelfW, shelfH, 8);
this.shelfPanel = shelfPanel;
// Text on top of panel
this.add.text(TRAY_CX - TRAY_W / 2 + 20, SHELF_Y - SDIE / 2 - 24, 'Set aside this turn', {
fontFamily: '"Julius Sans One"', fontSize: '16px', color: COLORS.textHex,
}).setOrigin(0, 0.5).setDepth(DEPTH.die);
}
buildScoringPanel() {
@ -276,12 +307,97 @@ export default class FarkelGame extends Phaser.Scene {
}
}
// Catan-style dice throw animation
animateDice(values) {
return new Promise((resolve) => {
playSound(this, SFX.DICE_ROLL);
const n = values.length; // only animate the dice actually being rolled
const landX = this.dieEls.slice(0, n).map((el) => el.cx);
const landY = TRAY_CY;
const startX = TRAY_CX;
const startY = TRAY_CY + 120;
const arcY = TRAY_CY - 200;
// Hide unused dice containers
for (let i = n; i < DICE; i++) this.dieEls[i].c.setVisible(false);
// Move rolling dice to throw origin, small, random angle
for (let i = 0; i < n; i++) {
const el = this.dieEls[i];
el.c.setVisible(true).setAlpha(0.25).setScale(0.35).setAngle(Phaser.Math.Between(0, 359))
.setPosition(startX + (i - (n - 1) / 2) * 18, startY);
this.drawDie(el.g, 0, 0, DIE, Phaser.Math.Between(1, 6));
}
// Cycle random faces while airborne
let cyclerStopped = false;
const cycler = this.time.addEvent({
delay: 55, loop: true,
callback: () => {
for (let i = 0; i < n; i++) {
this.drawDie(this.dieEls[i].g, 0, 0, DIE, Phaser.Math.Between(1, 6));
}
},
});
const stopCycler = () => { if (!cyclerStopped) { cyclerStopped = true; cycler.remove(); } };
let settled = 0;
for (let i = 0; i < n; i++) {
const el = this.dieEls[i];
const lx = landX[i] + (Math.random() * 10 - 5);
const ly = landY + (Math.random() * 10 - 5);
const outMs = 320 + i * 28;
const backMs = 460 + i * 40;
const totalMs = outMs + backMs;
// X flies straight to landing; Y arcs up then bounces down
this.tweens.add({ targets: el.c, x: lx, duration: totalMs, ease: 'Quad.Out' });
this.tweens.chain({
targets: el.c, tweens: [
{ y: arcY, duration: outMs, ease: 'Quad.Out' },
{ y: ly, duration: backMs, ease: 'Bounce.Out' },
]
});
// Scale up as die approaches
this.tweens.add({ targets: el.c, scale: 1, duration: outMs + backMs * 0.55, ease: 'Quad.Out' });
// Spin
this.tweens.add({
targets: el.c,
angle: el.c.angle + 540 + Math.random() * 180,
duration: totalMs,
ease: 'Quad.Out',
});
this.time.delayedCall(totalMs, () => {
stopCycler();
this.drawDie(el.g, 0, 0, DIE, values[i]);
// Snap to nearest upright angle with a small wiggle
const upright = Math.round(el.c.angle / 90) * 90 + (Math.random() * 10 - 5);
this.tweens.add({
targets: el.c, angle: upright, duration: 120, ease: 'Back.Out',
onComplete: () => {
el.c.setAlpha(1);
settled++;
if (settled === n) {
// Little squash-bounce on last die
for (let j = 0; j < n; j++)
this.tweens.add({ targets: this.dieEls[j].c, scaleX: 1.12, scaleY: 0.88, duration: 80, yoyo: true });
this.time.delayedCall(160, resolve);
}
},
});
});
}
});
}
renderDice() {
const rolled = this.gs.turn.rolled;
for (let i = 0; i < DICE; i++) {
const el = this.dieEls[i];
if (i < rolled.length) {
this.drawDie(el.g, el.cx, el.cy, DIE, rolled[i], { selected: this.selected.has(i) });
this.drawDie(el.g, 0, 0, DIE, rolled[i], { selected: this.selected.has(i) });
el.hit.setInteractive({ useHandCursor: true });
} else {
el.g.clear();
@ -294,7 +410,7 @@ export default class FarkelGame extends Phaser.Scene {
const g = this.shelfGfx;
g.clear();
const dice = this.gs.turn.setAsideDice;
const startX = TRAY_CX - TRAY_W / 2 + SDIE / 2 + 4;
const startX = TRAY_CX - TRAY_W / 2 + SDIE / 2 + 24;
for (let i = 0; i < dice.length; i++) {
const x = startX + i * (SDIE + SDIE_GAP);
this.paintDie(g, x, SHELF_Y, SDIE, dice[i], { locked: true });
@ -306,8 +422,14 @@ export default class FarkelGame extends Phaser.Scene {
for (let seat = 0; seat < this.scratchRows.length; seat++) {
const p = this.gs.players[seat];
const row = this.scratchRows[seat];
const showTurn = (seat === cur && !isGameOver(this.gs) && this.gs.turn.kept > 0);
row.score.setText(showTurn ? `${p.score} +${this.gs.turn.kept}` : String(p.score));
const hasPending = this.gs.turn.kept > 0 || (this.gs.phase === 'awaitPick' && this.selectionScore() > 0);
const showTurn = (seat === cur && !isGameOver(this.gs) && hasPending);
if (showTurn) {
const sel = (this.gs.phase === 'awaitPick') ? this.selectionScore() : 0;
row.score.setText(`${p.score} +${this.gs.turn.kept + sel}`);
} else {
row.score.setText(String(p.score));
}
row.star.setVisible(p.onBoard);
}
// Underline the active player's row.
@ -436,29 +558,13 @@ export default class FarkelGame extends Phaser.Scene {
async rollAnimated() {
this.busy = true;
this.updateControls();
playSound(this, SFX.DICE_ROLL);
rollDice(this.gs);
await this.tumble();
const values = this.gs.turn.rolled;
await this.animateDice(values);
this.render();
this.busy = false;
}
tumble() {
const n = this.gs.turn.rolled.length;
return new Promise((resolve) => {
this.tweens.addCounter({
from: 0, to: 1, duration: 520, ease: 'Quad.Out',
onUpdate: () => {
for (let i = 0; i < n; i++) {
const el = this.dieEls[i];
this.drawDie(el.g, el.cx, el.cy, DIE, 1 + Math.floor(Math.random() * 6), {});
}
},
onComplete: resolve,
});
});
}
async afterRoll() {
if (this.gs.phase === 'farkled') {
await this.farkleFx();

View File

@ -70,4 +70,4 @@ registerGame({ slug: 'solitairetour', name: 'Solitaire Tour', category: 'c
registerGame({ slug: 'splendor', name: 'Splendor', category: 'cards', cardGame: true, minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 41 });
registerGame({ slug: 'labyrinth', name: 'Labyrinth', category: 'tabletop', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 43 });
registerGame({ slug: 'videopoker', name: 'Video Poker', category: 'casino', cardGame: true, minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 44 });
registerGame({ slug: 'farkel', name: 'Farkel', category: 'tabletop', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 45 });
registerGame({ slug: 'farkel', name: 'Farkle', category: 'tabletop', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 45 });