game2d: A 2D Gaming Framework
๐ Overview
game2d is an open-source framework for game development that combines a
2D game engine with Lua scripting and a WebAssembly client. Built using a
declarative JSON object schema, it is designed for experimenting with game code
and assets created with generative AI.
๐ง Under Construction
game2d should be considered pre-release. It is intended as a demonstration of
a proof of a concept. It is not intended for use in any production system.
๐๏ธ Architecture Overview
graph TD
subgraph "API Layer"
API["game2d-api Service"] --> Auth["Authentication & Authorization"]
API --> GameManagement["Game Management"]
API --> AIService["AI Integration Service"]
end
subgraph "Storage Layer"
GameManagement --> MongoDB["MongoDB (Game Definitions)"]
GameManagement --> Redis["Redis (Caching)"]
end
subgraph "Client Layer"
Client["game2d WASM Client"] --> Ebitengine["Ebitengine (2D Game Engine)"]
Client --> LuaInterpreter["Lua Interpreter"]
Client --> API
end
subgraph "Frontend Layer"
WebUI["game2d-app React Web UI"] --> API
WebUI --> Client
end
AIService --> ExternalAI["External AI Services"]
๐งฉ Core Components
1. game2d Client
The main client and protocol, typically compiled into WebAssembly (WASM) for
browser integration, but also buildable for various native architectures.
- Engine: Combines the Ebitengine 2D game engine with a
Lua interpreter
- State Management: Shared game state between Lua and Go code
- Game Loop: Renders assets during draw phase, executes scripts during update phase
- Game Schema: Uses a declarative object schema for game definitions
2. game2d API Service
The distributed backend service providing REST API functionality:
- Game Storage: Persists game state definitions in MongoDB
- Performance: Implements Redis caching for fast access
- AI Integration: Interfaces with generative AI services to create game content
- User Management: Handles authentication, accounts, and profiles
- Content Delivery: Serves the web application UI
3. game2d App (Web UI)
A React/Vite application for interacting with the service:
- Game Management: Search, browse, edit, and save game definitions
- Account Management: Update profiles and account settings
- AI Interaction: Submit game definitions and prompts to AI services
- Game Player: Runs the WASM client and games directly in the browser
๐ Getting Started
Prerequisites
As long as the all of the above are installed, the build process can install any other requirements.
๐ง Development Workflow
-
Clone the repository
git clone https://github.com/dhaifley/game2d.git
cd game2d
-
Set up the development environment
cat <<EOF > .env
LOG_LEVEL='debug'
DB_CONNECTION='mongodb://game2d:mongodb@localhost:27017/game2d?authSource=admin'
CACHE_SERVERS='localhost:6379'
ACCOUNT_ID='test'
ACCOUNT_NAME='test'
SUPERUSER='admin'
SUPERUSER_PASSWORD='admin'
GUEST_USER='guest'
GUEST_USER_PASSWORD='guest'
EOF
set -a
. ./.env
You can change any of these defaults, but these values will work with the
defaults set in the Docker Compose configuration used to run and test
the services.
-
Run the services locally
make run
-
Access the application
When signing into a local test environment, use either the superuser or
guest user account configured in the local environment settings above.
-
Play some games
Once in the application, you can import and play any of the games in the
/examples directory by clicking the Import button on the Games page.
-
Stop and cleanup the services
make stop
-
Run all automated tests locally
make tests
๐ Documentation
While the service is running locally:
๐ฎ Game Definition Schema
game2d uses a declarative schema for defining games:
- Game State: Overall game properties and metadata
- Assets: Images and resources needed for rendering
- Script: Lua code executed during the game loop
- Objects: Compositions of assets, scripts, and data
- Subject: The special object representing the player
๐ฏ Roadmap
- Get to a minimum viable demo release
- Add audio support
- Implement user and account management and/or integration with external IDPs
- Play and viability testing and system prompt enhancements
- AI tool usage to allow game definition testing
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature)
- Commit your changes (
git commit -m 'Add some amazing feature')
- Push to the branch (
git push origin feature/amazing-feature)
- Open a Pull Request
๐ License
This project is licensed under the GPL-3.0 License - see the LICENSE file for
details.
Project Link: https://github.com/dhaifley/game2d