webdevpuneet.com

Dodge the Blocks Game: Neon Stages, Lasers and Dash

Dodge the Falling Blocks Game · Games · Plain HTML, CSS & JS · Live preview

CategoryGames

For supporters

Source Code

Want the source code?

Play the game for free. Become a WebDevPuneet supporter to unlock the complete HTML, CSS and JavaScript source code, the exports (HTML, React, Vue, Angular, Tailwind) and Fork.

Play freeSource code: Patreon

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

Five stage types introduced every 20 seconds: blocks, zig-zag blocks, walls with a gap, telegraphed lasers, then everything
Continuously rising fall speed and spawn rate, narrowing wall gaps, and a breather with a banner at each stage
Acceleration-based steering with tilt, drag-to-move for touch, and an invulnerable dash with a cooldown meter
Near-miss detection with a combo multiplier up to x5
Stars plus shield, slow-motion and shrink power-ups
A synthwave backdrop painted once, a scrolling perspective grid, speed streaks and neon hazards
Additive particles for engine sparks, dash trails and the crash, plus screen shake
On-screen ◀ DASH ▶ buttons, keyboard and drag controls, pause and mute
Web Audio sound effects and a best score in localStorage with try/catch

About this UI Snippet

Dodge the Blocks: Stage-Based Difficulty, Near-Miss Combos and a Synthwave Look

Screenshot of the Dodge the Falling Blocks Game snippet rendered live

Dodge the Blocks is a one-axis survival game: hazards fall from the top and you steer a hover-car left and right at the bottom to avoid them for as long as you can. This snippet turns that simple idea into a full game on one HTML5 <canvas>, with no libraries and no image files. It has a synthwave look (a striped sun, mountains and a scrolling perspective grid), new hazard types introduced stage by stage, a dash move, near-miss combos, collectible stars and three power-ups. It plays with the arrow keys or A and D, on-screen buttons, or by dragging on the game.

Stages that teach one hazard at a time

Every 20 seconds a new stage begins, announced with a banner, a 1.6-second breather with no spawns, and a bonus. Stage 1 is plain falling blocks; stage 2 adds zig-zag blocks that swing side to side as they fall; stage 3 adds walls that span the whole width except for one gap; stage 4 adds lasers that flash a dashed warning line for almost a second before firing a full-height beam; stage 5 and beyond mixes everything. Fall speed and spawn rate rise continuously, and the gaps in walls slowly narrow, so the difficulty keeps climbing between stage changes too.

Movement that feels responsive

With keys or buttons the car accelerates and glides to a stop instead of moving a fixed step per frame, and it tilts with its speed. Dragging on the canvas pulls the car toward your finger like a spring. The dash fires the car sideways at high speed for 0.18 seconds, during which it cannot be hit, which makes it the tool for squeezing through a closing wall gap or escaping a laser warning; it then needs 1.6 seconds to recharge, shown by a meter.

Near misses, stars and power-ups

While a hazard passes the car's row, the game tracks the smallest horizontal gap between them. If it was under 9 pixels when the hazard leaves, you get a "CLOSE!" bonus, and consecutive near misses within two seconds build a combo up to x5 that also multiplies stars. Stars are worth 50 points. Power-ups are a shield (absorbs one hit and destroys the hazard), slow motion (the world runs at half speed for five seconds but your car does not) and shrink (a smaller car for six seconds). The score is ten points per second survived plus all bonuses, and the best score is saved in localStorage.

Neon rendering

Hazards are drawn as dark slabs with a bright outline, a soft outer glow and a highlight strip, in a random colour from a neon palette. The backdrop is painted once into an off-screen canvas; the grid floor scrolls faster as the game speeds up, speed streaks fall through the scene, and particles use additive blending so engine sparks, dash trails and the crash explosion glow. Sound effects come from the Web Audio API, with a mute button, and the game pauses on P, a button or a tab switch.

Step by step

How to Use

  1. 1
    Start and steerPress Start. Move with the arrow keys or A and D, the ◀ ▶ buttons, or by dragging on the game. The car accelerates and glides, so tap for small moves.
  2. 2
    Survive the stagesEvery 20 seconds a new stage adds a hazard: zig-zag blocks, then walls with a single gap, then lasers. A banner names the new hazard and you get a short breather.
  3. 3
    Dash through troublePress Space, Shift, the up arrow or DASH to shoot sideways for a split second; you cannot be hit while dashing. The meter at the bottom left shows when it is ready again.
  4. 4
    Watch for laser warningsA blinking dashed red line with a ! means a laser will fire there in under a second. Move away or dash across it before the beam appears.
  5. 5
    Skim for combosPass a block with less than 9 pixels to spare for a CLOSE! bonus. Near misses in quick succession build a combo up to x5, which also multiplies stars.
  6. 6
    Grab stars and power-upsStars are 50 points. S is a shield, T is slow motion for the world and M shrinks your car. Your best score is saved in your browser.

Real-world uses

Common Use Cases

Learning difficulty design
Introducing one hazard per stage with a breather in between is a clear example of teaching players new mechanics gradually.
A one-thumb mobile game template
Drag-to-move, a big DASH button and simple rules make it comfortable on a phone and easy to adapt.
A synthwave canvas style
The striped sun, perspective grid and neon outlines show how to get a strong retro look from a few gradients and lines.
An interactive 404 page or loading screen
A quick survival game works as a distraction while something loads, like the Space Blaster Arcade Game.
A base for an endless dodger
Hazard types are small objects with their own update and collision rectangles, so new patterns slot into spawn() easily.

Got questions?

Frequently Asked Questions

While a falling hazard overlaps the car's row vertically, the game measures the horizontal gap between the two rectangles and keeps the smallest one. When the hazard has passed below the car, a gap under 9 pixels counts as a near miss, adds 10 points times the current combo and raises the combo by one (up to x5).

A laser first spends about 0.95 seconds as a blinking dashed warning line with an exclamation mark, then fires a full-height beam for about 0.38 seconds. It only collides while the beam is active, so you always have time to move or dash away.

Dash launches the car sideways in the direction you last moved at high speed for 0.18 seconds. During a dash the car cannot be hit, so you can pass through a wall edge or a laser beam. It then recharges for 1.6 seconds.

Ten points per second survived, plus near-miss bonuses, stars (50 times the combo), and a stage bonus of 100 times the stage number reached minus one. The best score is stored in localStorage.

fallSpeed() sets how fast hazards fall over time, the spawn interval in update() sets how often they appear, STAGE_LEN sets how long each stage lasts, and spawn() holds the chance of each hazard type. Larger wall gaps and a shorter DASH_CD make it easier.