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.
 
 
 
 

36 lines
886 B

  1. function initGame(game, state) {
  2. state.info = {};
  3. state.info.time = 60 * 60 * 9;
  4. state.player.stats = {};
  5. state.player.stats.health = 100;
  6. }
  7. // TODO: format string this lol
  8. function renderTime(time) {
  9. let hours = Math.floor(time / 3600) % 12;
  10. const ampm = Math.floor(time / 3600) % 24 < 12 ? "AM" : "PM";
  11. let minutes = Math.floor(time / 60) % 60;
  12. let seconds = time % 60;
  13. if (minutes <= 9)
  14. minutes = "0" + minutes;
  15. if (seconds <= 9)
  16. seconds = "0" + seconds;
  17. return hours + ":" + minutes + ":" + seconds + " " + ampm;
  18. }
  19. function updateWorldInfo(state) {
  20. const timeInfo = document.querySelector("#world-info-time");
  21. timeInfo.textContent = "Time: " + renderTime(state.info.time);
  22. }
  23. function updatePlayerInfo(state) {
  24. const health = document.querySelector("#player-info-health");
  25. health.textContent = "Health: " + state.player.stats.health;
  26. }