Dodge the traffic and grab the boosts.
Reach the goal score before you run out of lives. You score for every rival you pass, and boosts give bonuses. Crashing costs lives.
You write these functions. The game calls them when something happens.
onPass()
Runs every time a rival car goes past you safely.
function onPass() {
score = score + 1;
}onCrash()
Runs when you hit a rival.
function onCrash() {
lives = lives - 1;
}onPickup()
Runs when you drive over a boost.
function onPickup() {
score = score + 5;
}onTick()
Runs at every moment of the race. Use it to change things as you drive.
function onTick() {
// try changing speed here
}Variables at the top of your code are the game's settings. Change a value, press Play, and see what happens.
Each step shows code you can add to the end of your game's code. A function or variable written later replaces the earlier one, so you never have to delete anything.
Steer between the cars. Passing a rival runs onPass, crashing runs onCrash, and a boost runs onPickup.
function onPass() {
score = score + 1;
}More traffic means more to dodge.
let traffic = 5;onTick runs every moment, and distance counts up as you drive. You can make something happen at a certain distance. Here the race jumps to speed 4 at distance 50.
function onTick() {
if (distance === 50) {
speed = 4;
}
}A boost makes you faster, and a crash puts you back to slow. Changing speed in the functions makes the race feel alive.
function onPickup() {
score = score + 5;
speed = Math.min(5, speed + 1);
}
function onCrash() {
lives = lives - 1;
speed = 1;
}// ๐๏ธ Racing!
let car = "๐๏ธ";
let rival = "๐";
let boost = "๐";
let goal = 50; // reach this score to win
let lives = 3;
let speed = 2; // 1 (slow) to 5 (fast)
let traffic = 3; // 0 (empty road) to 5 (very busy)
// The game keeps a variable called distance: how far you have driven.
function onPass() {
score = score + 1;
}
function onCrash() {
lives = lives - 1;
}
function onPickup() {
score = score + 5;
}
// runs every moment of the race
function onTick() {
// try changing speed here
}