a munch adventure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

58 lines
1.3 KiB

  1. stories = [];
  2. function initGame(story, state) {
  3. state.info = {};
  4. state.info.time = 60 * 60 * 9;
  5. state.player.stats = {};
  6. state.player.stats.health = 100;
  7. }
  8. // TODO: format string this lol
  9. function renderTime(time) {
  10. let hours = Math.floor(time / 3600) % 12;
  11. const ampm = Math.floor(time / 3600) % 24 < 12 ? "AM" : "PM";
  12. let minutes = Math.floor(time / 60) % 60;
  13. let seconds = time % 60;
  14. if (minutes <= 9)
  15. minutes = "0" + minutes;
  16. if (seconds <= 9)
  17. seconds = "0" + seconds;
  18. return hours + ":" + minutes + ":" + seconds + " " + ampm;
  19. }
  20. function updateWorldInfo(state) {
  21. const timeInfo = document.querySelector("#world-info-time");
  22. timeInfo.textContent = "Time: " + renderTime(state.info.time);
  23. }
  24. function updatePlayerInfo(state) {
  25. const health = document.querySelector("#player-info-health");
  26. health.textContent = "Health: " + state.player.stats.health;
  27. }
  28. /*
  29. {
  30. func: the function to invoke
  31. delay: how long to wait between invocations
  32. loop: false = no looping, true = loop forever
  33. }
  34. */
  35. function startTimer(config, state) {
  36. if (config.loop) {
  37. const timeout = setTimeout(() => {
  38. config.func();
  39. state.timers.global.delete(timeout);
  40. startTimer(config, state);
  41. }, config.delay);
  42. state.timers.global.add(timeout);
  43. }
  44. }