url-tetris

tetris inside the browser address bar
git clone https://tongong.net/git/url-tetris.git
Log | Files | Refs | README

commit be3578ac63f9bc1f6519117988ba5d2ecc7b1ff0
parent c18f6a81a428ab5ea02b34682a284af49c434cfb
Author: tongong <tongong@gmx.net>
Date:   Mon,  1 Jun 2020 12:51:29 +0200

increased difficulty; added highscore system

Diffstat:
Mmain.js | 10+++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/main.js b/main.js @@ -47,6 +47,7 @@ var fallingTetrominoes = []; var score; var playing = false; var timer; +var speed; function FallingTetromino(tetrominoIndex, posX, posY) { this.tetrominoIndex = tetrominoIndex; @@ -125,6 +126,7 @@ function checkRows() { row = field[index]; if (row.reduce((a, b) => a + b) == 4) { score++; + speed *= 0.97; field.splice(index, 1); field.push([0, 0, 0, 0]); document.title = "Score: " + score; @@ -135,8 +137,9 @@ function checkRows() { console.log(field[20].reduce((a, b) => a + b) > 0); if (field[20].reduce((a, b) => a + b) > 0) { playing = false; - setUrl("Game Over! Score: " + score); - document.title = "url-tetris" + if (score > (localStorage.getItem("highscore") || -1)) localStorage.setItem("highscore", score); + setUrl("Game Over! Score: " + score + " | High Score: " + localStorage.getItem("highscore")); + document.title = "url-tetris"; window.clearTimeout(timer); } } @@ -246,6 +249,7 @@ function rightPressed() { } function startGame() { + speed = 600; field = []; fallingTetrominoes = []; score = 0; @@ -263,7 +267,7 @@ function frame() { if (playing) { fallingTetrominoes.forEach((e) => e.goLeft()); renderTetrominoes(); - timer = window.setTimeout(frame, 1000); + timer = window.setTimeout(frame, speed); } }