Two-device game with peer-to-peer WebRTC communication. Draw levels on your phone, play on your laptop!
- ๐จ Draw your own levels - Sketch platforms and obstacles with your phone camera
- ๐ฎ Real-time gameplay - Control your character directly from your phone
- ๐ก Peer-to-peer - Direct phone-to-laptop connection via WebRTC data channels
- ๐ No server needed - Fully decentralized, works anywhere
- ๐ผ๏ธ Image processing - OpenCV.js converts drawings into playable levels
- ๐น๏ธ Touch controls - Responsive mobile controller with haptic feedback
- โก Fast & reliable - Low-latency P2P communication
| Technology | Purpose |
|---|---|
| JavaScript | Core game logic |
| HTML/CSS | User interface |
| WebRTC | Peer-to-peer networking |
| PeerJS | Simplified WebRTC API |
| Phaser 3 | Game engine & physics |
| OpenCV.js | Computer vision & image processing |
| QRCode.js | Easy phone connection |
- Modern web browser (Chrome, Firefox, Safari, Edge)
- Node.js & npm (for local development)
- Phone and laptop
# 1. Clone the repository
git clone https://github.com/Rayaanxrio/Drawit.git
cd Drawit
# 2. Install dependencies
npm install
# 3. Start local development server
npm run devThe server will start on http://localhost:3000
- Open
http://localhost:3000/index.htmlin your browser - Wait for peer ID to generate (QR code will appear)
- Keep this window open
- Scan the QR code with your phone camera
- Or manually open the URL shown below the QR code
- Wait for connection (status chip will turn green โ)
- Tap "PLAY GAME"
- Point camera at your drawing and capture
- Adjust corner markers to frame your level
- Tap "SEND LEVEL"
- Use on-screen controls to play!
- Black marker โ Platforms (safe to land on)
- Red marker โ Danger zones (instant game over)
- Use thick, bold strokes for best detection
- Draw on clean white surface (whiteboard, paper, etc.)
- Ensure good lighting without glare
Platforms (Black):
- Stairs and ramps
- Floating islands
- Curved paths
- Ladders
- Trampolines
Dangers (Red):
- Spike pits
- Lava pools
- Moving obstacles
- Barriers
| Button | Action |
|---|---|
| โ LEFT | Move character left |
| โถ RIGHT | Move character right |
| โฒ JUMP | Jump (hold to move while in air) |
- Navigate from bottom-left (spawn point) to explore your level
- Land on black platforms to stay safe
- Avoid red danger zones or it's game over!
- Design creative levels and share with friends
drawit-p2p/
โโโ public/
โ โโโ index.html # Laptop game interface
โ โโโ phone.html # Mobile controller interface
โ โโโ peer.js # WebRTC P2P wrapper
โ โโโ game.js # Phaser game engine
โ โโโ image-processor.js # OpenCV shape detection
โ โโโ style.css # Styling
โโโ package.json # Dependencies
โโโ README.md # This file
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ Phone โ โ Laptop โ
โ โ โ โ
โ โข Camera โโโโWebRTC Data Channelโโโโบโ โข Game โ
โ โข Controls โ (PeerJS Signaling) โ โข Display โ
โ โ โ โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
- Laptop: Generates unique peer ID via PeerJS
- Laptop: Displays peer ID in QR code
- Phone: Scans QR code to get peer ID
- Phone: Connects to laptop using peer ID
- P2P: Direct data channel established
- Phone: Captures image โ sends via data channel
- Laptop: Processes image with OpenCV.js
- Laptop: Builds Phaser game level
- Phone: Sends controller inputs
- Laptop: Updates game in real-time
Image Transfer:
- Images are chunked into 16KB packets (WebRTC limit)
- Sent sequentially via reliable data channel
- Reassembled on laptop side
- Processed with perspective transform
Controller Inputs:
- Sent as JSON messages:
{ action: 'left-start' } - Low latency (~10-50ms typical)
- Reliable delivery guaranteed
Problem: QR code doesn't appear
- Solution: Wait a few seconds for PeerJS to connect to signaling server
- Check browser console for errors
Problem: Phone can't connect to laptop
- Solution: Ensure both devices are on the same network
- Try refreshing both pages
- Check firewall settings
Problem: "Missing peer ID in URL" error
- Solution: Make sure you scanned the complete QR code
- Or manually type the full URL with
?peer=parameter
Problem: Shapes not detected
- Use thicker marker strokes
- Improve lighting (avoid shadows/glare)
- Lower "Min Area" in debug settings
- Clean the drawing surface
Problem: Too much noise detected
- Increase "Min Area" to filter small marks
- Increase "Blur Size" for smoother detection
- Clean the whiteboard completely
Problem: Shapes too simplified
- Lower "Epsilon Factor" to preserve detail
- Use bolder, more defined shapes
Problem: Game lags or stutters
- Draw fewer/simpler shapes
- Increase "Epsilon Factor" to simplify polygons
- Close other browser tabs
- Try a different device
Deploy to any static hosting service:
Vercel:
npm install -g vercel
vercelNetlify:
npm install -g netlify-cli
netlify deployGitHub Pages:
- Push to GitHub repository
- Enable GitHub Pages in Settings
- Select main branch / root folder
By default, the app uses the free PeerJS cloud server (0.peerjs.com). For production or privacy, you can run your own:
Option 1: Use PeerJS Cloud (Default)
- No setup needed
- Free tier available
- May have rate limits
Option 2: Self-hosted PeerJS Server
Install and run:
npm install -g peer
peerjs --port 9000 --key peerjs --path /myappUpdate public/peer.js:
const PEER_CONFIG = {
host: 'your-server.com',
secure: true,
port: 9000,
path: '/myapp',
debug: 2
};| Browser | Laptop | Phone | Notes |
|---|---|---|---|
| Chrome | โ | โ | Best performance |
| Firefox | โ | โ | Fully supported |
| Safari | โ | โ | iOS 14+ |
| Edge | โ | โ | Chromium-based |
Camera Access Requirements:
- HTTPS connection (or localhost)
- Camera permission granted
- Modern browser version
Contributions are welcome! Here's how:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- PeerJS - Simplified WebRTC API
- Phaser - Excellent game engine
- OpenCV.js - Powerful computer vision
- QRCode.js - Easy QR code generation
Ideas for future development:
- Multiple color support (blue=ice, green=bouncy)
- Level saving and sharing
- Multiplayer racing mode
- Power-ups and collectibles
- Animated platforms
- Shape recognition (auto-detect circles, rectangles)
- Level editor with touch drawing
- Leaderboard and scoring
Having issues? Here's how to get help:
- Check the Troubleshooting section
- Look at browser console for errors
- Open an issue on GitHub
- Join our community discussions
If you find this project useful, please consider giving it a star on GitHub!
Built with โค๏ธ using WebRTC and modern web technologies
๐ฎ Have fun creating and playing your own levels! โจ