Dam Beavers: Defend the Dam

Inspiration The idea for Dam Beavers: Defend the Dam came from flipping classic defensive conventions on their head. Rather than constructing static towers along the perimeter of a path, we wanted the player's primary defensive ammunition to be the very resource they harvest. Beavers naturally build dams to control water flow and create safe habitats; mechanizing the logging industry into relentless downriver intruders created an intuitive narrative and mechanical tension: gather timber to build your home, or weaponize that timber to protect it.

How It Was Built The entire game was engineered as a single, self-contained index.html file using native browser APIs to ensure 100% offline functionality within strict mobile portrait constraints: Rendering Engine: An HTML5 2D Canvas renders the multi-lane river corridor, procedural vector animations for woodcutter beavers, and dynamic elliptical wake ripples trailing floating logs. Input Architecture: Direct touch/pointer listeners calculate coordinates via getBoundingClientRect(), allowing players to tap river lanes directly to launch projectiles or forage from the banks. Audio Synthesis: A custom Web Audio API engine generates real-time procedural sound effects (wood chopping, projectile launches, impacts, alarms, and explosions) using oscillating waveforms without external audio files. State Management: Session states, scores, and upgrades serialize directly to localStorage, supporting instant pause, save, and reload flows.

Challenges Faced Mathematical Economy Balancing: Creating an economic curve that rewarded automation while preserving late-game tension required exponential scaling formulas. We calculated beaver hire costs as:$$\text{Cost}{n} = \lfloor \text{Cost}{0} \times 1.6^{n-1} \rfloor$$where $\text{Cost}_{0} = 40$ and $n$ represents the total number of beavers hired. This prevented resource inflation from trivializing higher waves. Clean Hitbox & Lane-Switching Collision: Coordinating collision detection across standard units, floating logs, and dynamic minion drones required balancing lane indexing with precise Axis-Aligned Bounding Box (AABB) checks:$$\Delta x < \frac{w_1 + w_2}{2} \quad \text{and} \quad \Delta y < \frac{h_1 + h_2}{2}$$This ensured lane-switching drones smoothly interpolated across the river without clipping through collision routines. Zero-Asset Visual Polish: Because no CDNs or external image assets were permitted, every visual cue—from wagging beaver tails to 3-lane dreadnought saw blades—had to be mathematically rendered via canvas path routines and trigonometric time functions like $\sin(\omega t + \phi)$.

Key Learnings Scaffolding Core Loops Over Feature Creep: Prioritizing the core harvest-and-launch loop early created a solid foundation that easily accommodated boss mechanics, secondary upgrades, and particle effects later. Decoupling Currency from Scoring: Separating consumable upgrade coins from persistent survival scores ($\text{Score} = (\text{Wave} - 1) \times 100$) delivered a far more accurate and competitive survival benchmark. Native Web Power: Complex animations, sound synthesis, and state persistence can run with high performance and zero external dependencies when fully leveraging modern vanilla web standards.

Built With

Share this project:

Updates

Submission history