A real-time multiplayer 2D platformer game built with Next.js and Firebase where players can explore and jump across platforms together in a large scrolling world.
- Real-time multiplayer synchronization using Firebase Firestore
- Create and join game rooms with unique room codes
- 2D platformer gameplay with gravity and jumping
- Large scrolling map (2400x1200) with camera following
- Position interpolation for smooth multiplayer movement
- Multiple platforms at different heights to explore
- Keyboard controls (Arrow Keys/WASD to move, Space to jump)
- Each player gets a unique emoji and color
- Players flip direction when moving left/right
- Debug mode showing player positions and IDs
npm install- Go to Firebase Console
- Create a new project (or select an existing one)
- Click on "Web" icon to add a web app
- Copy the Firebase configuration values
- In Firebase Console, go to "Firestore Database"
- Click "Create Database"
- Choose "Start in test mode" (for development)
- Select a location and create
-
Copy
.env.local.exampleto.env.local:cp .env.local.example .env.local
-
Edit
.env.localand add your Firebase credentials:NEXT_PUBLIC_FIREBASE_API_KEY=your_api_key NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_project_id.firebaseapp.com NEXT_PUBLIC_FIREBASE_PROJECT_ID=your_project_id NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your_project_id.appspot.com NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your_sender_id NEXT_PUBLIC_FIREBASE_APP_ID=your_app_id
npm run devOpen http://localhost:3000 in your browser.
- Create a Room: Click "Create New Room" to start a new game
- Share Room Code: Copy the room code from the URL and share it with friends
- Join a Room: Enter a room code and click "Join"
- Move Around: Use Arrow Keys or A/D to move left and right
- Jump: Press Space, W, or Up Arrow to jump on platforms
- Explore: The camera follows you as you explore the large map
- Play Together: See other players in real-time as you all explore the map
- Move Left: Left Arrow or A
- Move Right: Right Arrow or D
- Jump: Space, Up Arrow, or W
- Push your code to GitHub
- Go to Vercel
- Import your repository
- Add your environment variables in Vercel dashboard
- Deploy
Before deploying to production, update your Firestore security rules:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /rooms/{roomId}/players/{playerId} {
allow read: if true;
allow write: if request.auth == null;
allow delete: if request.auth == null;
}
}
}- Next.js 16 - React framework
- TypeScript - Type safety
- Tailwind CSS - Styling
- Firebase Firestore - Real-time database
- Vercel - Deployment platform
├── app/
│ ├── game/
│ │ └── page.tsx # Platformer with camera scrolling and multiplayer
│ ├── layout.tsx # Root layout
│ ├── page.tsx # Home page (create/join room)
│ └── globals.css # Global styles
├── lib/
│ └── firebase.ts # Firebase configuration
└── .env.local # Environment variables (create from .env.local.example)
- Camera System: Smooth camera follows the player, keeping them centered while respecting map boundaries
- Collision Detection: Platform collision checks player bounds against all platforms in the map
- Interpolation: Other players' positions are smoothly interpolated for lag compensation
- Firebase Optimization: Position updates throttled to 200ms to stay within free tier limits
- Efficient Rendering: Only renders players and platforms visible on screen
- Platformer Mechanics: Gravity-based physics with jumping
- Large Scrolling Map: 2400x1200 pixel world with camera following player
- Multiple Platforms: Over 30 platforms at different heights to explore
- Position Interpolation: Smooth rendering of other players' movements
- Real-time Sync: Player positions update across all clients
- Client-side Prediction: Local player uses immediate updates for responsive controls
- Debug Mode: Shows player count, IDs, and positions for troubleshooting
ISC