How akrepkov/crazy_pong works
Project type and purpose
• This is a single-page, browser-based Pong clone written in vanilla JavaScript and HTML5 Canvas. Its primary function is to let users practice Pong with features like multi-ball mode, keyboard controls, and hash-based tab routing.
File structure
• Top-level files:
• README.md – project description
• index.js – (likely build/dev script or entry shim)
• package.json / package-lock.json – dependency metadata
• public/
• index.html – the shell page hosting the Canvas and controls
• styles.css – Flexbox-based responsive layout and UI styling
• src/
• app.js – application bootstrap, hash-based router, tab management
• controls.js – keyboard event handlers, mapping keys to paddle actions
• game.js – core game loop (requestAnimationFrame), physics (ball/paddle), scoring, game state
• node_modules/ – third-party packages (if any, though code is vanilla)
Key insights from README
• Hash-based routing (#practice) for view/tab switching
• Canvas rendering for paddles and balls
• ES6 classes for Ball and Paddle
• Game loop driven by requestAnimationFrame
• Visibility API to pause/resume or log tab focus changes
a. Browser Environment (container boundary)
b. UI Layer
• HTML (index.html)
• CSS (styles.css)
• Tabbed Navigation (hash router in app.js)
c. Input Layer
• Keyboard Event Listener (controls.js)
• Key Mapping (W/S and ↑/↓)
d. Game Engine
• Game Loop (requestAnimationFrame)
• Physics & Rules (Ball & Paddle ES6 classes, collision detection, scoring)
• Multi-ball Manager
e. Rendering Layer
• HTML5 Canvas API
f. Utility / Services
• Random Name Generator (logic in game.js or helper)
• Visibility Change Handler (document.visibilitychange)
Relationships and data flow
1. User presses key → controls.js captures event → updates paddle velocity/state
2. Game Loop tick (app.js calls game.js) → physics update → game state mutation
3. Renderer reads updated state → draws frame to Canvas
4. Collision or score event → game state triggers scoring logic → UI scoreboard updated
5. Hash change in URL → app.js router switches view (e.g., practice tab)
Architectural patterns and design principles
• Modular separation: input, game logic, rendering, and routing each in own file
• Single Responsibility: each ES6 class handles one domain object (Ball or Paddle)
• Event-driven loop: using requestAnimationFrame as the heartbeat
Specific elements
• Component names (app.js, controls.js, game.js, index.html, styles.css)