From 0d8b03841b08496fc1578aba38000323d5913be0 Mon Sep 17 00:00:00 2001 From: flo <> Date: Wed, 2 Apr 2025 11:55:52 +0200 Subject: [PATCH] level and speed change. --- public/index.html | 2 +- public/script/index.js | 58 +++++++++++++++++++++++++++++++++++++++++- public/style/index.css | 4 +-- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/public/index.html b/public/index.html index 6c7682e..ef9149c 100644 --- a/public/index.html +++ b/public/index.html @@ -17,7 +17,7 @@

- +
diff --git a/public/script/index.js b/public/script/index.js index 07445e0..e654c2f 100644 --- a/public/script/index.js +++ b/public/script/index.js @@ -22,7 +22,7 @@ let leftInterval; let keyPress = []; let score = 0; -let level = 1; +let level = 0; let lines = 0; let speed = 1000; @@ -98,6 +98,39 @@ const templateColor = [ [255, 40, 130, 200] ]; +const speedSecondsToBotomPerLevel = [ + 15.974, //0 + 14.31, //1 + 12.646, //2 + 10.982, //3 + 9.318, //4 + 7.654, //5 + 5.99, //6 + 4.326, //7 + 2.662, //8 + 1.997, //9 + 1.664, //10 + 1.664, //11 + 1.664, //12 + 1.331, //13 + 1.331, //14 + 1.331, //15 + 0.998, //16 + 0.998, //17 + 0.998, //18 + 0.666, //19 + 0.666, //20 + 0.666, //21 + 0.666, //22 + 0.666, //23 + 0.666, //24 + 0.666, //25 + 0.666, //26 + 0.666, //27 + 0.666, //28 + 0.333 //29 +]; + let currentPiece = []; let color = [] @@ -304,6 +337,10 @@ function checkLine() { } } + for (let k = 0; k < 10; k++) { + boardData[k][0] = [0, 0, 0, 255]; + } + lineFilled++; } } @@ -322,6 +359,24 @@ function checkLine() { } scoreElement.innerText = score; + lines += lineFilled; + level = Math.floor(lines / 10); + initAndChangeSpeedDrop(); +} + +function initAndChangeSpeedDrop() { + if (level > 29) { + speed = (speedSecondsToBotomPerLevel[29]/20) * 1000; + } + else { + speed = (speedSecondsToBotomPerLevel[level]/20) * 1000; + } + clearInterval(downInterval); + downInterval = setInterval(() => { + moveDown(); + + refresh(); + }, speed); } function moveTo(x, y) { @@ -380,6 +435,7 @@ function fasteDrop() { } img.onload = () => { + initAndChangeSpeedDrop(); loadTetris(); refresh(); diff --git a/public/style/index.css b/public/style/index.css index 69a4a0b..09cb90e 100644 --- a/public/style/index.css +++ b/public/style/index.css @@ -29,8 +29,8 @@ body { } .tetris { - width: 200px; - height: 400px; + width: 300px; + height: 600px; } .first {