Compare commits
2 Commits
036298227f
...
4b6593b074
| Author | SHA1 | Date |
|---|---|---|
|
|
4b6593b074 | |
|
|
19620c10d4 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -23,6 +23,9 @@
|
|||
"cybro-upset-03",
|
||||
"cybro-upset-04",
|
||||
"cybro-upset-05"
|
||||
],
|
||||
"pick": [
|
||||
"cybro-pick"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
@ -78,6 +81,9 @@
|
|||
"victor-upset-03",
|
||||
"victor-upset-04",
|
||||
"victor-upset-05"
|
||||
],
|
||||
"pick": [
|
||||
"victor-pick"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
@ -104,6 +110,9 @@
|
|||
"croc-upset-03",
|
||||
"croc-upset-04",
|
||||
"croc-upset-05"
|
||||
],
|
||||
"pick": [
|
||||
"croc-pick"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
@ -123,6 +132,9 @@
|
|||
"upset": [
|
||||
"mario-upset-01",
|
||||
"mario-upset-02"
|
||||
],
|
||||
"pick": [
|
||||
"mario-upset-01"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
@ -149,6 +161,9 @@
|
|||
"ethel-upset-03",
|
||||
"ethel-upset-04",
|
||||
"ethel-upset-05"
|
||||
],
|
||||
"pick": [
|
||||
"ethel-pick"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
@ -175,6 +190,9 @@
|
|||
"jeff-upset-03",
|
||||
"jeff-upset-04",
|
||||
"jeff-upset-05"
|
||||
],
|
||||
"pick": [
|
||||
"jeff-pick"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
@ -230,6 +248,9 @@
|
|||
"fireball-upset-03",
|
||||
"fireball-upset-04",
|
||||
"fireball-upset-05"
|
||||
],
|
||||
"pick": [
|
||||
"fireball-pick"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
@ -249,6 +270,9 @@
|
|||
"upset": [
|
||||
"bernie-upset-01",
|
||||
"bernie-upset-02"
|
||||
],
|
||||
"pick": [
|
||||
"bernie-happy-01"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,12 @@ export const RESOURCE_BAG = [
|
|||
// 18 number chits for the 18 non-desert hexes.
|
||||
export const CHIT_BAG = [2, 3, 3, 4, 4, 5, 5, 6, 6, 8, 8, 9, 9, 10, 10, 11, 11, 12];
|
||||
|
||||
// Hex IDs visited in the standard Catan clockwise spiral (outer ring → inner ring → centre).
|
||||
// Rows [3,4,5,4,3] assign IDs left-to-right, top-to-bottom: 0-2, 3-6, 7-11, 12-15, 16-18.
|
||||
export const CHIT_SPIRAL = [0, 1, 2, 6, 11, 15, 18, 17, 16, 12, 7, 3, 4, 5, 10, 14, 13, 8, 9];
|
||||
// Standard chit values A–R placed in spiral order; desert hex is skipped when assigning.
|
||||
export const CHIT_SEQUENCE = [5, 2, 6, 3, 8, 10, 9, 12, 11, 4, 8, 10, 9, 4, 5, 6, 3, 11];
|
||||
|
||||
// 9 ports: 4 generic 3:1, one 2:1 per resource.
|
||||
export const PORT_BAG = ['any', 'any', 'any', 'any', 'brick', 'lumber', 'wool', 'grain', 'ore'];
|
||||
|
||||
|
|
|
|||
|
|
@ -254,7 +254,7 @@ export default class CatanGame extends Phaser.Scene {
|
|||
fontFamily: '"Julius Sans One"', fontSize: '14px', color: COLORS.mutedHex,
|
||||
}).setOrigin(0, 0.5).setDepth(D.hud);
|
||||
|
||||
// cost legend (right, above buttons)
|
||||
// cost legend (bottom bar, right of dice)
|
||||
this.buildCostLegend();
|
||||
|
||||
// action buttons (vertical column, right)
|
||||
|
|
@ -273,19 +273,45 @@ export default class CatanGame extends Phaser.Scene {
|
|||
}
|
||||
|
||||
buildCostLegend() {
|
||||
const x = 1600, y = 230;
|
||||
const panelRight = 1900;
|
||||
const panelW = 320;
|
||||
const cx = panelRight - panelW / 2;
|
||||
const bgCy = 980, bgH = 164;
|
||||
|
||||
const panel = this.add.container(0, 0).setDepth(D.hud);
|
||||
panel.add(this.add.rectangle(x, y + 80, 180, 200, 0x000000, 0.3).setStrokeStyle(1, COLORS.accent, 0.5));
|
||||
panel.add(this.add.text(x, y - 4, 'Build Costs', { fontFamily: 'Righteous', fontSize: '16px', color: COLORS.goldHex }).setOrigin(0.5));
|
||||
const lines = [
|
||||
['Road', 'Brick Lumber'],
|
||||
['Settle', 'Br Lu Wo Gr'],
|
||||
['City', '2 Grain 3 Ore'],
|
||||
['Dev', 'Wool Grain Ore'],
|
||||
panel.add(this.add.rectangle(cx, bgCy, panelW, bgH, 0x000000, 0.3).setStrokeStyle(1, COLORS.accent, 0.5));
|
||||
panel.add(this.add.text(cx, bgCy - bgH / 2 + 7, 'Build Costs', {
|
||||
fontFamily: 'Righteous', fontSize: '20px', color: COLORS.goldHex,
|
||||
}).setOrigin(0.5, 0));
|
||||
|
||||
const rows = [
|
||||
{ name: 'Road', resources: ['brick', 'lumber'] },
|
||||
{ name: 'Settlement', resources: ['brick', 'lumber', 'wool', 'grain'] },
|
||||
{ name: 'City', resources: ['grain', 'grain', 'ore', 'ore', 'ore'] },
|
||||
{ name: 'Dev Card', resources: ['wool', 'grain', 'ore'] },
|
||||
];
|
||||
lines.forEach((ln, i) => {
|
||||
panel.add(this.add.text(x - 78, y + 30 + i * 38, ln[0], { fontFamily: '"Julius Sans One"', fontSize: '15px', color: COLORS.textHex }).setOrigin(0, 0.5));
|
||||
panel.add(this.add.text(x - 78, y + 48 + i * 38, ln[1], { fontFamily: '"Julius Sans One"', fontSize: '12px', color: COLORS.mutedHex }).setOrigin(0, 0.5));
|
||||
|
||||
const lx = panelRight - panelW + 14;
|
||||
const rx = panelRight - 14;
|
||||
const rowY0 = bgCy - bgH / 2 + 44;
|
||||
const rowStep = (bgH - 44 - 14) / (rows.length - 1);
|
||||
const SW = 16, SH = 16, SG = 4, SR = 3; // swatch w/h/gap/radius
|
||||
|
||||
const g = this.add.graphics();
|
||||
panel.add(g);
|
||||
|
||||
rows.forEach(({ name, resources }, i) => {
|
||||
const ry = rowY0 + i * rowStep;
|
||||
panel.add(this.add.text(lx, ry, name, {
|
||||
fontFamily: '"Julius Sans One"', fontSize: '19px', color: COLORS.textHex,
|
||||
}).setOrigin(0, 0.5));
|
||||
const totalW = resources.length * SW + (resources.length - 1) * SG;
|
||||
let sx = rx - totalW;
|
||||
for (const r of resources) {
|
||||
g.fillStyle(RESOURCE_INFO[r].swatch, 1);
|
||||
g.fillRoundedRect(sx, ry - SH / 2, SW, SH, SR);
|
||||
sx += SW + SG;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@
|
|||
|
||||
import {
|
||||
NODES, EDGES, HEXES, PORT_SLOTS, edgeBetween,
|
||||
RESOURCE_BAG, CHIT_BAG, PORT_BAG, COSTS, DEV_DECK, RESOURCE_TYPES, WIN_VP,
|
||||
RESOURCE_BAG, PORT_BAG, COSTS, DEV_DECK, RESOURCE_TYPES, WIN_VP,
|
||||
CHIT_SPIRAL, CHIT_SEQUENCE,
|
||||
} from './CatanBoard.js';
|
||||
|
||||
// ── small utilities ─────────────────────────────────────────────────────────
|
||||
|
|
@ -26,16 +27,6 @@ export function handSize(player) {
|
|||
return RESOURCE_TYPES.reduce((s, r) => s + player.resources[r], 0);
|
||||
}
|
||||
|
||||
// Hex adjacency (share an edge → share 2 corner nodes).
|
||||
const HEX_NEIGHBORS = HEXES.map(() => []);
|
||||
for (const e of EDGES) {
|
||||
if (e.hexes.length === 2) {
|
||||
const [h1, h2] = e.hexes;
|
||||
if (!HEX_NEIGHBORS[h1].includes(h2)) HEX_NEIGHBORS[h1].push(h2);
|
||||
if (!HEX_NEIGHBORS[h2].includes(h1)) HEX_NEIGHBORS[h2].push(h1);
|
||||
}
|
||||
}
|
||||
|
||||
// ── occupancy queries ────────────────────────────────────────────────────────
|
||||
export function nodeBuilding(state, nodeId) {
|
||||
for (const p of state.players) {
|
||||
|
|
@ -65,21 +56,12 @@ export function createInitialState(playerCount = 3) {
|
|||
const desertHex = hexes.find((h) => h.resource === 'desert');
|
||||
desertHex.hasRobber = true;
|
||||
|
||||
// Number chits onto non-desert hexes, 6/8 never adjacent.
|
||||
const nonDesert = hexes.filter((h) => h.resource !== 'desert');
|
||||
for (let attempt = 0; attempt < 500; attempt++) {
|
||||
const chits = shuffle(CHIT_BAG);
|
||||
nonDesert.forEach((h, i) => { h.number = chits[i]; });
|
||||
let ok = true;
|
||||
for (const h of nonDesert) {
|
||||
if (h.number !== 6 && h.number !== 8) continue;
|
||||
for (const nb of HEX_NEIGHBORS[h.id]) {
|
||||
const other = hexes[nb];
|
||||
if (other.number === 6 || other.number === 8) { ok = false; break; }
|
||||
}
|
||||
if (!ok) break;
|
||||
// Number chits: walk the standard spiral, skip desert, assign fixed sequence A–R.
|
||||
let chitIdx = 0;
|
||||
for (const hexId of CHIT_SPIRAL) {
|
||||
if (hexes[hexId].resource !== 'desert') {
|
||||
hexes[hexId].number = CHIT_SEQUENCE[chitIdx++];
|
||||
}
|
||||
if (ok) break;
|
||||
}
|
||||
|
||||
// Port types onto fixed slots.
|
||||
|
|
@ -109,10 +91,9 @@ export function createInitialState(playerCount = 3) {
|
|||
});
|
||||
}
|
||||
|
||||
// Snake setup order: 0..n-1 then n-1..0.
|
||||
const order = [];
|
||||
for (let s = 0; s < n; s++) order.push(s);
|
||||
for (let s = n - 1; s >= 0; s--) order.push(s);
|
||||
// Snake setup order: randomized forward then reverse.
|
||||
const seats = shuffle([...Array(n).keys()]);
|
||||
const order = [...seats, ...[...seats].reverse()];
|
||||
|
||||
return {
|
||||
playerCount: n,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import * as Phaser from 'phaser';
|
||||
import { GAME_HEIGHT, GAME_WIDTH, COLORS } from '../config.js';
|
||||
import { Button } from '../ui/Button.js';
|
||||
import { playMenuMusic, stopMenuMusic } from '../ui/MenuMusic.js';
|
||||
import { playMenuMusic, stopMenuMusic, setMenuMusicVolume } from '../ui/MenuMusic.js';
|
||||
import { enqueue as enqueueSpeech, resetQueue as resetSpeechQueue } from '../ui/SpeechQueue.js';
|
||||
|
||||
// Option tile dimensions — playfield rows
|
||||
const TILE_W = 190;
|
||||
|
|
@ -30,10 +31,12 @@ export default class OpponentSelectScene extends Phaser.Scene {
|
|||
this.playfieldTiles = [];
|
||||
this.selectedCardBack = null;
|
||||
this.cardBackTiles = [];
|
||||
this._initializing = false;
|
||||
}
|
||||
|
||||
async create() {
|
||||
playMenuMusic();
|
||||
setMenuMusicVolume(0.25);
|
||||
const cx = GAME_WIDTH / 2;
|
||||
|
||||
const bgKey = this.gameDef.category === 'casino' ? 'bg-casino' : 'bg-room';
|
||||
|
|
@ -90,7 +93,15 @@ export default class OpponentSelectScene extends Phaser.Scene {
|
|||
this.buildOpponentGrid(opponents);
|
||||
|
||||
const max = this.gameDef.maxOpponents ?? 1;
|
||||
this._initializing = true;
|
||||
this.cards.slice(0, max).forEach(({ opp, el }) => this.toggleOpponent(opp, el));
|
||||
this._initializing = false;
|
||||
|
||||
this.events.once('shutdown', () => {
|
||||
resetSpeechQueue();
|
||||
this.cards.forEach(c => c.destroyViz?.());
|
||||
if (!this._startingGame) setMenuMusicVolume(0.6);
|
||||
});
|
||||
|
||||
this.buildOptionSection('Playfield', 630, this.cache.json.get('playfields')?.playfields ?? [],
|
||||
'selectedPlayfield', 'playfieldTiles', (pf) => this.selectPlayfield(pf));
|
||||
|
|
@ -228,8 +239,71 @@ export default class OpponentSelectScene extends Phaser.Scene {
|
|||
canvas.style.display = 'block';
|
||||
});
|
||||
|
||||
// Spectrum visualizer canvas — overlays portrait when pick audio plays
|
||||
const vizCanvas = document.createElement('canvas');
|
||||
vizCanvas.width = portraitSize;
|
||||
vizCanvas.height = portraitSize;
|
||||
vizCanvas.style.cssText = `position:absolute;top:0;left:0;width:${portraitSize}px;height:${portraitSize}px;border-radius:50%;pointer-events:none;opacity:0;transition:opacity 0.2s ease;`;
|
||||
const vizCtx = vizCanvas.getContext('2d');
|
||||
const vsz = portraitSize;
|
||||
const BAR_COUNT = 6;
|
||||
const bars = Array.from({ length: BAR_COUNT }, () => ({ cur: 0.1, target: 0.5 }));
|
||||
let vizActive = false;
|
||||
let rafId = null;
|
||||
let retargetTimer = null;
|
||||
|
||||
function _vizFrame() {
|
||||
if (!vizActive) { rafId = null; vizCtx.clearRect(0, 0, vsz, vsz); return; }
|
||||
vizCtx.clearRect(0, 0, vsz, vsz);
|
||||
const gy = vsz * 0.58;
|
||||
const grad = vizCtx.createLinearGradient(0, gy, 0, vsz);
|
||||
grad.addColorStop(0, 'rgba(0,0,0,0)');
|
||||
grad.addColorStop(1, 'rgba(0,0,0,0.38)');
|
||||
vizCtx.fillStyle = grad;
|
||||
vizCtx.fillRect(0, gy, vsz, vsz - gy);
|
||||
const barW = vsz * 0.072;
|
||||
const gap = vsz * 0.03;
|
||||
const totalW = BAR_COUNT * barW + (BAR_COUNT - 1) * gap;
|
||||
const startX = (vsz - totalW) / 2;
|
||||
const maxH = vsz * 0.36;
|
||||
const baseY = vsz * 0.88;
|
||||
bars.forEach((bar, i) => {
|
||||
bar.cur += (bar.target - bar.cur) * 0.14;
|
||||
const h = Math.max(bar.cur * maxH, vsz * 0.04);
|
||||
const x = startX + i * (barW + gap);
|
||||
vizCtx.shadowColor = 'rgba(0,200,255,0.7)';
|
||||
vizCtx.shadowBlur = 5;
|
||||
vizCtx.fillStyle = 'rgba(0,200,255,0.88)';
|
||||
vizCtx.beginPath();
|
||||
vizCtx.roundRect(x, baseY - h, barW, h, 2);
|
||||
vizCtx.fill();
|
||||
});
|
||||
vizCtx.shadowBlur = 0;
|
||||
rafId = requestAnimationFrame(_vizFrame);
|
||||
}
|
||||
|
||||
function startViz() {
|
||||
vizActive = true;
|
||||
vizCanvas.style.opacity = '1';
|
||||
if (!retargetTimer) retargetTimer = setInterval(() => { bars.forEach(b => { b.target = 0.2 + Math.random() * 0.8; }); }, 120);
|
||||
if (!rafId) rafId = requestAnimationFrame(_vizFrame);
|
||||
}
|
||||
|
||||
function stopViz() {
|
||||
vizActive = false;
|
||||
vizCanvas.style.opacity = '0';
|
||||
clearInterval(retargetTimer);
|
||||
retargetTimer = null;
|
||||
}
|
||||
|
||||
function destroyViz() {
|
||||
stopViz();
|
||||
if (rafId) { cancelAnimationFrame(rafId); rafId = null; }
|
||||
}
|
||||
|
||||
portraitWrap.appendChild(canvas);
|
||||
portraitWrap.appendChild(video);
|
||||
portraitWrap.appendChild(vizCanvas);
|
||||
|
||||
// Text block
|
||||
const info = document.createElement('div');
|
||||
|
|
@ -268,7 +342,7 @@ export default class OpponentSelectScene extends Phaser.Scene {
|
|||
|
||||
el.addEventListener('click', () => this.toggleOpponent(opp, el));
|
||||
|
||||
this.cards.push({ opp, el, canvas, video });
|
||||
this.cards.push({ opp, el, canvas, video, startViz, stopViz, destroyViz });
|
||||
return el;
|
||||
}
|
||||
|
||||
|
|
@ -281,10 +355,12 @@ export default class OpponentSelectScene extends Phaser.Scene {
|
|||
this.applyOpponentStyle(el, false);
|
||||
const card = this.cards.find((c) => c.opp.id === opp.id);
|
||||
if (card) {
|
||||
card.stopViz();
|
||||
card.video.pause();
|
||||
card.video.style.display = 'none';
|
||||
card.canvas.style.display = 'block';
|
||||
}
|
||||
resetSpeechQueue();
|
||||
} else {
|
||||
// If already at max, bump the oldest selection out first
|
||||
if (this.selected.size >= max) {
|
||||
|
|
@ -292,6 +368,7 @@ export default class OpponentSelectScene extends Phaser.Scene {
|
|||
this.selected.delete(oldestId);
|
||||
const oldCard = this.cards.find((c) => c.opp.id === oldestId);
|
||||
if (oldCard) {
|
||||
oldCard.stopViz();
|
||||
this.applyOpponentStyle(oldCard.el, false);
|
||||
oldCard.video.pause();
|
||||
oldCard.video.style.display = 'none';
|
||||
|
|
@ -309,6 +386,16 @@ export default class OpponentSelectScene extends Phaser.Scene {
|
|||
card.canvas.style.display = 'block';
|
||||
});
|
||||
}
|
||||
if (!this._initializing) {
|
||||
const pickClips = opp.speech?.pick;
|
||||
if (pickClips?.length) {
|
||||
resetSpeechQueue();
|
||||
enqueueSpeech(pickClips[Math.floor(Math.random() * pickClips.length)], {
|
||||
onStart: () => this.cards.find(c => c.opp.id === opp.id)?.startViz(),
|
||||
onEnd: () => this.cards.find(c => c.opp.id === opp.id)?.stopViz(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
this.startBtn.setEnabled(this.selected.size >= min);
|
||||
}
|
||||
|
|
@ -422,6 +509,7 @@ export default class OpponentSelectScene extends Phaser.Scene {
|
|||
|
||||
startGame() {
|
||||
if (this.selected.size === 0) return;
|
||||
this._startingGame = true;
|
||||
stopMenuMusic();
|
||||
const opponents = this.cards
|
||||
.filter(({ opp }) => this.selected.has(opp.id))
|
||||
|
|
|
|||
|
|
@ -18,3 +18,7 @@ export function playMenuMusic() {
|
|||
export function stopMenuMusic() {
|
||||
if (_audio) _audio.pause();
|
||||
}
|
||||
|
||||
export function setMenuMusicVolume(vol) {
|
||||
_getAudio().volume = vol;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue