| @@ -5,11 +5,20 @@ function initGame(story, state) { | |||||
| state.info.time = 60 * 60 * 9; | state.info.time = 60 * 60 * 9; | ||||
| state.player.stats = {}; | state.player.stats = {}; | ||||
| state.player.stats.health = 100; | |||||
| state.timers = []; | state.timers = []; | ||||
| } | } | ||||
| function initGamePostSetup(state) { | |||||
| const holder = document.querySelector("#player-info"); | |||||
| Object.entries(state.player.stats).forEach(([key, val]) => { | |||||
| const field = document.createElement("div"); | |||||
| field.id = "player-info-" + key; | |||||
| holder.appendChild(field); | |||||
| }); | |||||
| } | |||||
| // TODO: format string this lol | // TODO: format string this lol | ||||
| function renderTime(time) { | function renderTime(time) { | ||||
| let hours = Math.floor(time / 3600) % 12; | let hours = Math.floor(time / 3600) % 12; | ||||
| @@ -33,9 +42,10 @@ function updateWorldInfo(state) { | |||||
| } | } | ||||
| function updatePlayerInfo(state) { | function updatePlayerInfo(state) { | ||||
| const health = document.querySelector("#player-info-health"); | |||||
| health.textContent = "Health: " + state.player.stats.health; | |||||
| Object.entries(state.player.stats).forEach(([key, val]) => { | |||||
| const field = document.querySelector("#player-info-" + key); | |||||
| field.textContent = val.name + ": " + val.value; | |||||
| }); | |||||
| } | } | ||||
| /* | /* | ||||
| @@ -48,7 +48,6 @@ | |||||
| </div> | </div> | ||||
| <div id="player-info"> | <div id="player-info"> | ||||
| <div class="info-header" id="player-info-header">Player</div> | <div class="info-header" id="player-info-header">Player</div> | ||||
| <div id="player-info-health"></div> | |||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| <div id="log"> | <div id="log"> | ||||
| @@ -83,6 +83,8 @@ function init(story) { | |||||
| story.intro.setup(state); | story.intro.setup(state); | ||||
| initGamePostSetup(state); | |||||
| refreshHook = story.refresh; | refreshHook = story.refresh; | ||||
| goToRoom(story.intro.start, state); | goToRoom(story.intro.start, state); | ||||
| @@ -10,12 +10,15 @@ stories.push({ | |||||
| intro: { | intro: { | ||||
| start: "stomach", | start: "stomach", | ||||
| setup: state => { | setup: state => { | ||||
| state.player.stats.health = {name: "Health", value: 100}; | |||||
| state.player.stats.stamina = {name: "Stamina", value: 100}; | |||||
| startTimer({ | startTimer({ | ||||
| id: "digestion", | id: "digestion", | ||||
| func: state => { | func: state => { | ||||
| state.player.stats.health -= 1; | |||||
| state.player.stats.health.value -= 1; | |||||
| if (state.player.stats.health <= 0) { | |||||
| if (state.player.stats.health.value <= 0) { | |||||
| goToRoom("digested", state); | goToRoom("digested", state); | ||||
| return false; | return false; | ||||
| } | } | ||||
| @@ -30,7 +33,7 @@ stories.push({ | |||||
| } | } | ||||
| }, | }, | ||||
| refresh: state => { | refresh: state => { | ||||
| setBackgroundColor(50 - state.player.stats.health/2, 0, 0) | |||||
| setBackgroundColor(50 - state.player.stats.health.value/2, 0, 0) | |||||
| }, | }, | ||||
| world: { | world: { | ||||
| stomach: { | stomach: { | ||||
| @@ -61,7 +64,7 @@ stories.push({ | |||||
| name: "Submit", | name: "Submit", | ||||
| desc: "Let Fen digest you", | desc: "Let Fen digest you", | ||||
| execute: (room, state) => { | execute: (room, state) => { | ||||
| state.player.stats.health = 0; | |||||
| state.player.stats.health.value = 0; | |||||
| goToRoom("digested", state); | goToRoom("digested", state); | ||||
| } | } | ||||
| } | } | ||||