logo

Babylon.js Market

By Lawrence

5 minutes

The betting engine runs as pure data. It holds the stacks, the pot, and a pointer to whose turn it is. But right now there is nothing to bet on. The table needs a deck, so that is what we build next. Cards are the first thing the chip machine has been waiting for. A harder question hides under that one. Soon this becomes a four-seat game, and every player runs the same code on their own machine. So how do all four agree on the exact same shuffle? Get that wrong, and one player sees the ace of spades while another sees a seven.

This lesson adds the deck. It builds no meshes and draws nothing on screen. Instead, it makes card ids as strings and announces each one over the bus. That sounds small. But the way it shuffles is the key to the whole multiplayer story.

A dealer's hands sending a fanned stream of glossy playing cards arcing across an emerald-green felt table, several cards caught mid-flight toward seats around the rim, a freshly shuffled deck stacked at center, faint glowing numbered arrows tracing the round-robin deal order from seat to seat, warm overhead light, near-black surround.

Add the Dealer to the scene

Open src/scenes/poker.json and add one entity next to Felt:

src/scenes/poker.json
"Dealer": {
  "components": {
    "DeckDealer": {
      "playerCount": 4,
      "cardsPerPlayer": 2,
      "riverSize": 5,
      "localIndex": 0,
      "roomCode": "table-7",
      "handNumber": 0
    }
  }
}

The component source already lives at src/components/DeckDealer/. Lesson 1's bjs download scene PokerTableDirector --all pulled it in. These settings spell out Texas Hold'em. playerCount: 4 and cardsPerPlayer: 2 mean four seats with two hole cards each. riverSize: 5 is the community row. localIndex: 0 marks which seat is yours. And roomCode: "table-7" is the interesting one — it is half of a seed.

Continue reading

Unlock the Full Course

Every lesson, the runnable examples, and the finished build — yours to keep.

$9one-time

Was this page helpful?

We read every note — tell us what's working and what isn't.

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search