A real-time multiplayer online battle arena (MOBA) game built with MapLibre GL, Phaser.js, Django, and MQTT for state synchronization.
- Real-time Multiplayer: MQTT-based networking for instant state synchronization
- Geospatial Gameplay: Maps based on real-world GeoJSON data with isometric view
- Multiple Hero Types: Warriors, Rangers, Mages, and Support classes
- Django Admin Interface: Manage all game aspects (maps, heroes, sessions) via admin panel
- Interactive Gameplay: Click-to-move controls, real-time combat, objectives
- Team-based: Red vs Blue team battles with bases, towers, and objectives
- MapLibre GL JS: Rendering geospatial maps with isometric perspective
- Phaser 3: Game entities, sprites, animations, and physics
- MQTT.js: Real-time message synchronization
- Vanilla JavaScript: Lightweight client-side logic
- Django 4.2+: Web framework and ORM
- Django REST Framework: RESTful API endpoints
- Paho MQTT: Python MQTT client
- SQLite: Database (easily swappable to PostgreSQL)
┌─────────────────────────────────────────────────────┐
│ Browser Client │
│ ┌──────────────┐ ┌──────────────┐ ┌───────────┐ │
│ │ MapLibre GL │ │ Phaser.js │ │ MQTT.js │ │
│ │ (Map Layer) │ │ (Entities) │ │ (Sync) │ │
│ └──────────────┘ └──────────────┘ └───────────┘ │
└─────────────────────────────────────────────────────┘
↕ WebSocket
┌─────────────────────────────────────────────────────┐
│ MQTT Broker │
│ (Mosquitto / EMQX) │
└─────────────────────────────────────────────────────┘
↕ MQTT
┌─────────────────────────────────────────────────────┐
│ Django Backend │
│ ┌──────────────┐ ┌──────────────┐ ┌───────────┐ │
│ │ REST API │ │ Game Logic │ │ Admin UI │ │
│ │ (DRF) │ │ (Models) │ │ │ │
│ └──────────────┘ └──────────────┘ └───────────┘ │
└─────────────────────────────────────────────────────┘
- Python 3.9+
- Node.js (optional, for development)
- MQTT Broker (Mosquitto recommended)
sudo apt-get update
sudo apt-get install mosquitto mosquitto-clients
sudo systemctl enable mosquitto
sudo systemctl start mosquittobrew install mosquitto
brew services start mosquittodocker run -d -p 1883:1883 -p 9001:9001 eclipse-mosquitto# Clone repository
git clone <repository-url>
cd browser-moba
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Create .env file
cp .env.example .env
# Edit .env with your settings
# Run migrations
python manage.py migrate
# Load sample data
python manage.py loaddata game/fixtures/sample_data.json
# Create superuser
python manage.py createsuperuser
# Collect static files
python manage.py collectstatic --noinputpython manage.py runserverVisit:
- Game: http://localhost:8000/
- Admin: http://localhost:8000/admin/
- API: http://localhost:8000/api/
MQTT_BROKER=localhost
MQTT_PORT=1883
MQTT_USERNAME=
MQTT_PASSWORD=
MQTT_KEEPALIVE=60Edit moba_game/settings.py:
# Game tick rate (updates per second)
GAME_TICK_RATE = 30
# Map boundaries
GAME_MAP_BOUNDS = {
'min_lat': 37.7,
'max_lat': 37.8,
'min_lng': -122.5,
'max_lng': -122.4,
}Access the admin interface at /admin/ to manage:
- Game Maps: Create and edit GeoJSON-based maps
- Hero Types: Define hero classes with stats
- Game Sessions: Create and manage active game sessions
- Players: View player stats and positions
- Buildings: Place towers, bases, and structures
- Objectives: Add map objectives and rewards
- Game Events: View game history and analytics
- Go to Admin → Game Maps → Add Game Map
- Enter map details (name, description, center coordinates)
- Add GeoJSON data with features:
- Bases: Points with
type: "base",team: "red|blue" - Lanes: LineStrings with
type: "lane" - Jungle: Polygons with
type: "jungle" - Objectives: Points with reward data
- Bases: Points with
Example GeoJSON:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "Red Base",
"type": "base",
"team": "red"
},
"geometry": {
"type": "Point",
"coordinates": [-122.430, 37.780]
}
}
]
}- Left Click: Move hero to location
- Right Click: Attack/Interact (planned)
- Q/W/E/R: Use abilities (planned)
- Enter: Open chat
- Tab: View scoreboard (planned)
- Lobby: Players join a game session and select heroes
- Selection: Choose hero type and team
- Battle: Fight enemy players and destroy objectives
- Victory: Destroy enemy base to win
moba/session/{session_id}/state- Full game state updatesmoba/session/{session_id}/player/{player_id}- Player-specific updatesmoba/session/{session_id}/events- Game events (kills, objectives)moba/session/{session_id}/chat- Chat messages
GET /api/maps/- List all mapsGET /api/maps/{id}/- Get map details
GET /api/hero-types/- List all hero typesGET /api/hero-types/{id}/- Get hero details
GET /api/sessions/- List active sessionsGET /api/sessions/{id}/- Get session detailsPOST /api/sessions/{id}/join/- Join a sessionPOST /api/sessions/{id}/start/- Start a session
GET /api/players/- List playersPOST /api/players/{id}/move/- Update player position
browser-moba/
├── moba_game/ # Django project settings
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── game/ # Main game app
│ ├── models.py # Data models
│ ├── admin.py # Admin interface
│ ├── views.py # API views
│ ├── serializers.py # DRF serializers
│ ├── mqtt_client.py # MQTT client
│ └── fixtures/ # Sample data
├── templates/ # HTML templates
│ └── index.html
├── static/ # Static files
│ └── js/
│ └── game.js # Main game client
├── requirements.txt
└── README.md
- New Hero Type: Admin → Hero Types → Add
- New Ability: Extend
HeroTypemodel and add logic - New Building Type: Add to
Building.BUILDING_TYPES - New Event Type: Add to
GameEvent.EVENT_TYPES
# Run Django tests
python manage.py test
# Check MQTT connection
mosquitto_sub -t "moba/#" -v- Set
DEBUG=Falsein.env - Configure
ALLOWED_HOSTS - Use PostgreSQL instead of SQLite
- Set up proper MQTT broker (not test.mosquitto.org)
- Use Nginx/Apache for static files
- Use Gunicorn/uWSGI for Django
# Build image
docker build -t moba-game .
# Run with Docker Compose
docker-compose up -d- Player abilities and cooldowns
- Combat system with damage calculations
- AI-controlled minions
- Experience and leveling system
- Item shop and inventory
- Match replay system
- Ranked matchmaking
- Mobile responsive design
- WebRTC voice chat
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
MIT License - See LICENSE file for details
- MapLibre GL JS: https://maplibre.org/
- Phaser 3: https://phaser.io/
- Django: https://www.djangoproject.com/
- MQTT: https://mqtt.org/
For issues and questions:
- GitHub Issues: [Create an issue]
- Documentation: [Wiki]
- Community: [Discord/Forum]