Skip to content

openfantasymap/browser-platformer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

20 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

GeoJSON Platformer - Action RPG Based on Real-World Trips

An innovative multiplayer action-RPG platformer where levels are generated from GeoJSON data representing real-world trips. Transform your travels into playable adventures!

๐ŸŽฎ Features

Authentication & Characters

  • Google OAuth Login: Secure authentication via Google account
  • Multi-Character System: Each player can create up to 3 unique characters
  • Character Progression: Each character has independent stats, inventory, and progress
  • Character Switching: Easily switch between your characters

Core Gameplay

  • Action-RPG Platformer: Side-scrolling platformer with combat, NPCs, and item collection
  • GeoJSON-Based Levels: Levels generated from real-world trip data (hiking routes, travel paths, etc.)
  • Combat System:
    • Simple slash attacks for basic enemies
    • Magic spells with elemental requirements for special foes
    • Different enemy types: slashable, magical, armored, flying, bosses
  • Multiplayer: Real-time multiplayer using WebSockets and MQTT
  • Morality System: Killing NPCs increases "evil points"
  • Economy: Collect gold, silver, and copper coins
  • Buildings: Inns for rest, shops for trading, and special locations

Level Design

  • Dynamic Generation: Coordinates from GeoJSON become platform positions
  • Contextual Entities: Properties define enemies, NPCs, buildings, and collectibles
  • Duration-Based: Short trips (5 min), long trips (15-20 min), or split multi-level journeys
  • Themes: Forest, desert, mountain, snow, and more

Technical Stack

  • Backend: Django with REST API
  • Frontend: Phaser.js game engine with TypeScript
  • Real-time: WebSockets (Django Channels) + MQTT
  • Data: GeoJSON for trip definitions
  • Rendering: HTML divs (replaceable with PNG sprites)

๐Ÿ—๏ธ Project Structure

browser-platformer/
โ”œโ”€โ”€ backend/                          # Django backend
โ”‚   โ”œโ”€โ”€ geojson_platformer/          # Django project
โ”‚   โ”‚   โ”œโ”€โ”€ settings.py              # Configuration
โ”‚   โ”‚   โ”œโ”€โ”€ urls.py                  # URL routing
โ”‚   โ”‚   โ””โ”€โ”€ asgi.py                  # ASGI config for WebSockets
โ”‚   โ”œโ”€โ”€ game/                        # Main game app
โ”‚   โ”‚   โ”œโ”€โ”€ models.py                # Database models
โ”‚   โ”‚   โ”œโ”€โ”€ views.py                 # API endpoints
โ”‚   โ”‚   โ”œโ”€โ”€ serializers.py           # REST serializers
โ”‚   โ”‚   โ”œโ”€โ”€ admin.py                 # Django admin config
โ”‚   โ”‚   โ”œโ”€โ”€ geojson_processor.py     # GeoJSON โ†’ Levels converter
โ”‚   โ”‚   โ”œโ”€โ”€ mqtt_client.py           # MQTT integration
โ”‚   โ”‚   โ”œโ”€โ”€ consumers.py             # WebSocket handlers
โ”‚   โ”‚   โ””โ”€โ”€ fixtures/                # Sample data
โ”‚   โ”œโ”€โ”€ requirements.txt             # Python dependencies
โ”‚   โ””โ”€โ”€ manage.py                    # Django management
โ”œโ”€โ”€ frontend/                        # Phaser.js frontend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ main.ts                  # Entry point
โ”‚   โ”‚   โ”œโ”€โ”€ scenes/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ GameScene.ts         # Main game scene
โ”‚   โ”‚   โ”œโ”€โ”€ entities/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Player.ts            # Player character
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Enemy.ts             # Enemy entities
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ NPC.ts               # Non-player characters
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Collectible.ts       # Coins and items
โ”‚   โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ api.ts               # Backend API client
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ websocket.ts         # WebSocket client
โ”‚   โ”‚   โ””โ”€โ”€ ui/
โ”‚   โ”‚       โ””โ”€โ”€ UIManager.ts         # UI overlay management
โ”‚   โ”œโ”€โ”€ index.html                   # HTML entry
โ”‚   โ”œโ”€โ”€ package.json                 # NPM dependencies
โ”‚   โ””โ”€โ”€ vite.config.ts               # Vite configuration
โ””โ”€โ”€ sample_trips/                    # Example GeoJSON trips
    โ”œโ”€โ”€ mountain_journey.geojson     # Mountain pass adventure
    โ”œโ”€โ”€ forest_path.geojson          # Forest trail
    โ””โ”€โ”€ desert_expedition.geojson    # Desert caravan route

