Lesson 7 of 7
Project: Rally
Your first arcade game! A car on two lanes, an incoming obstacle, a score that climbs when you dodge it.
The rules are precise — code them one by one: collision first, then the tick, keyboard last.
function crash(c, o) {
var d = o.x - c.x;
return d > -30 && d < 30 && c.lane === o.lane;
}🎯 Your goal
Build the game: var car = {x: 50, lane: 1}, var obstacle = {x: 300, lane: 1}, var score = 0. 1) The crash(c, o) function returns true when the distance o.x - c.x is strictly between -30 and 30 AND c.lane === o.lane. 2) The tick() function subtracts 5 from obstacle.x; when obstacle.x drops below 0, it restarts at 300 and score goes up by 1. 3) The right arrow (ArrowRight) adds 10 to car.x.
PRO lesson
This advanced chapter is part of CodeAge PRO. Unlock it to keep your adventure going.
Discover PRO →