From cd468417c61a9c98518518304733b08d72edfa4f Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Tue, 17 Dec 2019 14:57:34 -0500 Subject: [PATCH] Make powerups appear more slowly; add upgrades to speed them up --- constants.js | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++- gorge.js | 10 +++++++- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/constants.js b/constants.js index 4d5ac9a..86b5cf7 100644 --- a/constants.js +++ b/constants.js @@ -197,6 +197,14 @@ const effect_types = { "desc": function(effect) { return "Devour larger prey"; } + }, + "powerup-freq": { + "apply": function(effect, delay) { + return delay * effect.amount; + }, + "desc": function(effect) { + return "Speed up powerup spawns by " + Math.round((1 / effect.amount - 1) * 100) + "%"; + } } } @@ -210,6 +218,7 @@ function createTemplateUpgrades() { createClickUpgrades(); createHelperUpgrades(); createClickVictimUpgrades(); + createPowerupFreqUpgrades(); } const prodUpgradeCounts = [1, 5, 10, 25, 50, 75, 100]; @@ -335,7 +344,6 @@ function createHelperUpgrades() { for (let text of texts) { const key = prefix + infix + suffix + "-" + counter; - console.log(key); upgrades[key] = { "name": text.name, "desc": text.desc, @@ -405,6 +413,38 @@ function createClickVictimUpgrades() { }); } + +function createPowerupFreqUpgrades() { + const prefix = "powerup-freq-"; + let counter = 1; + powerupFreqUpgradeText.forEach(text => { + upgrades[prefix + counter] = { + "name": text.name, + "desc": text.desc, + "icon": "fa-drumstick-bite", + "cost": { + "food": 1000 * Math.pow(10, counter) + }, + "effects": [ + { + "type": "powerup-freq", + "id": prefix + counter, + "amount": 0.5 + } + ], + "prereqs": { + "upgrades": [ + + ] + } + }; + if (counter > 1) { + upgrades[prefix + counter].prereqs.upgrades.push(prefix + (counter - 1)); + } + counter += 1; + }); +} + let prodUpgradeText = { "micro": [ { @@ -1003,6 +1043,28 @@ const clickVictimUpgradeText = { } }; +const powerupFreqUpgradeText = [ + { + name: "powerup-freq-1", + desc: "", + }, + { + name: "powerup-freq-2", + desc: "", + }, + { + name: "powerup-freq-3", + desc: "", + }, + { + name: "powerup-freq-4", + desc: "", + }, + { + name: "powerup-freq-5", + desc: "", + } +] // to avoid yoinking stuff from global variables directly... // state.ownedUpgrades == ownedUpgrades diff --git a/gorge.js b/gorge.js index e549920..be067e1 100644 --- a/gorge.js +++ b/gorge.js @@ -826,9 +826,17 @@ function doPowerup() { body.removeChild(button); }, lifetime); + let delay = 60000 + Math.random() * 30000; + + for (let effect of effects["powerup-freq"]) { + if (ownedUpgrades[effect.parent]) { + delay = effect.apply(delay); + } + } + setTimeout(() => { doPowerup(); - }, 20000); + }, delay); const state = { ownedUpgrades: ownedUpgrades,