Stack falling blocks and clear lines.
Reach the goal score before the stack reaches the top. Filling a whole row clears it and scores points. If a new block has no room, the game is over.
You write these functions. The game calls them when something happens.
onLine(count)
Runs when you clear one or more lines. count says how many you cleared at once.
function onLine(count) {
score = score + count * 100;
}onLand()
Runs when a block lands without clearing any lines.
function onLand() {
score = score + 1;
}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.
Clear a line or two. onLine(count) gets the number of lines cleared at once, and by default each line is worth 100 points.
function onLine(count) {
score = score + count * 100;
}Clearing 4 lines at once is called a Tetris! Give it a big bonus, and score the normal 100 per line otherwise.
function onLine(count) {
if (count === 4) {
score = score + 1000;
} else {
score = score + count * 100;
}
}Make the game faster once your score passes 1000. Rules can depend on any variable, including the score itself.
function onLine(count) {
score = score + count * 100;
if (score >= 1000) {
speed = 3;
}
}A variable can be true or false. firstLine starts true, gives a bonus once, and is then switched off.
let firstLine = true;
function onLine(count) {
score = score + count * 100;
if (firstLine) {
score = score + 200;
firstLine = false;
}
}// ๐งฑ Tetris!
let goal = 500; // reach this score to win
let speed = 2; // 1 (slow) to 5 (fast)
// The game keeps a variable called lines: how many lines you have cleared in total.
// count is how many lines you just cleared in one go
function onLine(count) {
score = score + count * 100;
}
function onLand() {
score = score + 1;
}