js13kgames2017-muri/src/room_stasis.js

95 lines
3 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-08-24 22:00:19 +02:00
var doorAnimationSheet = null;
var doorSprite = null;
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() {
2017-08-24 22:00:19 +02:00
doorAnimationSheet = kontra.spriteSheet({
2017-08-28 21:29:27 +02:00
image: kontra.assets.images.stasis_doorSheet,
frameWidth: 24, frameHeight: 21,
2017-08-24 17:06:46 +02:00
animations: {
2017-08-28 21:29:27 +02:00
closed: {frames: 0},
opened: {frames: 2},
open: {frames: '0..3', frameRate: 6},
close: {frames: '3..0', frameRate: 6}
2017-08-24 17:06:46 +02:00
}
});
2017-08-24 22:00:19 +02:00
doorSprite = kontra.sprite({
2017-08-24 17:06:46 +02:00
x: 72, y: 8,
2017-08-24 22:00:19 +02:00
animations: doorAnimationSheet.animations
2017-08-24 17:06:46 +02:00
});
2017-08-25 17:03:26 +02:00
background = muri.bg('stasis');
backgroundDark = muri.bg('stasis_dark');
2017-08-28 21:29:27 +02:00
muri.get('entity')
.create('stasis.lightSwitch',
2017-08-28 23:51:21 +02:00
kontra.sprite({x: 15, y: 12, 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-08-25 17:03:26 +02:00
stasis.update = function() {
2017-08-28 21:29:27 +02:00
if (roomState.isLightOn &&
!muri.get('entity').get('stasis.door')) {
muri.get('entity')
.create('stasis.door', doorSprite)
.addCallback(function() {
if (!roomState.isDoorOpen) {
doorSprite.playAnimation('open');
roomState.isDoorOpen = true;
2017-09-12 00:33:44 +02:00
setTimeout(function() { muri.currentRoom = 'lift'; }, 800);
2017-08-28 21:29:27 +02:00
} else {
doorSprite.playAnimation('close');
roomState.isDoorOpen = false;
}
});
2017-08-23 23:31:50 +02:00
}
};
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);
}());