commit 8b212b5d00bdf28973e135b1dd3479f19f03ee69 Author: Fen Dweller Date: Mon Jul 16 21:48:46 2018 -0500 Add basic functionality: resources that go up if you own stuff diff --git a/constants.js b/constants.js new file mode 100644 index 0000000..dfb85e9 --- /dev/null +++ b/constants.js @@ -0,0 +1,29 @@ +"use strict"; + +const buildings = { + "micro": { + "name": "Micro", + "cost": 1e1, + "prod": 0.1 + }, + "anthro": { + "name": "Anthro", + "cost": 1e2, + "prod": 2 + }, + "car": { + "name": "Car", + "cost": 1e3, + "prod": 5 + }, + "train": { + "name": "Train", + "cost": 1e4, + "prod": 25 + }, + "house": { + "name": "House", + "cost": 1e5, + "prod": 100 + } +} diff --git a/gorge.html b/gorge.html new file mode 100644 index 0000000..9302650 --- /dev/null +++ b/gorge.html @@ -0,0 +1,22 @@ + + + + + + Gorge + + + + + + + + + + + + + + +
Food: 0
+ diff --git a/gorge.js b/gorge.js new file mode 100644 index 0000000..8127928 --- /dev/null +++ b/gorge.js @@ -0,0 +1,65 @@ +"use strict"; + +let belongings = {} + +let resources = { + "food": 0 +} + +let updateRate = 60; + +// setup stuff lol + +// we'll initialize the dict of buildings we can own + +function setup() { + for (const [key, value] of Object.entries(buildings)) { + belongings[key] = {}; + belongings[key].count = 0; + } + + console.log(belongings) +} + +function price(type) { + return buildings[type].cost * Math.pow(1.02, belongings[type].count) +} + +function calculateProductivity() { + let productivity = 0; + for (const [key, value] of Object.entries(belongings)) { + productivity += productivityOf(key); + } + return productivity; +} + +// here's where upgrades will go :3 + +function productivityOf(type) { + let baseProd = buildings[type].prod; + + return baseProd * belongings[type].count; +} + +// update stuff + +function updateResources() { + addResources(); + displayResources(); + + setTimeout(updateResources, 1000/updateRate); +} + +function addResources() { + resources.food += calculateProductivity() * 1 / updateRate; +} + +function displayResources() { + document.getElementById("resource-food").innerText = "Food: " + render(resources.food); +} + +window.onload = function() { + setup(); + + setTimeout(updateResources, 1000/updateRate); +} diff --git a/numbers.js b/numbers.js new file mode 100644 index 0000000..455547c --- /dev/null +++ b/numbers.js @@ -0,0 +1,3 @@ +function render(val) { + return Math.round(val); +} diff --git a/polyfill.js b/polyfill.js new file mode 100644 index 0000000..207a036 --- /dev/null +++ b/polyfill.js @@ -0,0 +1,11 @@ +if (!Object.entries) + console.log("Your browser doesn't support Object.entries()") + Object.entries = function( obj ){ + var ownProps = Object.keys( obj ), + i = ownProps.length, + resArray = new Array(i); // preallocate the Array + while (i--) + resArray[i] = [ownProps[i], obj[ownProps[i]]]; + + return resArray; + };