diff --git a/game.js b/game.js index 1f12b96..4aca084 100644 --- a/game.js +++ b/game.js @@ -87,11 +87,17 @@ function startTimer(config, state) { if (config.loop) { const timeout = setTimeout(() => { const result = config.func(state); - state.timers = state.timers.filter(x => x.timeout != timeout); refresh(); - if (result) - startTimer(config, state); + // the timer may have terminated itself! + // we have to make sure it still exists + + if (state.timers.some(x => x.timeout == timeout)){ + state.timers = state.timers.filter(x => x.timeout != timeout); + if (result) + startTimer(config, state); + } + }, config.delay); state.timers.push({id: config.id, timeout: timeout, room: config.room, classes: config.classes || []}); @@ -112,7 +118,6 @@ function stopRoomTimers(room, state) { matches.forEach(timer => clearTimeout(timer.timeout)); state.timers = state.timers.filter(timer => timer.room != room); - } function stopClassTimers(timerClass, state, inverse) { diff --git a/satiate.css b/satiate.css index 4ec76c6..f534aee 100644 --- a/satiate.css +++ b/satiate.css @@ -312,8 +312,6 @@ a:hover { } } - - #moves { padding: 25px; position: relative; diff --git a/stories/fen-snack.js b/stories/fen-snack.js index 47dadb8..62c6162 100644 --- a/stories/fen-snack.js +++ b/stories/fen-snack.js @@ -98,9 +98,28 @@ stories.push({ }, enter: (room, state) => { playLoop("loop/fen-stomach.ogg"); + + startTimer({ + id: "stomach-churns", + func: state => { + if (Math.random() > 0.8) { + state.player.stats.stamina.value -= 25; + state.player.stats.stamina.value = Math.max(0, state.player.stats.stamina.value); + print(["The crux's stomach clenches around you, smothering you in the beast's slimy embrace."]); + } + return true; + }, + delay: 10000, + loop: true, + room: "stomach", + classes: [ + "alive" + ] + }, state); }, exit: (room, state) => { stopLoop("loop/fen-stomach.ogg"); + stopRoomTimers("stomach", state); }, hooks: [ @@ -171,9 +190,33 @@ stories.push({ }, enter: (room, state) => { playLoop("loop/fen-intestines.ogg"); + + startTimer({ + id: "intestines-churns", + func: state => { + if (Math.random() > 0.8) { + if (state.player.stats.stamina.value > 50) { + state.player.stats.stamina.value -= 25; + state.player.stats.stamina.value = Math.max(0, state.player.stats.stamina.value); + print(["Your prison's walls ripple and grind, shoving you against the valve leading to the crux's boiling stomach - but you manage to resist the powerful pull."]); + } else { + print(["Too exhausted to resist, your slimy body is crammed into the crux's churning stomach by a powerful wave of peristalsis."]); + goToRoom("stomach", state); + } + } + return true; + }, + delay: 10000, + loop: true, + room: "intestines", + classes: [ + "alive" + ] + }, state); }, exit: (room, state) => { stopLoop("loop/fen-intestines.ogg"); + stopRoomTimers("intestines", state); }, exits: { "up": { @@ -233,9 +276,33 @@ stories.push({ }, enter: (room, state) => { playLoop("loop/fen-bowels.ogg"); + + startTimer({ + id: "bowels-churns", + func: state => { + if (Math.random() > 0.8) { + if (state.player.stats.stamina.value > 50) { + state.player.stats.stamina.value -= 25; + state.player.stats.stamina.value = Math.max(0, state.player.stats.stamina.value); + print(["Fen's bowels clench and churn, grinding you into their musky walls."]); + } else { + state.player.stats.health.value /= 4; + print(["Drained of stamina, you can do little to resist as Fen's bowels grind you away."]); + } + } + return true; + }, + delay: 10000, + loop: true, + room: "bowels", + classes: [ + "alive" + ] + }, state); }, exit: (room, state) => { stopLoop("loop/fen-bowels.ogg"); + stopRoomTimers("bowels", state); }, exits: { "up": { diff --git a/world.js b/world.js index a21c180..396e1ec 100644 --- a/world.js +++ b/world.js @@ -85,7 +85,7 @@ function goToRoom(dest, state) { } if (from && from.exit) - from.exit(state.world[dest], state); + from.exit(from, state); if (room.enter) room.enter(state.world[dest], state);