miles990-claude-software-skills-game-development.ocm.json json Copy{
"ocm" : "1" ,
"id" : "miles990-claude-software-skills-game-development" ,
"kind" : "skill" ,
"name" : "game-development" ,
"description" : "Game development patterns, architectures, and best practices" ,
"publisher" : "miles990" ,
"version" : "1.0.0" ,
"capabilities" : {
"domains" : [
"science" ,
"coding"
],
"tags" : [
"skill-md" ,
"game" ,
"unity" ,
"unreal" ,
"godot" ,
"flame" ,
"flutter" ,
"ecs" ,
"physics" ,
"multiplayer"
],
"languages" : [
"en"
]
},
"quality_prior" : 0.6 ,
"examples" : [
"Game development patterns, architectures, and best practices"
],
"primary" : false ,
"metadata" : {
"source" : {
"provider" : "skills.sh" ,
"repository" : "https://github.com/miles990/claude-software-skills" ,
"path" : "domain-applications/game-development/SKILL.md" ,
"ref" : "HEAD" ,
"url" : "https://github.com/miles990/claude-software-skills/blob/HEAD/domain-applications/game-development/SKILL.md" ,
"key" : "miles990/claude-software-skills/domain-applications/game-development/SKILL.md"
}
},
"instructions" : "# Game Development\n\n## Overview\n\nPatterns and practices for building games across platforms. Covers architecture, rendering, physics, AI, multiplayer, and optimization.\n\n---\n\n## Game Architecture\n\n### Game Loop\n\n```\n┌─────────────────────────────────────────────────────────────┐\n│ Game Loop │\n│ │\n│ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │\n│ │ Input │ ─→ │ Update │ ─→ │ Physics │ ─→ │ Render │ │\n│ │ Process │ │ Logic │ │ Step │ │ Frame │ │\n│ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │\n│ ↑ │ │\n│ └─────────────────────────────────────────────┘ │\n│ Next Frame │\n└─────────────────────────────────────────────────────────────┘\n```\n\n### Fixed vs Variable Timestep\n\n| Type | Use Case | Code Pattern |\n|------|----------|--------------|\n| Fixed | Physics, determinism | `while (accumulator >= dt) { update(dt); }` |\n| Variable | Rendering, animations | `update(deltaTime);` |\n| Hybrid | Most games | Fixed physics, variable render |\n\n```typescript\n// Hybrid game loop\nlet accumulator = 0;\nconst FIXED_DT = 1/60;\n\nfunction gameLoop(currentTime: number) {\n const deltaTime = currentTime - lastTime;\n accumulator += deltaTime;\n\n // Fixed timestep for physics\n while (accumulator >= FIXED_DT) {\n physicsUpdate(FIXED_DT);\n accumulator -= FIXED_DT;\n }\n\n // Variable timestep for rendering\n const alpha = accumulator / FIXED_DT;\n render(alpha); // Interpolate between states\n\n requestAnimationFrame(gameLoop);\n}\n```\n\n---\n\n### Entity Component System (ECS)\n\n```\n┌─────────────────────────────────────────────────────────────┐\n│ ECS Architecture │\n│ │\n│ Entity: Just an ID │\n│ ┌─────┐ ┌─────┐ ┌─────┐ │\n│ │ 1 │ │ 2 │ │ 3 │ │\n│ └─────┘ └─────┘ └─────┘ │\n│ │\n│ Components: Pure Data │\n│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │\n│ │ Position │ │ Velocity │ │ Sprite │ │\n│ │ x, y, z │ │ vx, vy │ │ texture │ │\n│ └──────────┘ └──────────┘ └──────────┘ │\n│ │\n│ Systems: Logic │\n│ ┌────────────────┐ ┌────────────────┐ │\n│ │ MovementSystem │ │ RenderSystem │ │\n│ │ Position+Vel │ │ Position+Sprite│ │\n│ └────────────────┘ └────────────────┘ │\n└─────────────────────────────────────────────────────────────┘\n```\n\n```typescript\n// Component definitions\ninterface Position { x: number; y: number; }\ninterface Velocity { vx: number; vy: number; }\ninterface Sprite { texture: string; width: number; height: number; }\n\n// System\nfunction movementSystem(entities: Entity[], dt: number) {\n for (const entity of entities) {\n if (entity.has(Position) && entity.has(Velocity)) {\n const pos = entity.get(Position);\n const vel = entity.get(Velocity);\n pos.x += vel.vx * dt;\n pos.y += vel.vy * dt;\n }\n }\n}\n```\n\n---\n\n## 2D Game Development\n\n### Sprite Animation\n\n```typescript\ninterface Animation {\n frames: string[]; // Texture names\n frameDuration: number; // Seconds per frame\n loop: boolean;\n}\n\nclass AnimatedSprite {\n private currentFrame = 0;\n private elapsed = 0;\n\n update(dt: number) {\n this.elapsed += dt;\n if (this.elapsed >= this.animation.frameDuration) {\n this.elapsed = 0;\n this.currentFrame++;\n if (this.currentFrame >= this.animation.frames.length) {\n this.currentFrame = this.animation.loop ? 0 : this.animation.frames.length - 1;\n }\n }\n }\n\n get texture(): string {\n return this.animation.frames[this.currentFrame];\n }\n}\n```\n\n### Collision Detection\n\n| Method | Complexity | Use Case |\n|--------|------------|----------|\n| AABB | O(n²) → O(n log n) | Boxes, simple shapes |\n| Circle | O(n²) | Projectiles, characters |\n| SAT | O(n²) | Complex convex polygons |\n| Pixel Perfect | Expensive | Precise collision |\n\n```typescript\n// AABB collision\nfunction aabbIntersect(a: AABB, b: AABB): boolean {\n return a.x < b.x + b.width &&\n a.x + a.width > b.x &&\n a.y < b.y + b.height &&\n a.y + a.height > b.y;\n}\n\n// Spatial hash for broad phase\nclass SpatialHash {\n private cells = new Map<string, Entity[]>();\n private cellSize: number;\n\n insert(entity: Entity) {\n const key = this.getKey(entity.position);\n if (!this.cells.has(key)) this.cells.set(key, []);\n this.cells.get(key)!.push(entity);\n }\n\n query(position: Vector2): Entity[] {\n // Check neighboring cells\n const nearby: Entity[] = [];\n for (let dx = -1; dx <= 1; dx++) {\n for (let dy = -1; dy <= 1; dy++) {\n const key = this.getKey({ x: position.x + dx * this.cellSize, y: position.y + dy * this.cellSize });\n nearby.push(...(this.cells.get(key) || []));\n }\n }\n return nearby;\n }\n}\n```\n\n---\n\n## Game AI\n\n### Finite State Machine\n\n```typescript\ninterface State {\n enter(): void;\n update(dt: number): void;\n exit(): void;\n}\n\nclass EnemyAI {\n private states = new Map<string, State>();\n private currentState: State;\n\n transition(stateName: string) {\n this.currentState?.exit();\n this.currentState = this.states.get(stateName)!;\n this.currentState.enter();\n }\n}\n\n// Example: Patrol → Chase → Attack\nclass PatrolState implements State {\n enter() { this.setAnimation('walk'); }\n update(dt: number) {\n this.patrol();\n if (this.canSeePlayer()) {\n this.fsm.transition('chase');\n }\n }\n exit() {}\n}\n```\n\n### Behavior Trees\n\n```\n┌─────────────────────────────────────────────────────────────┐\n│ Behavior Tree │\n│ │\n│ [Selector] │\n│ / \\ │\n│ [Sequence] [Patrol] │\n│ / \\ │\n│ [CanSee?] [Attack] │\n│ │ │\n│ [Chase] │\n└─────────────────────────────────────────────────────────────┘\n```\n\n### Pathfinding (A*)\n\n```typescript\nfunction aStar(start: Node, goal: Node): Node[] {\n const openSet = new PriorityQueue<Node>();\n const cameFrom = new Map<Node, Node>();\n const gScore = new Map<Node, number>();\n const fScore = new Map<Node, number>();\n\n gScore.set(start, 0);\n fScore.set(start, heuristic(start, goal));\n openSet.enqueue(start, fScore.get(start)!);\n\n while (!openSet.isEmpty()) {\n const current = openSet.dequeue()!;\n\n if (current === goal) {\n return reconstructPath(cameFrom, current);\n }\n\n for (const neighbor of getNeighbors(current)) {\n const tentativeG = gScore.get(current)! + distance(current, neighbor);\n\n if (tentativeG < (gScore.get(neighbor) ?? Infinity)) {\n cameFrom.set(neighbor, current);\n gScore.set(neighbor, tentativeG);\n fScore.set(neighbor, tentativeG + heuristic(neighbor, goal));\n openSet.enqueue(neighbor, fScore.get(neighbor)!);\n }\n }\n }\n\n return []; // No path found\n}\n```\n\n---\n\n## Multiplayer Games\n\n### Network Architecture\n\n| Model | Latency | Complexity | Use Case |\n|-------|---------|------------|----------|\n| Peer-to-Peer | Low | Medium | Fighting games, small lobbies |\n| Client-Server | Medium | High | Most online games |\n| Authoritative Server | Higher | Highest | Competitive games |\n\n### Lag Compensation\n\n```typescript\n// Client-side prediction\nclass NetworkedPlayer {\n private pendingInputs: Input[] = [];\n private serverState: PlayerState;\n\n update(input: Input) {\n // 1. Apply input locally (prediction)\n this.applyInput(input);\n this.pendingInputs.push(input);\n\n // 2. Send to server\n this.sendInput(input);\n }\n\n onServerUpdate(state: PlayerState, lastProcessedInput: number) {\n // 3. Reconcile with server\n this.serverState = state;\n\n // 4. Re-apply unprocessed inputs\n this.pendingInputs = this.pendingInputs.filter(i => i.id > lastProcessedInput);\n for (const input of this.pendingInputs) {\n this.applyInput(input);\n }\n }\n}\n```\n\n### State Synchronization\n\n```typescript\n// Delta compression\ninterface StateDelta {\n timestamp: number;\n changes: Map<EntityId, ComponentChanges>;\n}\n\nfunction computeDelta(prev: GameState, curr: GameState): StateDelta {\n const changes = new Map();\n for (const [id, entity] of curr.entities) {\n const prevEntity = prev.entities.get(id);\n if (!prevEntity || hasChanged(prevEntity, entity)) {\n changes.set(id, getChangedComponents(prevEntity, entity));\n }\n }\n return { timestamp: curr.timestamp, changes };\n}\n```\n\n---\n\n## Game Optimization\n\n### Rendering Optimization\n\n| Technique | Benefit | Implementation |\n|-----------|---------|----------------|\n| Batching | Reduce draw calls | Combine sprites with same texture |\n| Culling | Skip invisible objects | Frustum culling, occlusion culling |\n| LOD | Reduce polygon count | Distance-based model switching |\n| Instancing | Efficient duplicates | GPU instancing for repeated objects |\n\n### Memory Optimization\n\n```typescript\n// Object pooling\nclass ObjectPool<T> {\n private pool: T[] = [];\n private factory: () => T;\n\n acquire(): T {\n return this.pool.pop() ?? this.factory();\n }\n\n release(obj: T) {\n this.reset(obj);\n this.pool.push(obj);\n }\n}\n\n// Usage\nconst bulletPool = new ObjectPool(() => new Bullet());\n\nfunction fireBullet() {\n const bullet = bulletPool.acquire();\n bullet.init(position, direction);\n activeBullets.add(bullet);\n}\n\nfunction onBulletHit(bullet: Bullet) {\n activeBullets.delete(bullet);\n bulletPool.release(bullet);\n}\n```\n\n---\n\n## Game Engines Reference\n\n| Engine | Language | Best For | Platform | Skill |\n|--------|----------|----------|----------|-------|\n| Unity | C# | Mobile, indie, VR | All | - |\n| Unreal | C++, Blueprint | AAA, realistic | PC, Console | - |\n| Godot | GDScript, C# | Indie, 2D | All | - |\n| **Flame** | Dart | Flutter 2D, casual | All | [flame/](./flame/) |\n| Phaser | JavaScript | Web 2D | Browser | - |\n| Three.js | JavaScript | Web 3D | Browser | - |\n| Bevy | Rust | Performance | Desktop | - |\n| LÖVE | Lua | Simple 2D | Desktop | - |\n\n### Flame Engine (Flutter)\n\n專為 Flutter 開發者設計的 2D 遊戲引擎,詳細文件請參考 [flame/SKILL.md](./flame/SKILL.md):\n\n- **flame-core/** - 組件、輸入、碰撞、相機、動畫、音效、粒子\n- **flame-systems/** - 14 個遊戲系統(任務、對話、背包、戰鬥等)\n- **flame-templates/** - RPG、Platformer、Roguelike 模板\n\n---\n\n## Related Skills\n\n- [[performance-optimization]] - General optimization\n- [[realtime-systems]] - WebSocket, networking\n- [[cpp]] - Performance-critical code\n- [[javascript-typescript]] - Web games" ,
"cost" : {
"context_tokens" : 2828
}
}