Skip to content

piqnt/polymatic-example-eight-ball

Repository files navigation

8-Ball Pool - Polymatic Example

Multiplayer 8-Ball pool, implemented using Polymatic framework, Socket.io, Planck/Box2D physics engine, and SVG rendering.

▶ Play Online

Gameplay

The gameplay is simplified eight-ball pool:

  • Solid (black edge) and stipe (white edge) are assigned to players randomly.
  • Two players take turns to play.
  • If a player pockets the cue ball, the turn is passed and the cue ball is placed at the original position.
  • If a player pockets the 8-ball before all their balls, they lose.
  • If a player pockets the 8-ball after all their balls, they win.
  • If a player pockets a ball that is assigned to them, they continue to play, otherwise the turn is passed to the other player.

Architecture Notes

  • Both client-side and server-side are implemented using polymatic middlewares. Some middlewares are only for client-side (i.g. rendering, and room client), some for server-side (i.g. room server), and some can be used in both (i.g. physics simulation). Offline mode uses only browser middlewares, however hen you create a room some middlewares run in the server, and some in the browser.
  • Socket.io is used to communicate between client and server. The server is authoritative and clients only send actions to the server.
  • Creating and joining rooms is handled by lobby-server and lobby-client, which is independent from game and rooms.
  • Games state is not persisted. If the server restarts, all games are lost.

Development

Make sure you have node.js/npm installed.

Install dependencies:

npm install

Run locally for development:

npm run dev

In production first build frontend, then start the server:

npm run build
npm start

About

Multiplayer 8-Ball pool, implemented using Polymatic, Socket.io, Planck/Box2D, and SVG

Topics

Resources

License

Stars

Watchers

Forks