# Cyber Surfer: Infinite Neon Runner Welcome to the development blueprint and complete codebase for **Cyber Surfer**, a retro-futuristic, lane-based pseudo-3D endless runner built from scratch using HTML5, CSS3, and Vanilla JavaScript. --- ## πŸš€ Playable Game Code (`index.html`) Here is the complete, self-contained implementation of the game. Save this code as `index.html` on your computer and double-click to play! ```html Cyber Surfer: Infinite Neon Runner
COINS: 0 | SCORE: 0
MULT: x1

CYBER SURFER

[A] [D] or [Left/Right Arrows] to change lanes.
[W] or [Up Arrow] to Jump.
[S] or [Down Arrow] to Slide.

On Mobile, swipe in any direction or use the on-screen buttons to control!
``` --- ## πŸ› οΈ Game Architecture & Design Document To understand how the game works underneath the hood, here is the breakdown of the core mechanics and algorithms used: ### 1. The Pseudo-3D Perspective Engine Classic 16-bit endless runners (and early browser games) do not use expensive WebGL calculations. Instead, they use mathematical perspective projections to project 3D coordinates onto a 2D viewport. Every element (obstacles, coins, players, track points) has a virtual 3D position $(worldX, worldY, worldZ)$. The core mathematical projection function inside the game is: $$x_{screen} = \frac{width_{canvas}}{2} + worldX \times scale$$ $$y_{screen} = horizonY + (groundYOffset - worldY) \times scale$$ $$scale = \frac{fov}{worldZ}$$ - **`worldZ` (Distance):** Serves as depth. Spawners place objects on the horizon ($worldZ = 300$). As objects approach the screen, `worldZ` decreases to `0`. - **`scale` (Perspective Factor):** At the horizon ($worldZ = 300$), `scale` is tiny, causing objects to shrink and cluster around the center. As `worldZ` approaches `15` (the player's position), `scale` increases exponentially, making obstacles slide rapidly off the screen. ### 2. Collisions & Physics Matrix Our character operates on simple kinematic equations to manage jump gravitational forces, dive speeds, and slide duck durations. - **Gravity Jump:** When the jump is triggered, `jumpVelocity` is set to positive. Each frame, `worldY` increments by `jumpVelocity`, and `jumpVelocity` is decreased by `gravity`. Once `worldY` drops below $0$, we anchor it back to ground level and stop the physics transition. - **Bounding Box Slicing:** Because the camera stays locked at a set player depth ($worldZ = 15$), collision detection checks if an obstacle's depth `obs.z` overlaps the player's zone ($12 \le z \le 18$). If it matches, the math queries lateral lane offsets ($X$ coordinates) and vertical $Y$ overlaps. ### 3. Procedural Hazard Spawner To guarantee an endless but always beatable pathway (which is key to Subway Surfers' design), the procedural generator picks from predefined lane combinations: 1. **The Single Block:** Spawns a laser hurdle or a suspended block in one lane while keeping two other lanes completely clear. 2. **The Double Arch Gate:** Blocks two lanesβ€”for example, a high archway in Lane 1 (must slide under) and a train in Lane 2 (cannot pass), leaving Lane 3 completely open. 3. **The Cluster Track:** Groups collectible coins in winding lines (sometimes floating over lasers to guide the player into jumping). --- ## πŸ“ˆ Ideas for Extensions Ready to customize and expand your game? Here are a few ways to build on this framework: * **Add Power-ups:** Create a **Coin Magnet** (which pulls coins in adjacent lanes toward the player by updating their `lane` to match the player's lane when $worldZ < 80$), or a **Hover Shield** to survive one crash. * **Implement a Speedometer:** Draw a circular neon dial on the canvas representing the player's board speed in kilometers per hour. * **Visual Skins:** Design alternative hoverboard designs (such as fire particle trails or glowing neon grids) that unlock as players save up coins in `localStorage`!