diff --git a/game.js b/game.js index 6512822..1d61806 100644 --- a/game.js +++ b/game.js @@ -8,8 +8,6 @@ function initGame(story, state) { state.player.stats.health = 100; state.timers = []; - - state.timers.global = new Set(); } // TODO: format string this lol @@ -55,9 +53,12 @@ Returns the timeout id - but you still need to cancel it through stopTimer! function startTimer(config, state) { if (config.loop) { const timeout = setTimeout(() => { - config.func(); + const result = config.func(state); state.timers = state.timers.filter(x => x.timeout != timeout); - startTimer(config, state); + refresh(); + + if (result) + startTimer(config, state); }, config.delay); state.timers.push({id: config.id, timeout: timeout, room: config.room}); diff --git a/satiate.js b/satiate.js index afbcfba..23e772a 100644 --- a/satiate.js +++ b/satiate.js @@ -75,6 +75,8 @@ function init(story) { initAudio(story, state); initGame(story, state); + story.intro.setup(state); + goToRoom(story.intro.start, state); } diff --git a/stories/fen-snack.js b/stories/fen-snack.js index fbbcdf6..efe98e7 100644 --- a/stories/fen-snack.js +++ b/stories/fen-snack.js @@ -8,7 +8,23 @@ stories.push({ "loop/fen-bowels.ogg" ], intro: { - start: "stomach" + start: "stomach", + setup: state => { + startTimer({ + id: "digestion", + func: state => { + state.player.stats.health -= 1; + + if (state.player.stats.health <= 0) { + goToRoom("digested", state); + return false; + } + return true; + }, + delay: 1000, + loop: true + }, state); + } }, world: { stomach: {