A research project that creates a dynamic game engine using LLMs to modify gameplay in real-time based on natural language descriptions.
This project enables users to:
- Start with a default 2D platformer game world
- Describe changes they want in natural language ("make gravity work backwards", "add flying enemies")
- Watch as an LLM generates code to modify the game in real-time
- Experience dynamic gameplay that evolves based on their descriptions
-
Game Engine (
src/engine/)- Entity-Component-System architecture
- 2D physics simulation using Matter.js
- Canvas-based rendering
-
LLM Integration (
src/llm/)- Google Gemini 2.5 Flash integration
- Context engineering for game modifications
- Code generation and validation
-
Code Execution (
src/execution/)- Sandboxed code execution using VM2
- Security constraints and resource limits
- Safe API exposure to generated code
-
Web Interface (
src/client/)- HTML5 Canvas game rendering
- Real-time chat interface for modifications
- Socket.io for live updates
- Node.js (v18+)
- Google AI API key
npm installCreate a .env file:
GOOGLE_AI_API_KEY=your_api_key_here
PORT=3000
npm run dev # Start development server
npm test # Run tests
npm run test:watch # Run tests in watch modenpm run build # Build for production
npm start # Start production serverThe project includes comprehensive testing:
- Unit tests for game engine components
- Integration tests for LLM code generation
- Security tests for code execution sandbox
- End-to-end tests for user interactions
npm test # Run all tests
npm run test:coverage # Generate coverage reportsrc/
├── engine/ # Core game engine
│ ├── entities/ # Entity definitions
│ ├── components/ # ECS components
│ ├── systems/ # Game systems
│ └── physics/ # Physics integration
├── llm/ # LLM integration
│ ├── context/ # Context engineering
│ ├── generation/ # Code generation
│ └── validation/ # Code validation
├── execution/ # Code execution sandbox
├── api/ # Game API for LLM-generated code
├── server/ # Express server
├── client/ # Frontend application
└── __tests__/ # Test files
- Project setup and dependencies
- Basic Entity-Component-System
- 2D physics integration
- Testing infrastructure
- Google Gemini API integration
- Context engineering system
- Code generation pipeline
- Security sandbox
- Web interface with game canvas
- Real-time chat system
- User experience enhancements
This project implements multiple security layers:
- VM2 sandboxing for code execution
- Resource limits (CPU, memory, time)
- API whitelisting for safe game modifications
- Input validation and sanitization
- Rate limiting for API calls
User: "Make all enemies move twice as fast"
LLM generates: game.entities.filter(e => e.hasComponent('Enemy')).forEach(e => e.speed *= 2)
Result: All enemy entities now move at double speed