Browse Source

Add a powerup that doubles food production for 10 seconds

tags/v0.0.4
Fen Dweller 5 years ago
parent
commit
7940442243
3 changed files with 49 additions and 9 deletions
  1. +6
    -7
      constants.js
  2. +1
    -0
      gorge.html
  3. +42
    -2
      gorge.js

+ 6
- 7
constants.js View File

@@ -1068,15 +1068,14 @@ const powerups = {
clickPopup("+1 car", "food", [e.clientX, e.clientY]); clickPopup("+1 car", "food", [e.clientX, e.clientY]);
} }
}, },
"nothing": {
name: "Nothing",
description: "Does nothing for 10 seconds",
icon: "fa-car",
"double": {
name: "Double Dip",
description: "Doubled productivity!",
icon: "fa-cogs",
duration: 10000, duration: 10000,
effect: state => state.belongings.car.count += 1,
effect: state => state.currentProductivity.food *= 2,
popup: (self, e) => { popup: (self, e) => {
clickPopup("CAR!", "gulp", [e.clientX, e.clientY]);
clickPopup("+1 car", "food", [e.clientX, e.clientY]);
clickPopup("VROOM!", "gulp", [e.clientX, e.clientY]);
} }
} }
} }

+ 1
- 0
gorge.html View File

@@ -32,6 +32,7 @@
<div id="resource-list"></div> <div id="resource-list"></div>
<div id="productivity"></div> <div id="productivity"></div>
<button id="tasty-micro">Eat Micro</button> <button id="tasty-micro">Eat Micro</button>
<div id="powerup-list"></div>
</div> </div>


<div id="upgrades-area"> <div id="upgrades-area">


+ 42
- 2
gorge.js View File

@@ -22,18 +22,36 @@ let lastTime = 0;
const activePowerups = []; const activePowerups = [];


function tickPowerups(delta) { function tickPowerups(delta) {
const powerupList = document.querySelector("#powerup-list");
let changed = false;
// I love mutating arrays as I traverse them. // I love mutating arrays as I traverse them.
for (let i = activePowerups.length-1; i >= 0; i--) { for (let i = activePowerups.length-1; i >= 0; i--) {
activePowerups[i].lifetime -= delta; activePowerups[i].lifetime -= delta;
if (activePowerups[i].lifetime <= 0) { if (activePowerups[i].lifetime <= 0) {
clickPopup("OOF", "info", [500, 500]); clickPopup("OOF", "info", [500, 500]);
powerupList.removeChild(activePowerups[i].element);
activePowerups.splice(i, 1); activePowerups.splice(i, 1);
changed = true;
} }
} }

if (changed) {
updateAll();
}
} }


function addPowerup(powerup) { function addPowerup(powerup) {
activePowerups.push({powerup: powerup, lifetime: powerup.duration});
const powerupList = document.querySelector("#powerup-list");

const powerupEntry = document.createElement("div");
powerupEntry.innerText = powerup.name;

powerupList.appendChild(powerupEntry);

activePowerups.push({powerup: powerup, lifetime: powerup.duration, element: powerupEntry});
updateAll();
} }


function applyGlobalProdBonuses(productivity) { function applyGlobalProdBonuses(productivity) {
@@ -133,6 +151,23 @@ function updateDisplay() {


function updateProductivity() { function updateProductivity() {
currentProductivity["food"] = calculateProductivity(); currentProductivity["food"] = calculateProductivity();

activePowerups.forEach(entry => {
const powerup = entry.powerup;
const state = {
ownedUpgrades: ownedUpgrades,
resources: resources,
currentProductivity: currentProductivity,
belongings: belongings
};

console.log(currentProductivity);

powerup.effect(state);
console.log(currentProductivity);
})
} }


function addResources(delta) { function addResources(delta) {
@@ -754,7 +789,12 @@ function doPowerup() {
}; };


button.addEventListener("mousedown", e => { button.addEventListener("mousedown", e => {
powerup.effect(state);
if (powerup.duration !== undefined) {
addPowerup(powerup);
} else {
powerup.effect(state);
}
powerup.popup(powerup, e); powerup.popup(powerup, e);
button.classList.add("powerup-clicked"); button.classList.add("powerup-clicked");
resources.food += 1000; resources.food += 1000;


Loading…
Cancel
Save