ソースを参照

Cleaned up timers; stories have a setup function. Added digestion to the fen-snack story

tags/v0.1.0
Fen Dweller 6年前
コミット
454b4b7627
3個のファイルの変更24行の追加5行の削除
  1. +5
    -4
      game.js
  2. +2
    -0
      satiate.js
  3. +17
    -1
      stories/fen-snack.js

+ 5
- 4
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});


+ 2
- 0
satiate.js ファイルの表示

@@ -75,6 +75,8 @@ function init(story) {
initAudio(story, state);
initGame(story, state);

story.intro.setup(state);

goToRoom(story.intro.start, state);
}



+ 17
- 1
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: {


読み込み中…
キャンセル
保存