Move things a little bit

This commit is contained in:
Aaron Fischer 2017-08-25 17:03:26 +02:00
parent ff2cfc3d60
commit 22d4f6bcee
3 changed files with 31 additions and 20 deletions

View file

@ -15,4 +15,4 @@
<script src="muri.js"></script>
<script src="bubble.js"></script>
<script src="mouse.js"></script>
<script src="act1.js"></script>
<script src="stasis.js"></script>

View file

@ -45,7 +45,7 @@ var muri = (function() {
var muri = {};
var bg = function(room) {
muri.bg = function(room) {
return kontra.sprite({
x: 0, y: 0,
image: kontra.assets.images['room_'+room]
@ -53,6 +53,7 @@ var muri = (function() {
};
muri.currentRoom = 'stasis';
muri.modules = [];
muri.rooms = {};
muri.get = function(moduleName) {
for (var i in muri.modules)
if (muri.modules[i].name === moduleName)
@ -66,20 +67,15 @@ var muri = (function() {
'stasis_door-sheet.png'
).then(function() {
document.getElementById('loading').style.display = 'none';
var rooms = {
stasis_dark: bg('stasis_dark'),
stasis: bg('stasis')
};
kontra.gameLoop({
update: function() {
rooms[muri.currentRoom].update();
muri.rooms[muri.currentRoom].update();
muri.modules.forEach(function(m) {
if (m.update !== undefined) m.update();
});
},
render: function() {
rooms[muri.currentRoom].render();
muri.rooms[muri.currentRoom].render();
muri.modules.forEach(function(m) {
if (m.render !== undefined) m.render();
});
@ -89,6 +85,10 @@ var muri = (function() {
muri.modules.forEach(function(m) {
if (m.init !== undefined) m.init();
});
muri.rooms.forEach(function(r) {
....
if (r.init !== undefined) r.init();
});
});
};

View file

@ -1,14 +1,16 @@
(function() {
var act1 = {};
var stasis = {};
var controlPanelSprite = kontra.sprite({x: 16, y: 13, width: 3, height: 2});
var background, backgroundDark = null;
var doorAnimationSheet = null;
var doorSprite = null;
var roomState = {
isDoorOpen: false
isDoorOpen: false,
isLightOn: false
};
act1.init = function() {
stasis.init = function() {
doorAnimationSheet = kontra.spriteSheet({
image: kontra.assets.images['stasis_door-sheet'],
frameWidth: 24,
@ -35,7 +37,10 @@
animations: doorAnimationSheet.animations
});
if (muri.currentRoom === 'stasis_dark') {
background = muri.bg('stasis');
backgroundDark = muri.bg('stasis_dark');
if (!roomState.isLightOn) {
muri.get('bubble')
.story([
[['Beep', 'Bip, Bip'], [20, 15]],
@ -45,9 +50,9 @@
}
};
act1.update = function() {
stasis.update = function() {
doorSprite.update();
if (muri.currentRoom === 'stasis') {
if (roomState.isLightOn) {
if (muri.get('mouse').clickedOn(doorSprite)) {
muri.get('mouse').releaseClick();
if (!roomState.isDoorOpen) {
@ -63,8 +68,8 @@
if (muri.get('mouse').clickedOn(controlPanelSprite)) {
muri.get('mouse').releaseClick();
if (muri.currentRoom === 'stasis_dark') {
muri.currentRoom = 'stasis';
if (!roomState.isLightOn) {
roomState.isLightOn = true;
muri.get('bubble')
.talk([
'Ah, much better.',
@ -77,11 +82,17 @@
}
};
act1.render = function() {
if (muri.currentRoom === 'stasis') {
stasis.render = function() {
if (roomState.isLightOn) {
background.render();
} else {
backgroundDark.render();
}
if (roomState.isLightOn) {
doorSprite.render();
}
};
muri.modules.push(act1);
muri.rooms['stasis'] = stasis;
}());