๐Ÿ“‹ Prerequisites

  • Python 3.10+
  • Node.js 18+
  • npm or yarn
  • Google Cloud account (for OAuth - free)
  • (Optional) MQTT broker (e.g., Mosquitto) for multiplayer

๐Ÿš€ Quick Start

1. Backend Setup

cd backend

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Copy environment file and configure Google OAuth
cp .env.example .env
# Edit .env and add your Google OAuth credentials
# See GOOGLE_OAUTH_SETUP.md for detailed instructions

# Run migrations
python manage.py makemigrations
python manage.py migrate

# Load sample data (enemies, NPCs, items)
python manage.py loaddata game/fixtures/sample_data.json

# Create demo trips from GeoJSON
python setup_demo.py

# Create superuser (for admin access)
python manage.py createsuperuser

# Run server
python manage.py runserver

The backend will be available at http://localhost:8000

Important: You must configure Google OAuth to use the game. See GOOGLE_OAUTH_SETUP.md for instructions.

2. Frontend Setup

cd frontend

# Install dependencies
npm install

# Run development server
npm run dev

The game will be available at http://localhost:3000

๐ŸŽฏ How to Play

Getting Started

  1. Login: Click "Sign in with Google" to authenticate
  2. Create Character: Create your first character (you can have up to 3)
  3. Select Character: Choose which character to play
  4. Pick a Trip: Select from available GeoJSON-based journeys
  5. Start Adventure: Begin your journey!

Controls

  • Arrow Keys: Move left/right
  • Space: Jump
  • Z: Slash attack (melee)
  • X: Magic spell (costs mana)
  • C: Interact with NPCs

Character Management

  • Create Characters: Up to 3 characters per Google account
  • Switch Characters: Return to character select to change characters
  • Independent Progress: Each character has separate stats, inventory, and progression
  • Delete Characters: Remove unwanted characters to make room for new ones

Game Mechanics

  1. Navigate Platforms: Jump across platforms generated from trip coordinates
  2. Combat Enemies: Use slash attacks or magic based on enemy type
  3. Collect Coins: Gather gold, silver, and copper
  4. Interact with NPCs: Talk to merchants, innkeepers, and quest givers
  5. Visit Buildings: Rest at inns, trade at shops
  6. Complete the Journey: Reach the end of the level
  7. Track Progress: Your character's progress is automatically saved

Enemy Types

  • Slashable: Defeated with basic attacks
  • Magical: Require magic spells
  • Armored: High defense, take reduced damage
  • Flying: Airborne enemies
  • Boss: Powerful end-level challenges

๐Ÿ“Š Database Models

Core Models

  • Player: Character stats, inventory, currency, morality (max 3 per user)
    • Fields: user (ForeignKey), character_slot (1-3), is_active
  • Trip: GeoJSON data, difficulty, theme, duration
  • Level: Generated level segments with platform data
  • Enemy: Enemy templates with stats and weaknesses
  • NPC: Non-combatant characters with dialogue
  • Building: Inns, shops, towers, etc.
  • Item: Weapons, armor, potions, spells
  • PlayerInventory: Player's collected items (per character)
  • LevelInstance: Active multiplayer sessions
  • LevelProgress: Player completion tracking (per character)

๐Ÿ—บ๏ธ Creating Custom Trips

GeoJSON Format

Create a GeoJSON file with:

{
  "type": "Feature",
  "geometry": {
    "type": "LineString",
    "coordinates": [
      [longitude, latitude],
      [longitude, latitude],
      ...
    ]
  },
  "properties": {
    "name": "Your Trip Name",
    "description": "Description",
    "difficulty": "easy|medium|hard|expert",
    "estimated_duration": 10,
    "theme": "forest|desert|mountain|snow",
    "background_story": "Your story here",
    "enemy_distribution": {
      "slashable": 50,
      "magical": 30,
      "armored": 15,
      "flying": 5
    },
    "npc_encounters": [
      {
        "type": "merchant",
        "location_index": 3,
        "name": "Trader Bob"
      }
    ],
    "buildings": [
      {
        "type": "inn",
        "location_index": 5,
        "name": "Rest Stop"
      }
    ]
  }
}

Loading Your Trip

  1. Upload via Django Admin:

    • Navigate to http://localhost:8000/admin
    • Go to Trips โ†’ Add Trip
    • Paste your GeoJSON data
    • Fill in metadata
    • Save
  2. Generate Levels:

    • In admin, select your trip
    • Click "Generate Levels" action
    • Levels will be created automatically
  3. Or via API:

    curl -X POST http://localhost:8000/api/trips/ \
      -H "Content-Type: application/json" \
      -d @your_trip.geojson
    
    curl -X POST http://localhost:8000/api/trips/{id}/generate_levels/

