# Architecture Research: HTML5 Canvas Arcade Games **Domain:** HTML5 Canvas 2D arcade games (Pong-like) **Researched:** 2026-03-10 **Confidence:** HIGH ## Standard Architecture ### System Overview ``` ┌────────────────────────────────────────────────────────────────┐ │ Presentation Layer │ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │ │ Canvas View │ │ UI Layer │ │ Audio Out │ │ │ │ (rendering) │ │ (DOM menus) │ │ (Web Audio) │ │ │ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │ │ │ │ │ │ ├─────────┴─────────────────┴─────────────────┴──────────────────┤ │ Game Loop Manager │ │ ┌────────────────────────────────────────────────────┐ │ │ │ requestAnimationFrame → Update → Render → Loop │ │ │ └────────────────────────────────────────────────────┘ │ ├─────────────────────────────────────────────────────────────────┤ │ State Machine │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ Menu │→ │ Game │→ │ Pause │→ │GameOver │ │ │ │ State │ │ State │ │ State │ │ State │ │ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ ├─────────────────────────────────────────────────────────────────┤ │ Game Logic Layer │ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │ │ Entity Mgr │ │ Physics/ │ │ Collision │ │ │ │ (ball, │ │ Movement │ │ Detection │ │ │ │ paddles) │ │ Update │ │ │ │ │ └──────────────┘ └──────────────┘ └──────────────┘ │ │ ┌──────────────┐ ┌──────────────┐ │ │ │ Particle │ │ Power-up │ │ │ │ System │ │ Logic │ │ │ └──────────────┘ └──────────────┘ │ ├─────────────────────────────────────────────────────────────────┤ │ Input Layer │ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │ │ Keyboard │ │ Input State │ │ Command │ │ │ │ Events │ │ Manager │ │ Queue │ │ │ └──────────────┘ └──────────────┘ └──────────────┘ │ └────────────────────────────────────────────────────────────────┘ ``` ### Component Responsibilities | Component | Responsibility | Typical Implementation | |-----------|----------------|------------------------| | **Game Loop Manager** | Orchestrates frame timing, calls update/render in sequence, manages requestAnimationFrame | Single `gameLoop()` function that runs at ~60fps | | **State Machine** | Transitions between menu, playing, paused, game over states; isolates logic per scene | Object with `onEnter()`, `update()`, `render()`, `onExit()` methods per state | | **Input Manager** | Captures keyboard events, debounces, maintains current key state | Listens to keydown/keyup, maintains a `keysPressed` object | | **Entity Manager** | Owns and updates all game objects (paddles, ball, power-ups) | Array of entities with position, velocity, update/render methods | | **Physics/Movement** | Updates entity positions based on velocity, applies gravity if needed | `velocity.x`, `velocity.y` updated per frame, position += velocity | | **Collision Detection** | Detects overlaps between entities, triggers responses | AABB (Axis-Aligned Bounding Box) for rectangles; circle distance for round objects | | **Particle System** | Manages short-lived visual effects (impacts, explosions, trails) | Maintains particle array, updates lifetime/position, removes expired particles | | **Power-up System** | Spawns power-ups, detects collection, applies effects | Object with spawn logic, duration tracking, effect callbacks | | **Audio Manager** | Plays sound effects and music with pooling to avoid cutoff | Array of audio elements for each sound, round-robin playback | | **Renderer** | Draws all entities to canvas | Canvas 2D context calls in specific order (background, entities, UI) | ## Recommended Project Structure For a vanilla JavaScript HTML5 Canvas game (no build tools), structure as a single HTML file or minimal multi-file approach: ``` index.html # Single entry point (if single-file) ├── └──