From bf854e7c23330efc01539682bf190780bb8743fc Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Wed, 25 Dec 2019 20:11:41 -0600 Subject: [PATCH] Add 10x click powerup --- constants.js | 9 +++++++++ gorge.js | 54 +++++++++++++++++++++++----------------------------- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/constants.js b/constants.js index 7fabbc8..e6788d4 100644 --- a/constants.js +++ b/constants.js @@ -1225,6 +1225,15 @@ const powerups = { popup: (self, e) => { clickPopup("VROOM!", "gulp", [e.clientX, e.clientY]); } + }, + "click": { + name: "Chaos Click", + description: "Ten times the clicking!", + icon: "fa-cursor", + duration: 10000, + prereqs: state => true, + effect: state => state.clickPowers.clickMultiplier *= 10, + popup: (self, e) => clickPopup("CLICK TIME!!", "gulp", [e.clientX, e.clientY]) } } diff --git a/gorge.js b/gorge.js index 157adf4..5eb7439 100644 --- a/gorge.js +++ b/gorge.js @@ -15,6 +15,12 @@ let updateRate = 60; const currentProductivity = {}; const contributions = {}; +const clickPowers = { + clickBonus: 0, + clickMultiplier: 1, + clickVictim: "micro" +} + let clickBonus = 0; let clickVictim = "micro"; @@ -25,6 +31,14 @@ let shiftHeld = false; let mouseTarget = undefined; +const state = { + ownedUpgrades: ownedUpgrades, + resources: resources, + currentProductivity: currentProductivity, + belongings: belongings, + clickPowers: clickPowers +}; + const numberModes = { words: { name: "Words", @@ -82,7 +96,6 @@ function tickPowerups(delta) { } function addPowerup(key, powerup) { - console.log(key, powerup) // powerup already exists if (activePowerups[key].life > 0) { activePowerups[key].life += powerup.duration; @@ -166,7 +179,6 @@ function addCost(cost1, cost2) { } function scaleCost(cost, scale) { - if (typeof(scale) != "number") console.log(scale) return Object.keys(resourceTypes).reduce((o, k) => {o[k] *= scale; return o;}, cost); } @@ -204,13 +216,11 @@ function buyBuilding(type, e) { } updateProductivity(); - updateClickBonus(); } function updateAll() { updateProductivity(); - updateClickBonus(); updateClickVictim(); updateOptions(); } @@ -239,21 +249,19 @@ function updateDisplay() { function updateProductivity() { Object.assign(currentProductivity, calculateProductivity()); + + // maybe this should go somewhere else - it also does clicking... + updateClickPowers(); + Object.entries(activePowerups).forEach(([key, entry]) => { if (entry.life > 0) { const powerup = entry.powerup; - - const state = { - ownedUpgrades: ownedUpgrades, - resources: resources, - currentProductivity: currentProductivity, - belongings: belongings - }; powerup.effect(state); } }); + } function addResources(delta) { @@ -407,8 +415,9 @@ function displayUpgrades(owned) { } } -function updateClickBonus() { +function updateClickPowers() { let bonus = 0; + clickPowers.clickMultiplier = 1; for (let effect of effects["click"]) { if (ownedUpgrades[effect.parent]) { @@ -416,13 +425,13 @@ function updateClickBonus() { } } - clickBonus = bonus; + clickPowers.clickBonus = bonus; } function updateClickVictim() { for (let effect of effects["click-victim"]) { if (ownedUpgrades[effect.parent]) { - clickVictim = effect.id; + clickPowers.clickVictim = effect.id; document.querySelector("#tasty-micro").innerText = "Eat " + buildings[effect.id].name; } } @@ -448,12 +457,11 @@ function buyUpgrade(id, e) { clickPopup(text, "upgrade", [e.clientX, e.clientY]); updateProductivity(); - updateClickBonus(); updateClickVictim(); } function eatPrey() { - const add = buildings[clickVictim]["prod"].food * 10 + clickBonus; + const add = clickPowers.clickMultiplier * (buildings[clickPowers.clickVictim]["prod"].food * 10 + clickPowers.clickBonus); resources.food += add; return add; } @@ -947,13 +955,6 @@ function clickPopup(text, type, location) { } function doNews() { - const state = { - ownedUpgrades: ownedUpgrades, - resources: resources, - currentProductivity: currentProductivity, - belongings: belongings - }; - let options = []; news.forEach(entry => { if (entry.condition(state)) { @@ -1005,13 +1006,6 @@ function doPowerup() { const choices = []; - const state = { - ownedUpgrades: ownedUpgrades, - resources: resources, - currentProductivity: currentProductivity, - belongings: belongings - }; - Object.entries(powerups).forEach(([key, val]) => { if (val.prereqs(state)) choices.push(key);