From edf8c813aa2163ed9c032e22cac72167c6dcb5e0 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Wed, 4 Dec 2019 11:27:02 -0500 Subject: [PATCH] Animate upgrade/building buttons a bit. Show text when buying upgrades --- gorge.css | 39 +++++++++++++++++++++++++++++++++++++-- gorge.js | 10 ++++++++-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/gorge.css b/gorge.css index 451c976..62859cb 100644 --- a/gorge.css +++ b/gorge.css @@ -166,8 +166,16 @@ button { color: #1a1; } -.building-button:hover { - background-color: #333; +#buildings-area:hover > #buildings:hover ~ .building-button:not(:hover) { + opacity: 1; +} + +#buildings-area:hover > .building-button:hover { + opacity: 1; +} + +#buildings-area:hover > .building-button:not(:hover) { + opacity: 0.6; } .building-button-disabled:hover { @@ -265,6 +273,11 @@ button { margin: 10px; display: block; background-color: #444; + transition: 0.2s; +} + +.upgrade-button:hover { + transform: scale(1.25, 1.25); } @media (max-aspect-ratio: 1/1) { @@ -315,6 +328,17 @@ button { --target: 200px; } +.click-popup-upgrade { + pointer-events: none; + transform-origin: -50% 50%; + text-align: center; + position: fixed; + animation: click-popup-upgrade 2s linear; + animation-fill-mode: both; + font-size: 36px; + --target: -200px; +} + @keyframes click-popup-food { 0% { transform: translate(0px, 0px) scale(1, 1); @@ -337,6 +361,17 @@ button { } } +@keyframes click-popup-upgrade { + 0% { + transform: translate(0px, 0px) scale(1, 1); + opacity: 1; + } + 100% { + transform: translate(var(--target), 200px) scale(0.5, 0.5); + opacity: 0; + } +} + div::-webkit-scrollbar { diff --git a/gorge.js b/gorge.js index 9a2ec22..feefee8 100644 --- a/gorge.js +++ b/gorge.js @@ -224,7 +224,7 @@ function updateClickBonus() { clickBonus = bonus; } -function buyUpgrade(id) { +function buyUpgrade(id, e) { if (ownedUpgrades[id]) { return; } @@ -239,6 +239,10 @@ function buyUpgrade(id) { ownedUpgrades[id] = true; + let text = "Bought " + upgrade.name + "!"; + + clickPopup(text, "upgrade", [e.clientX, e.clientY]); + updateProductivity(); updateClickBonus(); } @@ -451,7 +455,7 @@ function createUpgrades() { button.addEventListener("mousemove", function(e) { upgradeTooltip(key, e); }); button.addEventListener("mouseleave", function() { upgradeTooltipRemove(); }); - button.addEventListener("click", function() { buyUpgrade(key); }); + button.addEventListener("click", function(e) { buyUpgrade(key, e); }); container.appendChild(button); } @@ -563,6 +567,8 @@ function clickPopup(text, type, location) { direction = -150; } else if (type == "gulp") { direction = -150; + } else if (type == "upgrade") { + direction = -50; } direction *= Math.random() * 0.5 + 1;