A real-time multiplayer zombie survival game built with vanilla JavaScript and Socket.IO. Players can create or join rooms using join codes and battle waves of zombies together.
- Real-time Multiplayer: Create rooms with unique join codes that friends can use to connect from anywhere
- Optimized Performance: 60 FPS with 100+ enemies using advanced optimization techniques
- Multiple Weapons: Pistol, SMG, Shotgun, Sniper, Grenade Launcher, Flamethrower, and more
- Enemy Variety: Different zombie types including fast zombies, tanks, and bosses
- Power-ups: Health packs, weapon upgrades, speed boosts
- Wave System: Progressively harder waves with more enemies
- Persistent Saves: Local save system for single-player progress
- Open
index.htmldirectly in your browser, or - Run a local server:
python3 -m http.server 8000 # or node server.js - Navigate to
http://localhost:8000
-
Install server dependencies:
cd server npm install -
Start the multiplayer server:
npm start # or for development with auto-reload npm run dev -
Open the game in your browser and press
Mto access multiplayer -
Create or Join a Room:
- Click "Create Room" to generate a 6-character join code
- Share the join code with friends
- Friends click "Join Room" and enter the code
- WASD / Arrow Keys: Move
- Mouse: Aim
- Left Click: Shoot
- Number Keys (1-6): Switch weapons
- M: Open multiplayer menu
- ESC: Pause game
cd server
heroku create your-game-name
heroku config:set CLIENT_URL=https://your-game-domain.com
git push heroku main- Set up Node.js on your server
- Clone the repository
- Configure environment variables in
.env.production - Run with PM2:
npm install -g pm2 pm2 start index.js --name boxhead-server
- Connect your GitHub repository
- Set environment variables in the dashboard
- Deploy automatically on push
-
GitHub Pages (easiest):
- Push to GitHub
- Enable GitHub Pages in repository settings
- Update
multiplayerClient.connect()URL in the code
-
Netlify / Vercel:
- Drop the project folder into their dashboard
- Configure the server URL
- WebSocket Communication: Real-time bidirectional communication using Socket.IO
- Authoritative Server: Server handles all game logic to prevent cheating
- Client Prediction: Smooth gameplay despite network latency
- Delta Compression: Only changes are sent to minimize bandwidth (5-10KB/s per player)
- Binary Serialization: Efficient data encoding for network packets
- Collision System: Integer-based spatial hashing, object pooling, collision layers
- Rendering: Batched draw calls, offscreen canvas caching
- Memory: Pre-allocated object pools to minimize garbage collection
- Network: Binary serialization, delta compression, entity interpolation
See OPTIMIZATIONS.md for detailed performance information.
Create a .env file in the server directory:
PORT=3001
CLIENT_URL=http://localhost:3000
MAX_PLAYERS_PER_ROOM=8
ROOM_CODE_LENGTH=6
TICK_RATE=60Update the server URL in network/multiplayerClient.js:
connect(serverUrl = 'https://your-server-url.com')├── index.html # Main game HTML
├── main.js # Game entry point
├── config.js # Game configuration
├── engine/ # Core engine (rendering, input, game loop)
├── entities/ # Game entities (player, enemies, bullets)
├── systems/ # Game systems (collision, audio, saves)
├── network/ # Multiplayer client code
├── ui/ # User interface components
├── server/ # Multiplayer server
│ ├── index.js # Server entry point
│ └── multiplayer/ # Room management, game sessions
└── OPTIMIZATIONS.md # Performance documentation
- New Weapons: Add to
config.jsand updateplayer.js - New Enemies: Add to
CONFIG.ENEMY_TYPESand updateenemy.js - New Power-ups: Add to
CONFIG.POWERUP_TYPESand updatepowerup.js
- Check that the server is running (
npm startin server directory) - Verify the server URL in the client code
- Check firewall settings for port 3001
- Codes are case-insensitive but must be exact
- Codes expire after 30 minutes of inactivity
- Maximum 8 players per room by default
- Ensure hardware acceleration is enabled in your browser
- Close other demanding applications
- Try reducing the number of particles in
config.js
MIT License - feel free to use this code for your own projects!
Built with ❤️ using vanilla JavaScript and Socket.IO