js13kgames2017-muri/src/room_lift.js

95 lines
3 KiB
JavaScript
Raw Normal View History

2017-09-12 00:33:44 +02:00
(function() {
'use strict';
var lift = {};
var buttonSheet, background = null;
var buttons = [];
var roomState = {
2017-09-12 23:52:00 +02:00
bridgeAccessible: false,
hydroDoorBroken: true
2017-09-12 00:33:44 +02:00
};
2017-09-12 22:40:34 +02:00
2017-09-12 00:33:44 +02:00
var createButtonEntity = function(i, room) {
var e = muri.get('entity')
.create('lift.button'+i,
kontra.sprite({x: 59, y: i*2+8+i*2,
animations: buttonSheet.animations}))
.addCallback(function() {
buttons.forEach(function(b) { b.sprite.playAnimation('off'); });
2017-09-12 23:52:00 +02:00
if (room === 'bridge' && !roomState.bridgeAccessible) {
muri.get('bubble')
.talk([
'The bridge is not accessible.',
'You have no sufficient permission to do that.']);
return;
}
if (room === 'hydro' && roomState.hydroDoorBroken) {
muri.get('bubble')
.talk([
'The hyperlift moved, but to door to the hydro deck does not open.',
'You can\'t access this deck with a broken door.'
]);
return;
}
2017-09-12 00:33:44 +02:00
muri.get('entity').get('lift.button'+i).sprite.playAnimation('on');
2017-09-12 23:52:00 +02:00
var goMessage = muri.ra([
2017-09-12 22:40:34 +02:00
'Sure, ' + room,
'Okay, straight to ' + room,
'Set ' + room + ' for destination',
room + ', okay'
]);
muri.get('bubble')
.talk([goMessage])
.then(function() {
muri.changeRoom(room);
});
2017-09-12 00:33:44 +02:00
});
e.sprite.playAnimation('off');
return e;
};
lift.init = function() {
buttonSheet = kontra.spriteSheet({
image: kontra.assets.images.lift_button,
frameWidth: 2, frameHeight: 2,
animations: {
on: {frames: 1},
off: {frames: 0}
}
});
2017-09-12 22:40:34 +02:00
background = muri.bg('lift');
2017-09-12 00:33:44 +02:00
buttons = [
2017-09-12 22:40:34 +02:00
createButtonEntity(0, 'bridge'), // Bridge
createButtonEntity(1, 'hydro'), // Hydro Deck
createButtonEntity(2, 'stasis'), // Stasis
createButtonEntity(3, 'engine') // Engine room
2017-09-12 00:33:44 +02:00
];
2017-09-12 23:52:00 +02:00
buttons[2].sprite.playAnimation('on');
2017-09-12 00:33:44 +02:00
};
2017-09-12 22:40:34 +02:00
lift.onEnter = function(fromRoom) {
2017-09-12 23:52:00 +02:00
var welcomeMessage = muri.ra([
2017-09-12 22:40:34 +02:00
'Welcome on board, where do you want?',
'Please specify your destination.',
'Insert desired deck on console.',
'What level please?'
]);
muri.get('bubble').talk([welcomeMessage]);
};
2017-09-12 00:33:44 +02:00
lift.update = function() {};
lift.render = function() {
background.render();
};
lift.name = 'lift';
muri.rooms.push(lift);
}());