From 22d4f6bcee2f74480e2626879de3717d29d438ab Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Fri, 25 Aug 2017 17:03:26 +0200 Subject: [PATCH] Move things a little bit --- src/index_dev.html | 2 +- src/muri.js | 16 ++++++++-------- src/{act1.js => stasis.js} | 33 ++++++++++++++++++++++----------- 3 files changed, 31 insertions(+), 20 deletions(-) rename src/{act1.js => stasis.js} (77%) diff --git a/src/index_dev.html b/src/index_dev.html index 5689dab..a7e18bb 100644 --- a/src/index_dev.html +++ b/src/index_dev.html @@ -15,4 +15,4 @@ - + diff --git a/src/muri.js b/src/muri.js index 4f60f8d..1cb0605 100644 --- a/src/muri.js +++ b/src/muri.js @@ -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(); + }); }); }; diff --git a/src/act1.js b/src/stasis.js similarity index 77% rename from src/act1.js rename to src/stasis.js index d1118a9..4e3fe92 100644 --- a/src/act1.js +++ b/src/stasis.js @@ -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; }());