Commit a01bee1c authored by Mahmoud Aglan's avatar Mahmoud Aglan

feat(ludo): FULL REWRITE — proper board path, dice animation, player panels

Complete Ludo game overhaul:
- NEW: board-map.js with exact 52-square path coordinates on 15x15 grid
- Pieces now move on CORRECT squares (not random circular positions)
- Home columns, safe squares (stars), home bases all properly mapped
- Dice roll ANIMATION: 10 frames of random faces with rotation
- Dice slam-in effect + star burst on rolling 6
- 4 player panels showing whose turn it is (active border glow)
- Proper game flow: roll → valid moves → auto-pick best → animate
- Bot turns show dice face updates
- Capture: screen shake + heavy haptic
- Finish: star burst + success haptic
- Win: confetti + celebration
- Board rendering: colored home zones, grid lines, home columns,
  safe squares with stars, center triangles, piece shadows + highlights
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent fed41bb4
// Ludo Board Map — exact grid coordinates for all 52 shared squares + home columns
// Board is 15x15 grid. Each position is [col, row] from top-left (0,0)
// The 52 shared squares, numbered 0-51, going clockwise from red's start
export const SHARED_PATH = [
[6,1],[6,2],[6,3],[6,4],[6,5], // 0-4: top column going down
[5,6],[4,6],[3,6],[2,6],[1,6],[0,6], // 5-10: left row going left
[0,7], // 11: left corner
[0,8],[1,8],[2,8],[3,8],[4,8],[5,8], // 12-17: left row going right
[6,9],[6,10],[6,11],[6,12],[6,13],[6,14], // 18-23: bottom column going down
[7,14], // 24: bottom corner
[8,14],[8,13],[8,12],[8,11],[8,10],[8,9], // 25-30: bottom column going up
[9,8],[10,8],[11,8],[12,8],[13,8],[14,8], // 31-36: right row going right
[14,7], // 37: right corner
[14,6],[13,6],[12,6],[11,6],[10,6],[9,6], // 38-43: right row going left
[8,5],[8,4],[8,3],[8,2],[8,1],[8,0], // 44-49: top column going up
[7,0], // 50: top corner
[6,0], // 51: back to start area
];
// Starting squares for each player (where they enter the board)
export const START_SQUARES = [1, 14, 27, 40]; // Red, Blue, Green, Yellow
// Home column paths (6 squares each, going toward center)
export const HOME_COLUMNS = [
[[7,1],[7,2],[7,3],[7,4],[7,5],[7,6]], // Red: top going down
[[1,7],[2,7],[3,7],[4,7],[5,7],[6,7]], // Blue: left going right
[[7,13],[7,12],[7,11],[7,10],[7,9],[7,8]], // Green: bottom going up
[[13,7],[12,7],[11,7],[10,7],[9,7],[8,7]], // Yellow: right going left
];
// Home entry points (the square BEFORE entering home column)
export const HOME_ENTRY = [0, 13, 26, 39]; // The square just before home column
// Safe squares (stars) — pieces can't be captured here
export const SAFE_SQUARES = [0, 8, 13, 21, 26, 34, 39, 47];
// Home base positions (where pieces sit before entering the board)
export const HOME_BASES = [
[[2,2],[4,2],[2,4],[4,4]], // Red (top-left)
[[10,2],[12,2],[10,4],[12,4]], // Blue (top-right)
[[10,10],[12,10],[10,12],[12,12]], // Green (bottom-right)
[[2,10],[4,10],[2,12],[4,12]], // Yellow (bottom-left)
];
// Convert a board grid position [col,row] to pixel coordinates
export function gridToPixel(col, row, cellSize) {
return {
x: col * cellSize + cellSize / 2,
y: row * cellSize + cellSize / 2
};
}
// Get the pixel position for a piece given its game state
export function getPiecePosition(localPos, playerIdx, cellSize) {
if (localPos === -1) return null; // In home base — handled separately
if (localPos >= 52) {
// In home column
const homeIdx = localPos - 52;
if (homeIdx < 6) {
const [col, row] = HOME_COLUMNS[playerIdx][homeIdx];
return gridToPixel(col, row, cellSize);
}
return gridToPixel(7, 7, cellSize); // Finished — center
}
// On shared path — convert local position to global
const globalPos = (localPos + START_SQUARES[playerIdx]) % 52;
const [col, row] = SHARED_PATH[globalPos];
return gridToPixel(col, row, cellSize);
}
// Get home base pixel position for a piece still at home
export function getHomeBasePosition(playerIdx, pieceIdx, cellSize) {
const [col, row] = HOME_BASES[playerIdx][pieceIdx];
return gridToPixel(col, row, cellSize);
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment