
Game Architecture
Structure a browser game (Three.js or Phaser) with event-bus messaging, centralized GameState, and core-loop-first scope before adding polish.
Install
npx skills add https://github.com/opusgamelabs/game-creator --skill game-architectureWhat is this skill?
- Core loop first: input → movement → fail → score → restart before juice or extra levels
- Event-driven cross-module communication via singleton EventBus and predefined event constants
- Centralized GameState singleton—systems read and mutate through events, not scattered module state
- Companion system-patterns.md covers pooling, delta-time, disposal, waves, buffs, haptics, and assets
- Applies to both Three.js (3D) and Phaser (2D) browser games (MIT, v1.3.0)
Adoption & trust: 545 installs on skills.sh; 185 GitHub stars; 3/3 security scanners passed (skills.sh audits).
Recommended Skills
Journey fit
Canonical shelf is Build because the skill encodes implementation architecture—EventBus, GameState, pooling, and asset patterns you apply while writing game code. Frontend subphase fits browser-first 3D/2D clients where UI, scenes, and input live in the player-facing stack.
Common Questions / FAQ
Is Game Architecture safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - Game Architecture
# Game Architecture Patterns Reference knowledge for building well-structured browser games. These patterns apply to both Three.js (3D) and Phaser (2D) games. ## Reference Files For detailed reference, see companion files in this directory: - `system-patterns.md` — Object pooling, delta-time normalization, resource disposal, wave/spawn systems, buff/powerup system, haptic feedback, asset management ## Core Principles 1. **Core Loop First**: Implement the minimum gameplay loop before any polish. The order is: input -> movement -> fail condition -> scoring -> restart. Only after the core loop works should you add visuals, audio, or juice. Keep initial scope small: 1 scene/level, 1 mechanic, 1 fail condition. 2. **Event-Driven Communication**: Modules never import each other for communication. All cross-module messaging goes through a singleton EventBus with predefined event constants. 3. **Centralized State**: A single GameState singleton holds all game state. Systems read state directly and modify it through events. No scattered state across modules. 4. **Configuration Centralization**: Every magic number, balance value, asset path, spawn point, and timing value goes in `Constants.js`. Game logic files contain zero hardcoded values. 5. **Orchestrator Pattern**: One `Game.js` class initializes all systems, manages game flow (boot -> gameplay -> death/win -> restart), and runs the main loop. Systems don't self-initialize. **No title screen by default** — boot directly into gameplay. Only add a title/menu scene if the user explicitly asks for one. 6. **Restart-Safe and Deterministic**: Gameplay must survive full restart cycles cleanly. `GameState.reset()` restores a complete clean slate. All event listeners are removed in cleanup/shutdown. No stale references, lingering timers, leaked tweens, or orphaned physics bodies survive across restarts. Test by restarting 3x in a row — the third run must behave identically to the first. 7. **Clear Separation of Concerns**: Code is organized into functional layers: - `core/` - Foundation (Game, EventBus, GameState, Constants) - `systems/` - Engine-level systems (input, physics, audio, particles) - `gameplay/` - Game mechanics (player, enemies, weapons, scoring) - `level/` - World building (level construction, asset loading) - `ui/` - Interface (menus, HUD, overlays) ## Event System Design ### Event Naming Convention Use `domain:action` format grouped by feature area: ```js export const Events = { // Player PLAYER_DAMAGED: 'player:damaged', PLAYER_HEALED: 'player:healed', PLAYER_DIED: 'player:died', // Enemy ENEMY_SPAWNED: 'enemy:spawned', ENEMY_KILLED: 'enemy:killed', // Game flow GAME_STARTED: 'game:started', GAME_PAUSED: 'game:paused', GAME_OVER: 'game:over', // System ASSETS_LOADED: 'assets:loaded', LOADING_PROGRESS: 'loading:progress' }; ``` ### Event Data Contracts Always pass structured data objects, never primitives: ```js // Good eventBus.emit(Events.PLAYER_DAMAGED, { amount: 10, source: 'enemy', damageType: 'melee' }); // Bad eventBus.emit(Events.PLAYER_DAMAGED, 10); ``` ## State Management ### GameState Structure Organize state into clear domains: ```js class GameState { constructor() { this.player = { health, maxHealth, speed, inventory, buffs }; this.combat = { killCount, waveNumber, score }; this.game = { started, paused, isPlaying }; } } ``` ## Game Flow Standard flow for both 2D and 3D games: ``` Boot/Load -> Gameplay <-> Pause Menu (if requested) -> Game Over -> Gam