A multiplayer virtual world where users can create avatars, move around in real-time, and have their avatars taken over by AI when they go offline.
- Real-time Multiplayer: Multiple players can join the world simultaneously and see each other move in real-time
- Persistent Avatars: Player positions and facing directions are saved to Supabase and restored on reconnect
- AI Takeover: When a player disconnects, their avatar becomes an AI-controlled robot that continues to exist in the world
- Spectator Mode: Watch-only view at
/watchto observe the world without logging in - Collision System: Players, robots, and walls block each other's movement
- Directional Movement: WASD/Arrow keys control movement with visual facing indicators
- Conversation System: Players and AI robots can request, accept, and engage in real-time conversations with proximity-based initiation.
The project consists of five main components:
Handles user authentication, game rendering, and player input. Connects to WebSocket servers for real-time updates.
- Play Mode (
/play): Interactive gameplay (requires login) - Watch Mode (
/watch): Spectator view (no login required) - Tech: React + TypeScript, Vite, TailwindCSS, Supabase Auth
Manages the live game simulation, player connections, and AI coordination.
- Play Server (port 3001): Handles authenticated player connections
- Watch Server (port 3002): Broadcasts world state to spectators
- Game Loop (10Hz): Processes movement and collision detection
- AI Loop (1Hz): Queries Python API for robot decisions
- Tech: Node.js, TypeScript, WebSockets (
ws), Supabase
Provides AI decision-making and avatar metadata management.
- AI Endpoint (
POST /agent/decision): Returns movement targets for robots - Avatar CRUD: Create, update, and manage avatar profiles
- Tech: FastAPI, SQLite, Supabase Storage
Core game logic used by the realtime server. Ensures deterministic, collision-aware simulation.
- Entity System: Players, Robots, Walls (all 2x2 grid units)
- Action Pipeline: Validates and applies movement/direction changes
- Pathfinding: BFS algorithm for robot navigation
- Tech: Pure TypeScript (no dependencies)
- Authentication: User login/signup
- Database:
user_positionstable stores x, y, facing_x, facing_y - Storage: Avatar sprite images (future feature)
- Node.js v18+ and npm
- Python 3.10+
- Supabase Account (free tier works fine)
- Create a project at supabase.com
- Run the migrations in
supabase/migrations/via the Supabase dashboard SQL editor
Create .env files in the following directories:
realtime-server/.env
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SERVICE_KEY=your-service-role-keyapi/.env
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SERVICE_KEY=your-service-role-keyweb/.env
VITE_SUPABASE_URL=https://your-project.supabase.co
VITE_SUPABASE_ANON_KEY=your-anon-public-keyWhere to find keys: Supabase Dashboard โ Settings โ API
You need 3 terminals running simultaneously:
Terminal 1: Realtime Server (runs on port 3001 & 3002)
cd realtime-server
npm install
npm run devTerminal 2: Python API (runs on port 3003)
cd api
python -m venv venv
.\venv\Scripts\activate # Windows
# source venv/bin/activate # Mac/Linux
pip install -r requirements.txt
python -m app.mainTerminal 3: Web Client (runs on port 3000)
cd web
npm install
npm run dev- Play: http://localhost:3000/play (requires login)
- Watch: http://localhost:3000/watch (no login)
- Click "Sign Up" on the login page
- Enter email and password (Supabase handles this)
- You'll be redirected to the game view
- Use WASD or Arrow Keys to move
UofTHacks-Project/
โโโ web/ # React frontend
โ โโโ src/pages/ # GameView (play) & WatchView (spectator)
โ โโโ src/components/ # Grid, Cell, EntityDot rendering
โ โโโ src/contexts/ # AuthContext for Supabase login
โ
โโโ realtime-server/ # WebSocket game server
โ โโโ src/index.ts # WebSocket server setup
โ โโโ src/game.ts # Game loop & AI loop
โ โโโ src/handlers.ts # Join, move, disconnect logic
โ โโโ src/db.ts # Supabase position persistence
โ
โโโ api/ # Python FastAPI backend
โ โโโ app/main.py # AI decision endpoint
โ โโโ app/database.py # SQLite avatar storage
โ โโโ app/models.py # Pydantic schemas
โ
โโโ world/ # Shared game engine (TypeScript)
โ โโโ engine/world.ts # World class, tick(), Pathfinding, Conversations
โ โโโ actions/ # Movement validation & collision pipeline
โ โโโ entities/ # Player, Robot, Wall definitions
โ โโโ utils/ # Pathfinding, Reservations, Conversations, Flowfields
โ
โโโ supabase/
โโโ migrations/ # Database schema (user_positions)
- Improve UI/UX (currently minimal styling)
- Add avatar customization UI
- Display player names above entities
- Add minimap or zoom controls
- Implement chat system
- Replace random walk with smarter pathfinding
- Add LLM integration for decision-making
- Implement goal-seeking behavior (e.g., patrol, follow player)
- Add personality traits to robots
- Add items or collectibles
- Implement different entity types (NPCs, obstacles)
- Add player interactions (trading, combat)
- Create larger, procedurally generated maps
- Optimize collision detection for larger maps
- Add server-side anti-cheat validation
- Implement room/instance system for scalability
- Add reconnection resilience
- Testing Multiplayer: Open multiple browser tabs to
/playwith different accounts - Debugging: Check browser console (frontend) and terminal logs (servers)
- Hot Reload: All three servers support hot reload during development
- Database: Use Supabase dashboard to inspect
user_positionstable - Ports: Make sure 3000, 3001, 3002, 3003 are available
"EADDRINUSE: address already in use"
- Kill the process:
netstat -ano | findstr :3001thentaskkill /PID <PID> /F
"Supabase credentials not set"
- Verify
.envfiles exist and have correct keys - Restart the server after adding
.env
"Disconnected-Reconnecting" loop
- Check that realtime-server is running
- Verify WebSocket URLs in
GameView.tsxandWatchView.tsx
Each component has its own README with detailed information:
web/README.md- Frontend architecturerealtime-server/README.md- Server logic & AI takeoverapi/README.md- Python API endpointsworld/README.md- Game engine internals