cookie clicker but bigger
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

66 rindas
1.2 KiB

  1. "use strict";
  2. let belongings = {}
  3. let resources = {
  4. "food": 0
  5. }
  6. let updateRate = 60;
  7. // setup stuff lol
  8. // we'll initialize the dict of buildings we can own
  9. function setup() {
  10. for (const [key, value] of Object.entries(buildings)) {
  11. belongings[key] = {};
  12. belongings[key].count = 0;
  13. }
  14. console.log(belongings)
  15. }
  16. function price(type) {
  17. return buildings[type].cost * Math.pow(1.02, belongings[type].count)
  18. }
  19. function calculateProductivity() {
  20. let productivity = 0;
  21. for (const [key, value] of Object.entries(belongings)) {
  22. productivity += productivityOf(key);
  23. }
  24. return productivity;
  25. }
  26. // here's where upgrades will go :3
  27. function productivityOf(type) {
  28. let baseProd = buildings[type].prod;
  29. return baseProd * belongings[type].count;
  30. }
  31. // update stuff
  32. function updateResources() {
  33. addResources();
  34. displayResources();
  35. setTimeout(updateResources, 1000/updateRate);
  36. }
  37. function addResources() {
  38. resources.food += calculateProductivity() * 1 / updateRate;
  39. }
  40. function displayResources() {
  41. document.getElementById("resource-food").innerText = "Food: " + render(resources.food);
  42. }
  43. window.onload = function() {
  44. setup();
  45. setTimeout(updateResources, 1000/updateRate);
  46. }