From f1809a322d9ca7f63c9e14121ea05754e8bb3217 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Tue, 17 Dec 2019 11:27:22 -0500 Subject: [PATCH] Add random popups that give food when clicked --- gorge.css | 32 ++++++++++++++++++++++++++++++++ gorge.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/gorge.css b/gorge.css index de600ec..8d0e43f 100644 --- a/gorge.css +++ b/gorge.css @@ -526,3 +526,35 @@ div::-webkit-scrollbar-corner { opacity: 0; } } + +.popup-micro { + position: fixed; + --leftpos: 50%; + --toppos: 50%; + --lifetime: 10s; + left: var(--leftpos); + top: var(--toppos); + width: 100px; + height: 100px; + font-size: 80px; + animation: popup-micro-frames var(--lifetime) linear; +} + +@keyframes popup-micro-frames { + 0% { + opacity: 0; + } + 20% { + opacity: 1; + } + 80% { + opacity: 1; + } + 100% { + opacity: 0; + } +} + +.popup-micro > .fas { + text-align: center; +} \ No newline at end of file diff --git a/gorge.js b/gorge.js index ea959c5..1be4a34 100644 --- a/gorge.js +++ b/gorge.js @@ -684,6 +684,51 @@ function showNews(text) { body.removeChild(div); }, 10000); } + +function doPopupMicro() { + const lifetime = 10000; + + const div = document.createElement("div"); + + const left = Math.round(Math.random() * 50 + 25) + "%"; + const top = Math.round(Math.random() * 50 + 25) + "%"; + + div.classList.add("popup-micro"); + + div.style.setProperty("--lifetime", lifetime/1000 + "s"); + div.style.setProperty("--leftpos", left); + div.style.setProperty("--toppos", top); + const icon = document.createElement("div"); + + icon.classList.add("fas"); + icon.classList.add("fa-drumstick-bite"); + + div.appendChild(icon); + + const body = document.querySelector("body"); + + body.appendChild(div); + + const remove = setTimeout(() => { + body.removeChild(div); + }, lifetime); + + setTimeout(() => { + doPopupMicro(); + }, 20000); + + div.addEventListener("click", e => { + clickPopup("GULP!", "gulp", [e.clientX, e.clientY]); + clickPopup("+1000 food", "food", [e.clientX, e.clientY]); + resources.food += 1000; + clearTimeout(remove); + body.removeChild(div); + }); + +} + + + function fillTooltip(type, field, content) { let item = document.querySelector("#" + type + "-tooltip-" + field); if (typeof(content) === "string") { @@ -784,6 +829,7 @@ window.onload = function() { lastTime = performance.now(); doNews(); + doPopupMicro(); setTimeout(updateDisplay, 1000/updateRate);