๐Ÿ”ง API Endpoints

Authentication

  • POST /api/auth/google/login/ - Initiate Google OAuth
  • POST /api/auth/logout/ - Logout user
  • GET /api/user/me/ - Get current user info

Character Management

  • GET /api/characters/ - List user's characters (max 3)
  • GET /api/characters/active/ - Get active character
  • POST /api/characters/create/ - Create new character
  • POST /api/characters/{id}/activate/ - Set active character
  • DELETE /api/characters/{id}/delete/ - Delete character

Trips

  • GET /api/trips/ - List all trips
  • GET /api/trips/{id}/ - Get trip details
  • POST /api/trips/ - Create new trip (requires auth)
  • POST /api/trips/{id}/generate_levels/ - Generate levels

Levels

  • GET /api/levels/ - List levels
  • GET /api/levels/{id}/ - Get level details
  • POST /api/levels/{id}/start_instance/ - Start multiplayer instance

Players

  • GET /api/players/ - List players
  • GET /api/players/{id}/ - Get player details
  • POST /api/players/{id}/rest/ - Rest (restore health/mana)
  • POST /api/players/{id}/add_currency/ - Add coins
  • GET /api/players/{id}/inventory/ - Get inventory

Game Data

  • GET /api/enemies/ - List enemy templates
  • GET /api/npcs/ - List NPCs
  • GET /api/items/ - List items
  • GET /api/buildings/ - List buildings

Note: Most endpoints require authentication via JWT token.

๐ŸŒ Multiplayer Setup

Using WebSockets (Built-in)

WebSockets are configured by default via Django Channels. Multiple players can join the same level instance.

Using MQTT (Optional)

For advanced multiplayer with external MQTT broker:

  1. Install MQTT Broker:

    # macOS
    brew install mosquitto
    brew services start mosquitto
    
    # Ubuntu/Debian
    sudo apt-get install mosquitto
    sudo systemctl start mosquitto
  2. Configure Backend: Edit .env:

    MQTT_BROKER_HOST=localhost
    MQTT_BROKER_PORT=1883
    
  3. Enable MQTT in Django: Uncomment in game/apps.py:

    from .mqtt_client import mqtt_client
    mqtt_client.connect()

๐ŸŽจ Customization

Replacing Divs with Sprites

Currently, entities are rendered as colored divs. To use PNG sprites:

  1. Add assets to frontend:

    frontend/public/assets/
    โ”œโ”€โ”€ player.png
    โ”œโ”€โ”€ enemy_slime.png
    โ”œโ”€โ”€ npc_merchant.png
    โ””โ”€โ”€ platforms/
    
  2. Update entity classes: In Player.ts, Enemy.ts, etc., replace:

    this.sprite = scene.add.rectangle(x, y, 30, 40, 0x00FF00);

    With:

    this.sprite = scene.add.sprite(x, y, 'player');
  3. Preload assets: In GameScene.ts preload():

    this.load.image('player', 'assets/player.png');

Adding New Enemy Types

  1. Create in Django admin or via API
  2. Update Enemy.ts color mapping
  3. Add to level generator in geojson_processor.py

๐Ÿงช Development

Run Tests

# Backend
cd backend
python manage.py test

# Frontend
cd frontend
npm test

Code Structure

  • Backend: Follow Django best practices
  • Frontend: TypeScript with Phaser.js patterns
  • GeoJSON Processing: geojson_processor.py handles conversion logic

๐Ÿ“ Future Enhancements

  • Boss battles at level ends
  • Quest system with objectives
  • Crafting system
  • Player-to-player trading
  • Leaderboards
  • Mobile support
  • Real sprite assets
  • Sound effects and music
  • Save/load system
  • Achievement system

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

๐Ÿ“œ License

MIT License - feel free to use this project for learning, experimentation, or building your own trip-based games!

๐Ÿ†˜ Troubleshooting

Backend won't start

  • Check Python version (3.10+)
  • Ensure virtual environment is activated
  • Run migrations: python manage.py migrate

Frontend won't start

  • Check Node version (18+)
  • Clear node_modules: rm -rf node_modules && npm install
  • Check if backend is running on port 8000

No trips showing

  • Run python setup_demo.py to load sample data
  • Check Django admin for trips
  • Ensure is_active=True on trips

WebSocket connection fails

  • Ensure Django Channels is installed
  • Check that ASGI application is configured
  • Verify WebSocket URL in browser console

๐Ÿ“ง Support

For questions or issues, please open a GitHub issue or contact the development team.


Transform your real-world adventures into epic platformer journeys! ๐Ÿ—บ๏ธ๐ŸŽฎ

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •