js13kgames2017-muri/src/room_stasis.js

70 lines
2.1 KiB
JavaScript
Raw Normal View History

(function() {
2017-09-12 00:33:44 +02:00
'use strict';
2017-08-31 12:56:40 +02:00
2017-08-25 17:03:26 +02:00
var stasis = {};
2017-08-25 17:03:26 +02:00
var background, backgroundDark = null;
2017-09-12 22:40:34 +02:00
var door = null;
2017-08-24 22:00:19 +02:00
var roomState = {
2017-08-25 17:03:26 +02:00
isDoorOpen: false,
2017-08-31 13:54:57 +02:00
isLightOn: false,
isIntroRunning: true
2017-08-24 22:00:19 +02:00
};
2017-08-23 23:31:50 +02:00
2017-08-25 17:03:26 +02:00
stasis.init = function() {
background = muri.bg('stasis');
backgroundDark = muri.bg('stasis_dark');
2017-08-28 21:29:27 +02:00
muri.get('entity')
.create('stasis.lightSwitch',
2017-09-12 22:40:34 +02:00
kontra.sprite({x: 9, y: 11, width: 3, height: 2,
2017-08-28 21:29:27 +02:00
image: kontra.assets.images.stasis_lightSwitch}))
.addCallback(function() {
2017-08-31 13:54:57 +02:00
if (roomState.isIntroRunning) return;
2017-08-28 21:29:27 +02:00
if (!roomState.isLightOn) {
roomState.isLightOn = true;
muri.get('bubble')
.talk([
'Ah, much better.',
'Looks like something happened to my stasis capsule.'
]);
} else {
muri.get('bubble')
.talk(['No, I will not turn off the light again!']);
}
});
2017-08-25 17:03:26 +02:00
if (!roomState.isLightOn) {
2017-08-23 23:31:50 +02:00
muri.get('bubble')
.story([
[['Beep', 'Bip, Bip'], [20, 15]],
2017-08-31 13:54:57 +02:00
[['Urgh ... ...', 'Where I am?', 'What happened?'], [40, 35]],
[['I can\'t see a thing ...', '... need to turn on the light ...'], [40, 35]]
])
.then(function() {
roomState.isIntroRunning = false;
});
2017-08-23 23:31:50 +02:00
}
};
2017-09-12 22:40:34 +02:00
stasis.onEnter = function(prevRoom) {
door.sprite.playAnimation('close');
};
2017-08-25 17:03:26 +02:00
stasis.update = function() {
2017-09-12 22:40:34 +02:00
if (roomState.isLightOn && !door)
door = muri.door('stasis', [76, 11]);
};
2017-08-25 17:03:26 +02:00
stasis.render = function() {
if (roomState.isLightOn) {
background.render();
} else {
backgroundDark.render();
}
};
2017-08-25 21:53:22 +02:00
stasis.name = 'stasis';
muri.rooms.push(stasis);
}());