Просмотр исходного кода

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

tags/v0.1.0
Fen Dweller 6 лет назад
Родитель
Сommit
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.player.stats.health = 100;


state.timers = []; state.timers = [];

state.timers.global = new Set();
} }


// TODO: format string this lol // 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) { function startTimer(config, state) {
if (config.loop) { if (config.loop) {
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
config.func();
const result = config.func(state);
state.timers = state.timers.filter(x => x.timeout != timeout); state.timers = state.timers.filter(x => x.timeout != timeout);
startTimer(config, state);
refresh();
if (result)
startTimer(config, state);
}, config.delay); }, config.delay);


state.timers.push({id: config.id, timeout: timeout, room: config.room}); 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); initAudio(story, state);
initGame(story, state); initGame(story, state);


story.intro.setup(state);

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




+ 17
- 1
stories/fen-snack.js Просмотреть файл

@@ -8,7 +8,23 @@ stories.push({
"loop/fen-bowels.ogg" "loop/fen-bowels.ogg"
], ],
intro: { 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: { world: {
stomach: { stomach: {


Загрузка…
Отмена
Сохранить