js13kgames2017-muri/src/stasis.js

100 lines
2.9 KiB
JavaScript
Raw Normal View History

(function() {
2017-08-25 17:03:26 +02:00
var stasis = {};
2017-08-23 23:31:50 +02:00
var controlPanelSprite = kontra.sprite({x: 16, y: 13, width: 3, height: 2});
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,
isLightOn: false
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-24 17:06:46 +02:00
image: kontra.assets.images['stasis_door-sheet'],
2017-08-24 22:00:19 +02:00
frameWidth: 24,
frameHeight: 21,
2017-08-24 17:06:46 +02:00
animations: {
closed: {
frames: 0
},
opened: {
frames: 2
},
open: {
2017-08-24 22:00:19 +02:00
frames: '0..3',
frameRate: 6,
2017-08-24 17:06:46 +02:00
},
close: {
2017-08-24 22:00:19 +02:00
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');
if (!roomState.isLightOn) {
2017-08-23 23:31:50 +02:00
muri.get('bubble')
.story([
[['Beep', 'Bip, Bip'], [20, 15]],
[['Urgh ... ...', 'Where I am?', 'What happened?'], [35, 40]],
[['I can\'t see a thing ...', '... need to turn on the light ...'], [35, 40]]
]);
}
};
2017-08-25 17:03:26 +02:00
stasis.update = function() {
2017-08-24 22:00:19 +02:00
doorSprite.update();
2017-08-25 17:03:26 +02:00
if (roomState.isLightOn) {
2017-08-24 22:00:19 +02:00
if (muri.get('mouse').clickedOn(doorSprite)) {
2017-08-24 17:06:46 +02:00
muri.get('mouse').releaseClick();
2017-08-24 22:00:19 +02:00
if (!roomState.isDoorOpen) {
doorSprite.playAnimation('open');
roomState.isDoorOpen = true;
} else {
doorSprite.playAnimation('close');
roomState.isDoorOpen = false;
}
2017-08-24 17:06:46 +02:00
}
}
2017-08-23 23:31:50 +02:00
if (muri.get('mouse').clickedOn(controlPanelSprite)) {
muri.get('mouse').releaseClick();
2017-08-25 17:03:26 +02:00
if (!roomState.isLightOn) {
roomState.isLightOn = true;
2017-08-23 23:31:50 +02:00
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
stasis.render = function() {
if (roomState.isLightOn) {
background.render();
} else {
backgroundDark.render();
}
if (roomState.isLightOn) {
2017-08-24 22:00:19 +02:00
doorSprite.render();
2017-08-24 17:06:46 +02:00
}
};
2017-08-25 21:53:22 +02:00
stasis.name = 'stasis';
muri.rooms.push(stasis);
}());