From 4d1208af7d32158e660df6a8e891b132b9e41b6a Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sat, 12 Jan 2019 11:00:02 -0500 Subject: [PATCH] Added background color control. --- game.js | 7 +++++-- satiate.js | 8 ++++++++ stories/fen-snack.js | 3 +++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/game.js b/game.js index d49925b..9311b78 100644 --- a/game.js +++ b/game.js @@ -93,11 +93,14 @@ function stopClassTimers(timerClass, state, inverse) { matches.forEach(timer => clearTimeout(timer.timeout)); state.timers = others; } - - } function stopAllTimers(state) { state.timers.forEach(x => clearTimeout(x.timeout)); state.timers = []; } + +function setBackgroundColor(r, g, b) { + document.querySelector(".scene").style["background-color"] = "rgb(" + r + "," + g + "," + b + ")"; + +} diff --git a/satiate.js b/satiate.js index 23e772a..3fe4bea 100644 --- a/satiate.js +++ b/satiate.js @@ -7,6 +7,8 @@ const version = "pre-alpha"; let state; +let refreshHook; + function print(lines) { (lines.concat([newline])).forEach(line => { const log = document.querySelector("#log"); @@ -24,6 +26,10 @@ function refresh() { updateRoom(state); updateWorldInfo(state); updatePlayerInfo(state); + + if (refreshHook) { + refreshHook(state) + } } function switchModal(to) { @@ -77,6 +83,8 @@ function init(story) { story.intro.setup(state); + refreshHook = story.refresh; + goToRoom(story.intro.start, state); } diff --git a/stories/fen-snack.js b/stories/fen-snack.js index 64b9cfe..2b2f52a 100644 --- a/stories/fen-snack.js +++ b/stories/fen-snack.js @@ -29,6 +29,9 @@ stories.push({ }, state); } }, + refresh: state => { + setBackgroundColor(50 - state.player.stats.health/2, 0, 0) + }, world: { stomach: { id: "stomach",