This project is a real-time multiplayer backend for a cooperative survival game.
Players join a room, wait in a lobby, and then survive waves of enemies together. The system is designed to handle multiple rooms with many concurrent players.
-
Room-based multiplayer (max 50 players per room)
-
30-second lobby countdown before game start
-
Cooperative gameplay (players vs enemy waves)
-
2 waves of enemies (10 enemies each)
-
Increasing difficulty per wave
-
Real-time state updates using WebSockets
-
Group-based result:
- WIN → at least one player survives all waves
- LOSE → all players die
Join Room → Lobby (30s) → Game Start → Waves → Result
JOIN_ROOM
JOIN_SUCCESS→ returns roomIdLOBBY_TIMER→ countdown updatesGAME_START→ game beginsGAME_STATE_UPDATE→ real-time statePLAYER_ELIMINATED→ player diesGAME_END→ WIN / LOSE
game-backend/
├── src/
│ ├── server.js
│ ├── gateway/
│ │ └── socketHandler.js
│ ├── rooms/
│ │ ├── room.js
│ │ └── roomManager.js
│ ├── game/
│ │ └── gameEngine.js
│
├── public/
│ └── index.html
│
├── package.json
└── README.md- Node.js
- Socket.IO
- HTML Canvas (for demo UI)
npm install
node src/server.jsOpen:
public/index.html
-
Open multiple tabs in browser
-
Each tab = one player
-
Observe:
- lobby countdown
- wave progression
- player elimination
- final result
- Balances performance and gameplay
- Avoids heavy CPU/network load
- Ensures smooth real-time updates
- Single source of truth
- Prevents inconsistent state
- Simplifies synchronization
- Players cannot join after game starts
- New players are assigned to a new room
- Game runs entirely in memory for speed
This project demonstrates:
- Room-based player grouping
- Real-time state synchronization
- Tick-based simulation loop
- Wave-based enemy system
- Controlled game lifecycle (lobby → game → end)
The implementation validates a scalable and maintainable multiplayer backend design.
- Add player-controlled movement
- Add projectile-based combat
- Add reconnect handling
- Add distributed state (Redis)
- Add matchmaking strategies
Laiba Firdouse