Skip to content

Commit 1107351

Browse files
authored
Merge pull request #76 from geekahedron/main
Add popup with overlap percentage
2 parents af14f78 + 1269208 commit 1107351

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

Js/script.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,10 @@ function splitBlockAndAddNextOneIfOverlaps() {
412412
const overhangSize = Math.abs(delta);
413413
const overlap = size - overhangSize;
414414

415+
const overlapPercent = Math.max(0,Math.round((overlap / size) * 100));
416+
showOverlapPopup(overlapPercent);
417+
418+
415419
if (overlap > 0) {
416420
cutBox(top, overlap, size, delta);
417421
const shift = (overlap / 2 + overhangSize / 2) * Math.sign(delta);
@@ -440,6 +444,29 @@ function splitBlockAndAddNextOneIfOverlaps() {
440444
}
441445
}
442446

447+
// Function to display overlap percentage
448+
function showOverlapPopup(percent) {
449+
const popup = document.getElementById("overlap-popup");
450+
popup.textContent = `${percent}%`;
451+
452+
// Color feedback
453+
if (percent >= 90) {
454+
popup.style.background = "rgba(0, 128, 0, 0.8)"; // green
455+
} else if (percent >= 60) {
456+
popup.style.background = "rgba(255, 165, 0, 0.8)"; // orange
457+
} else {
458+
popup.style.background = "rgba(178, 34, 34, 0.8)"; // red
459+
}
460+
461+
popup.classList.add("show");
462+
463+
setTimeout(() => {
464+
popup.classList.remove("show");
465+
}, 1000);
466+
}
467+
468+
469+
443470
// Function to handle game over scenario
444471
function missedTheSpot() {
445472
const top = stack[stack.length - 1];

css/style.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,32 @@ body {
412412
animation: score-pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
413413
}
414414

415+
/* Overlop feedback styles */
416+
#overlap-popup {
417+
position: absolute;
418+
top: 20px;
419+
left: 50%;
420+
transform: translateX(-50%);
421+
background: rgba(0, 0, 0, 0.8);
422+
color: white;
423+
padding: 10px 20px;
424+
border-radius: 8px;
425+
font-family: 'Segoe UI', sans-serif;
426+
font-size: 18px;
427+
font-weight: bold;
428+
display: none;
429+
z-index: 1000;
430+
opacity: 0;
431+
transition: opacity 0.3s ease, transform 0.3s ease;
432+
}
433+
#overlap-popup.show {
434+
display: block;
435+
opacity: 1;
436+
transform: translateX(-50%) scale(1.05);
437+
}
438+
439+
440+
415441
#youtube {
416442
position: absolute;
417443
bottom: 10px;

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ <h1>Game Over!</h1>
9696
<!-- score box -->
9797
<div id="score">0</div>
9898

99+
<!-- overlap feedback box -->
100+
<div id="overlap-popup">100%</div>
101+
102+
99103
<!-- Theme Buttons -->
100104
<div id="theme-controls">
101105
<button id="theme-default" class="theme-btn active" data-tooltip="Default Theme">🌅</button>

0 commit comments

Comments
 (0)