Browse Source

Add basic functionality: resources that go up if you own stuff

tags/v0.0.1
Fen Dweller 7 years ago
commit
8b212b5d00
No known key found for this signature in database GPG Key ID: E80B35A6F11C3656
5 changed files with 130 additions and 0 deletions
  1. +29
    -0
      constants.js
  2. +22
    -0
      gorge.html
  3. +65
    -0
      gorge.js
  4. +3
    -0
      numbers.js
  5. +11
    -0
      polyfill.js

+ 29
- 0
constants.js View File

@@ -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
}
}

+ 22
- 0
gorge.html View File

@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<title>Gorge</title>
<link rel="stylesheet" href="style.css">
<script src="polyfill.js"></script>
<script src="constants.js"></script>
<script src="numbers.js"></script>
<script src="gorge.js"></script>
<meta name="theme-color" content="#000000" />
<meta name="description" content="An idle game about eating people" />
<meta property="og:title" content="Stroll" />
<meta property="og:description" content="An idle game about eating people" />
<meta property="og:image" content="https://chemicalcrux.org/gorge.png" />
<link rel="shortcut icon" href="https://chemicalcrux.org/favicon.ico" type="image/x-icon" />
</head>

<body>
<div id="resource-food">Food: 0</div>
</body>

+ 65
- 0
gorge.js View File

@@ -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);
}

+ 3
- 0
numbers.js View File

@@ -0,0 +1,3 @@
function render(val) {
return Math.round(val);
}

+ 11
- 0
polyfill.js View File

@@ -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;
};

Loading…
Cancel
Save