瀏覽代碼

Add random popups that give food when clicked

tags/v0.0.4
Fen Dweller 5 年之前
父節點
當前提交
f1809a322d
共有 2 個檔案被更改,包括 78 行新增0 行删除
  1. +32
    -0
      gorge.css
  2. +46
    -0
      gorge.js

+ 32
- 0
gorge.css 查看文件

@@ -526,3 +526,35 @@ div::-webkit-scrollbar-corner {
opacity: 0; 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 查看文件

@@ -684,6 +684,51 @@ function showNews(text) {
body.removeChild(div); body.removeChild(div);
}, 10000); }, 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) { function fillTooltip(type, field, content) {
let item = document.querySelector("#" + type + "-tooltip-" + field); let item = document.querySelector("#" + type + "-tooltip-" + field);
if (typeof(content) === "string") { if (typeof(content) === "string") {
@@ -784,6 +829,7 @@ window.onload = function() {
lastTime = performance.now(); lastTime = performance.now();


doNews(); doNews();
doPopupMicro();


setTimeout(updateDisplay, 1000/updateRate); setTimeout(updateDisplay, 1000/updateRate);




Loading…
取消
儲存