|
|
|
@@ -688,44 +688,61 @@ function showNews(text) { |
|
|
|
function doPowerup() { |
|
|
|
const lifetime = 10000; |
|
|
|
|
|
|
|
const powerup = document.createElement("div"); |
|
|
|
const button = document.createElement("div"); |
|
|
|
|
|
|
|
const left = Math.round(Math.random() * 50 + 25) + "%"; |
|
|
|
const top = Math.round(Math.random() * 50 + 25) + "%"; |
|
|
|
|
|
|
|
powerup.classList.add("powerup"); |
|
|
|
button.classList.add("powerup"); |
|
|
|
|
|
|
|
powerup.style.setProperty("--lifetime", lifetime/1000 + "s"); |
|
|
|
powerup.style.setProperty("--leftpos", left); |
|
|
|
powerup.style.setProperty("--toppos", top); |
|
|
|
button.style.setProperty("--lifetime", lifetime/1000 + "s"); |
|
|
|
button.style.setProperty("--leftpos", left); |
|
|
|
button.style.setProperty("--toppos", top); |
|
|
|
const icon = document.createElement("div"); |
|
|
|
|
|
|
|
icon.classList.add("fas"); |
|
|
|
icon.classList.add("fa-drumstick-bite"); |
|
|
|
|
|
|
|
powerup.appendChild(icon); |
|
|
|
button.appendChild(icon); |
|
|
|
|
|
|
|
const body = document.querySelector("body"); |
|
|
|
|
|
|
|
body.appendChild(powerup); |
|
|
|
body.appendChild(button); |
|
|
|
|
|
|
|
const choices = []; |
|
|
|
|
|
|
|
Object.entries(powerups).forEach(([key, val]) => { |
|
|
|
choices.push(key); |
|
|
|
}); |
|
|
|
|
|
|
|
const choice = Math.floor(Math.random() * choices.length); |
|
|
|
|
|
|
|
const powerup = powerups[choices[choice]]; |
|
|
|
|
|
|
|
const remove = setTimeout(() => { |
|
|
|
body.removeChild(powerup); |
|
|
|
body.removeChild(button); |
|
|
|
}, lifetime); |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
doPowerup(); |
|
|
|
}, 20000); |
|
|
|
|
|
|
|
powerup.addEventListener("mousedown", e => { |
|
|
|
clickPopup("GULP!", "gulp", [e.clientX, e.clientY]); |
|
|
|
clickPopup("+1000 food", "food", [e.clientX, e.clientY]); |
|
|
|
powerup.classList.add("powerup-clicked"); |
|
|
|
const state = { |
|
|
|
ownedUpgrades: ownedUpgrades, |
|
|
|
resources: resources, |
|
|
|
currentProductivity: currentProductivity, |
|
|
|
belongings: belongings |
|
|
|
}; |
|
|
|
|
|
|
|
button.addEventListener("mousedown", e => { |
|
|
|
powerup.effect(state); |
|
|
|
powerup.popup(powerup, e); |
|
|
|
button.classList.add("powerup-clicked"); |
|
|
|
resources.food += 1000; |
|
|
|
clearTimeout(remove); |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
body.removeChild(powerup); |
|
|
|
body.removeChild(button); |
|
|
|
}, 500); |
|
|
|
}); |
|
|
|
|
|
|
|
|