Frog Crossing Game: Traffic, Logs and Diving Turtles
Frog Crossing Game · Games · Plain HTML, CSS & JS · Live preview
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.
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.
What's included
Features
About this UI Snippet
Frog Crossing: Tile Hops, Riding Platforms, Diving Turtles and Hand-Drawn Canvas Art

Frog Crossing is the classic road-and-river arcade game: hop up through four lanes of traffic, cross a river by riding logs and turtles, and land the frog in each of the five lily-pad homes at the top. This snippet builds a complete version on one HTML5 <canvas> with no libraries and no image files. Every car, truck, bulldozer, log, turtle, fly and the frog itself is drawn with canvas paths, and the scenery (hedge, grass with flowers, asphalt with lane lines and curbs) is painted once into an off-screen canvas. It plays with the arrow keys or WASD, an on-screen D-pad, or swipes and taps on the game.
Hops are tweens between tiles
The frog lives on a 9 by 11 grid of 40-pixel tiles. A hop is a 0.11-second tween from one tile to the next: frogX() and frogY() interpolate the position, the sprite lifts and stretches its legs at the top of the arc, and it rotates to face the way it jumped. A key pressed during a hop is queued and fires the moment the frog lands, so quick double-taps feel responsive. On land the frog snaps back to the nearest column; on water it keeps its exact position so it can ride.
Lanes that wrap forever
Each lane is a row of evenly spaced items (cars, trucks, logs or turtle groups) moving at its own speed. When an item leaves one side it jumps back by the lane's full repeat length, so traffic never runs out and the spacing never changes. Cars are tested every frame, even in mid-hop, against a slightly smaller hitbox. In the river the rule is reversed: the frog must be standing on a log or a turtle, and it drifts with it. Drifting off the edge of the screen is a splash.
Diving turtles, flies and the timer
Some turtle groups dive on a 7-second cycle: they float, blink while sinking (still safe), vanish under ripples (not safe) and rise again, so you have to time your crossing. Every life has 30 seconds, shown as a bar that turns yellow and red and ticks in the last five seconds, and the time you have left becomes a bonus when you reach a home. Now and then a fly lands in an empty home, worth 200 more points if you get there in time. Hitting the hedge between homes, or a home that is already full, costs a life.
Levels and scoring
Every new row you reach is worth 10 points, a home 50 plus the time bonus, and filling all five homes 1000 and the next level. Each level makes the traffic faster and denser, spaces the logs further apart and makes more turtles dive. An extra life comes at 5000 points. Deaths have their own animation (a squashed frog on the road, splash rings in the river), and sound effects for hops, homes, flies, splats, splashes and the level fanfare are made with the Web Audio API, with a mute button. The game pauses on P, a button or a tab switch, and the best score is kept in localStorage.
Step by step
How to Use
- 1HopPress Hop in, then hop with the arrow keys or WASD, the D-pad, or by swiping on the game (a quick tap hops forward). A press during a hop is queued.
- 2Cross the roadFour lanes of trucks, sports cars, cars and bulldozers move at different speeds and directions. Wait for a gap, hop, and use the grass strip in the middle as a safe stop.
- 3Ride across the riverYou cannot swim: land on a log or a turtle and ride it. Turtles that blink are about to dive, so hop off before they go under, and do not drift off the edge.
- 4Fill the five homesLand exactly in a lily-pad notch. Hitting the hedge or a full home costs a life. A fly in a home is worth 200 more.
- 5Beat the clockEach life has 30 seconds. The bar at the bottom shows the time, and whatever is left becomes a bonus when you reach a home.
- 6Clear levelsFill all five homes for +1000 and the next level, where the traffic is faster and more turtles dive. Press P to pause; your best score is saved.
Real-world uses
Common Use Cases
Got questions?
Frequently Asked Questions
When the frog is on a water row and not in mid-hop, the game looks for an item in that lane under the frog (and, for turtles, one that is not under water). If there is none the frog drowns; if there is one, the frog moves by the lane speed every frame, which carries it along. Moving past either edge of the screen also ends in a splash.
Some turtle groups have a timer that runs on a 7-second cycle: about 4 seconds floating, a blinking sinking phase (still safe), a phase under water (not safe) and a rising phase. On level 3 and above every second group dives instead of every third.
Collisions with traffic are checked every frame using the frog's interpolated position, not only when it lands, so hopping into the side of a passing car still counts. The car hitbox is a few pixels smaller than the drawing so near misses feel fair.
Each new row you reach in a life gives 10 points, a home gives 50 plus 10 for every second left on the timer, a fly in that home gives 200 more, and filling all five homes gives 1000. An extra life is awarded at 5000 points.
The LANES object maps each row to what moves in it (log, turtle, truck, sport, car or dozer), its speed in pixels per second (positive moves right), the item length in tiles and the gap in tiles. buildLanes() applies the level scaling, so a change there carries through every level.
Yes. Swipe in any direction to hop that way, tap to hop forward, or use the D-pad. The game pauses on its own when you switch tabs.