agent-game-engine
Enables AI agents to create, run, and debug 2D games in a sandboxed engine, providing tools for simulation, state inspection, and quality validation.
README
🎮 Agent Game Engine
AI-Agent-Native 2D Game Engine in TypeScript
A lightweight, sandboxed, high-performance 2D game engine designed for AI Coding Agents to write code, evaluate quality, and render games across Headless CLI, Web Browsers, Mobile, and Desktop environments.
✨ Core Features
- 🤖 Verb-Driven API: Simplified, declarative game methods (
spawn,controls,behavior,onCollision,winWhen,loseWhen). - 🛡️ QuickJS WASM Sandbox: Secure code execution with strict resource limits (16MB RAM, 100ms CPU timeout) and isolation from dangerous globals.
- ⚡ 22-Opcode Command Buffer Protocol: Binary ArrayBuffer rendering offload protocol between sandbox and host.
- 🚦 5-Layer Quality Gates: Automated evaluation system catching AST security violations, infinite loops, blank screens, frozen game states, and numerical exceptions (
NaN/Infinity). - 📱 Cross-Platform Runtime: Headless Node.js, HTML5 Browser
<canvas>, Mobile Touch with auto-responsive scaling (Fit/Fill/Pixel-Perfect), and Web Audio auto-unlock. - 🎨 Complete 2D Rendering Pipeline:
Camera2D: Lerp follow, deadzone, bounds clamping, shake, flash, fade, zoom & rotation.TilemapLoader: Tiled JSON orthogonal map rendering.SpriteSheet& Texture Atlases (TexturePacker & Aseprite).ParticleEmitter: Burst & continuous particle effects with scale & color gradients.- Viewport Frustum Culling for high-performance rendering.
- 💥 Advanced Physics & Spatial Acceleration:
SAT(Separating Axis Theorem) convex polygon & circle collision detection.QuadTree&SpatialHashGridsupporting 500+ entities @ >200 FPS.Raycastingline-of-sight & rigid body physics (Mass, Friction, Restitution, Impulse).
- 🎬 Animation, Tweens & Audio:
AnimationController: Frame sprite animation state machine.TweenEngine: 20+ Easing curves (Elastic, Bounce, Cubic, Quad, etc.).AudioManager: Web Audio SFX, BGM streaming loop, volume buses & fade transitions.
- 🕹️ Input, Scenes & UI Primitives:
- Unified Keyboard, Mouse (world coords), Touch multi-gestures, and Gamepad Action Mapping.
SceneManager: Lifecycle hooks and Fade/Slide transition effects.- UI Primitives:
UIButton,UIProgressBar,UIDialog(typewriter effect), and screen-fixedHUDoverlay.
- 🧰 Asset Loader & Developer Tools:
- Async loader with progress tracking.
DebugOverlay: Real-time FPS, entity count, draw calls.PhysicsWireframe: Hitbox wireframe visualization.TimeDilation&StepFrame: Slow-mo control and frame-by-frame step debugging.
- 🔌 CLI & MCP Server: 5 CLI commands (
run,validate,watch,benchmark,demo) and 10 Model Context Protocol tools for LLM agent interaction over stdio transport.
📦 Installation & Setup
# Clone the repository
git clone https://github.com/ImL1s/agent-game-engine.git
cd agent-game-engine
# Install dependencies
pnpm install
# Build the monorepo package (ESM + DTS)
pnpm build
# Run full test suite (1,279 tests)
pnpm test
🚀 Quick Start — 4 Supported Runtimes
1. Headless Node.js Runtime
import { AgentGame } from 'agent-game-engine';
// Initialize engine instance
const game = new AgentGame({ width: 800, height: 600, fps: 60 });
// Spawn player sprite with platformer controls
const player = game.spawn('player', { x: 100, y: 100, width: 32, height: 32 });
player.controls('platformer', { speed: 200, jumpForce: 400 });
// Spawn platforms & collectibles
game.spawn('platform', { x: 400, y: 500, width: 800, height: 40 });
for (let i = 0; i < 5; i++) {
game.spawn('coin', { x: 200 + i * 80, y: 350, width: 20, height: 20 }).behavior('float');
}
// Handle collisions
game.onCollision('player', 'coin', (p, coin) => {
coin.destroy();
game.addScore(10);
});
// Set win / lose conditions
game.winWhen(() => game.query('coin').length === 0);
game.loseWhen(() => player.y > 600);
// Advance engine simulation step by step
game.step(1 / 60);
const state = game.getState();
console.log(`Frame: ${state.frame}, Score: ${state.score}, Entities: ${state.entities.length}`);
2. CLI Usage
# Run game script headless for 60 frames and save state screenshot
pnpm agent-game run my-game.js --frames=60 --screenshot=out.png
# Run 5 Quality Gates validation on user script
pnpm agent-game validate my-game.js
# Launch interactive watch mode with Web live preview server
pnpm agent-game watch my-game.js --port=3000
# Run 500+ entity physics benchmark
pnpm agent-game benchmark
# Run playable interactive demo
pnpm agent-game demo
3. MCP (Model Context Protocol) Server Integration
Add to claude_desktop_config.json:
{
"mcpServers": {
"agent-game-engine": {
"command": "node",
"args": ["/absolute/path/to/agent-game-engine/dist/mcp/index.js"]
}
}
}
Programmatic MCP TypeScript initialization:
import { createMCPServer } from 'agent-game-engine/mcp';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
const server = createMCPServer();
const transport = new StdioServerTransport();
await server.connect(transport);
4. Browser Canvas Runtime (index.html)
<!DOCTYPE html>
<html>
<head>
<title>Agent Game Engine</title>
</head>
<body>
<canvas id="game-canvas" width="800" height="600"></canvas>
<script type="module">
import { AgentGame, BrowserRuntime, InputManager } from './dist/browser.js';
const canvas = document.getElementById('game-canvas');
const game = new AgentGame({ width: 800, height: 600 });
const player = game.spawn('player', { x: 100, y: 100 });
player.controls('platformer', { speed: 200, jumpForce: 400 });
game.spawn('platform', { x: 400, y: 500, width: 800, height: 40 });
const runtime = new BrowserRuntime({
canvas,
game,
targetFps: 60,
autoStart: true
});
</script>
</body>
</html>
🔌 MCP Server Tools (for AI Agents)
Exposes 10 tools over Stdio Transport for Claude, Cursor, Gemini, and custom AI agents:
game_load_code: Load game JavaScript code string.game_start: Initialize and start game session.game_step: Advance simulation by N frames with input state.game_get_state: Retrieve Zod JSON, 2D ASCII Grid, or Delta state.game_get_screenshot: Capture host canvas PNG screenshot as Base64.game_simulate_input: Inject keyboard/mouse/touch input.game_run_quality_gates: Run all 5 quality gates on current code.game_reset: Reset game to initial state.game_get_console: Retrieve intercepted console logs.game_list_skills: List available game engine skills.
🎮 Sample Games Included
- Pong: Simple classic paddle game.
- Platformer: Jumping, coins, platforms, and gravity.
- Space Shooter: Ship controls, spawning enemies, shooting projectiles.
- Tower Defense: Enemies, pathing, tower shooting, base zone protection.
- Puzzle: Color matching grid game.
- Tilemap RPG: Tiled JSON map, camera follow, scene transitions, NPC dialog.
- Physics Puzzle: SAT collisions, rigid body dynamics, particle bursts, time dilation slow-mo.
📜 License
MIT License © 2026 ImL1s
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。