Parcourir la source

Add random popups that give food when clicked

tags/v0.0.4
Fen Dweller il y a 5 ans
Parent
révision
f1809a322d
2 fichiers modifiés avec 78 ajouts et 0 suppressions
  1. +32
    -0
      gorge.css
  2. +46
    -0
      gorge.js

+ 32
- 0
gorge.css Voir le fichier

@@ -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;
}

+ 46
- 0
gorge.js Voir le fichier

@@ -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);



Chargement…
Annuler
Enregistrer