The frustrating part was that these bugs only showed up with multiple real players. Can't reproduce them locally, can't easily test fixes, and adding logging changes the timing enough that bugs disappear.
After rebuilding networking code for the third time across different projects, I noticed something: most multiplayer bugs come from thinking about networking instead of game logic.
## The approach
In single-player games, you just write: ```typescript player.x += velocity.x; player.health -= 10; ```
So I built martini-kit to make multiplayer work the same way:
```typescript const game = defineGame({ setup: ({ playerIds }) => ({ players: Object.fromEntries( playerIds.map(id => [id, { x: 100, y: 100, health: 100 }]) ) }),
actions: {
move: (state, { playerId, dx, dy }) => {
state.players[playerId].x += dx;
state.players[playerId].y += dy;
}
}
});
```That's it. No WebSockets, no serialization, no message handlers. martini-kit handles state sync, conflict resolution, connection handling, and message ordering automatically.
## How it works
Instead of thinking about messages, you think about state changes:
1. Define pure functions that transform state 2. One client is the "host" and runs the authoritative game loop 3. Host broadcasts state diffs (bandwidth optimized) 4. Clients patch their local state 5. Conflicts default to host-authoritative (customizable)
Those race conditions and ordering bugs are structurally impossible with this model.
## What's it good for
- Turn-based games, platformers, racing games, co-op games: works well - Fast-paced FPS with 60Hz tick rates: not ideal yet - Phaser adapter included, Unity/Godot adapters in progress - Works with P2P (WebRTC) or client-server (WebSocket) - Can integrate with Colyseus/Nakama/etc for matchmaking and auth
## Try it
[Interactive playground](https://martini.blueprintlab.io/preview) - test multiplayer instantly in your browser
Or install: ```bash npm install @martini-kit/core @martini-kit/phaser phaser ```
Links: - Website: https://martini.blueprintlab.io/ - Docs: https://martini.blueprintlab.io/docs - GitHub: https://github.com/BlueprintLabIO/martini - npm: https://www.npmjs.com/package/@martini-kit/core
Open to feedback and curious if anyone else has hit similar issues with multiplayer state management.