From 4ef0441c7d3c1d55cd706d1a48d4d22a41d070fc Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Fri, 18 Aug 2017 16:02:53 +0200 Subject: [PATCH] Rearrange everything --- src/bubbles.js | 39 ++++++++++++++++++++- src/index.html | 1 - src/main.js | 51 ++++++---------------------- src/muri.js | 92 +++++++++++++++++++++----------------------------- 4 files changed, 86 insertions(+), 97 deletions(-) diff --git a/src/bubbles.js b/src/bubbles.js index e3f268b..c1d723e 100644 --- a/src/bubbles.js +++ b/src/bubbles.js @@ -1 +1,38 @@ -var muri +// init: function() { +// muri.bubble.playerSprite = kontra.sprite({x: 0, y: 0, image: kontra.assets.images.player }) +// }, +// +// bubble: { +// isActive: false, +// playerSprite: false, +// +// show: function(text, position=[2, 7], delay=3, callback=false) { +// muri.bubble.isActive = true; +// var bubble = document.getElementById('bubble'); +// bubble.style.display = ''; +// bubble.style.left = position[0]*8; +// bubble.style.top = position[1]*8; +// bubble.innerHTML = text; +// setTimeout(function() { +// muri.bubble.isActive = false; +// bubble.style.display = 'none'; +// if (callback !== false) callback.call(); +// }, delay*1000); +// }, +// +// talk: function(texts, position) { +// if (texts.length === 0) return; +// var text = texts.shift(); +// var delay = Math.ceil(text.length/13); +// muri.bubble.show(text, position, delay, function() { +// muri.bubble.talk(texts, position); +// }); +// }, +// +// render: function() { +// if (muri.bubble.isActive) { +// muri.bubble.playerSprite.render(); +// } +// } +// } +//}; diff --git a/src/index.html b/src/index.html index be52c56..cc0b2e3 100644 --- a/src/index.html +++ b/src/index.html @@ -13,4 +13,3 @@ - diff --git a/src/main.js b/src/main.js index 7a8fef0..22b2cf9 100644 --- a/src/main.js +++ b/src/main.js @@ -44,44 +44,13 @@ // TODO: "speech bubbles" for text // TODO: Item store -(function() { - kontra.init('js13k-2017'); - kontra.assets.imagePath = 'assets/images'; - - kontra.assets.load( - 'room_stasis_dark.png', - 'room_stasis.png', - 'player.png' - ).then(function() { - document.getElementById('loading').style.display = 'none'; - - if (kontra.store.get('current-room') === null) - kontra.store.set('current-room', 'stasis_dark'); - - muri.bubble.talk([ - 'Uh ...', - 'Where I am? ...', - 'It is so dark in here, I can\'t even see my bare hands. I can\'t remember a thing and my brain hurts so bad. What happened here?' - ], [40, 20]); - - var rooms = { - stasis_dark: kontra.sprite({x: 0, y: 0, image: kontra.assets.images.room_stasis_dark}), - stasis: kontra.sprite({x: 0, y: 0, image: kontra.assets.images.room_stasis}) - }; - - var loop = kontra.gameLoop({ - update: function() { - var currentRoom = kontra.store.get('current-room'); - rooms[currentRoom].update(); - }, - render: function() { - var currentRoom = kontra.store.get('current-room'); - rooms[currentRoom].render(); - muri.bubble.render(); - } - }); - - muri.init(); - loop.start(); - }); -}()); +// (function() { +// +// muri.bubble.talk([ +// 'Uh ...', +// 'Where I am? ...', +// 'It is so dark in here, I can\'t even see my bare hands. I can\'t remember a thing and my brain hurts so bad. What happened here?' +// ], [40, 20]); +// +// }); +// }()); diff --git a/src/muri.js b/src/muri.js index 544f927..4e41f03 100644 --- a/src/muri.js +++ b/src/muri.js @@ -1,64 +1,48 @@ -this.muri = { - init: function(kontra) { - kontra.init('js13k-2017'); - kontra.assets.imagePath = 'assets/images'; +var muri = (function() { + kontra.init('js13k-2017'); + kontra.assets.imagePath = 'assets/images'; + + var muri = {}; + + var bg = function(room) { + return kontra.sprite({ + x: 0, y: 0, + image: kontra.assets.images['room_'+room] + }); + }; + muri.modules = []; + + muri.start = function() { kontra.assets.load( 'player.png', 'room_stasis_dark.png', 'room_stasis.png' ).then(function() { + document.getElementById('loading').style.display = 'none'; + if (kontra.store.get('current-room') === null) + kontra.store.set('current-room', 'stasis_dark'); + var rooms = { + stasis_dark: bg('stasis_dark'), + stasis: bg('stasis') + }; + + kontra.gameLoop({ + update: function() { + var currentRoom = kontra.store.get('current-room'); + rooms[currentRoom].update(); + for (m in muri.modules) m.update(); + }, + render: function() { + var currentRoom = kontra.store.get('current-room'); + rooms[currentRoom].render(); + for (m in muri.modules) m.render(); + } + }).start(); }); - } -}; - - - -(function(m) { - var bubble = {}; - - bubble.show = function() { }; - m.bubble = bubble; - return bubble; -}(muri || {})); + return muri; +}()); - init: function() { - muri.bubble.playerSprite = kontra.sprite({x: 0, y: 0, image: kontra.assets.images.player }) - }, - - bubble: { - isActive: false, - playerSprite: false, - - show: function(text, position=[2, 7], delay=3, callback=false) { - muri.bubble.isActive = true; - var bubble = document.getElementById('bubble'); - bubble.style.display = ''; - bubble.style.left = position[0]*8; - bubble.style.top = position[1]*8; - bubble.innerHTML = text; - setTimeout(function() { - muri.bubble.isActive = false; - bubble.style.display = 'none'; - if (callback !== false) callback.call(); - }, delay*1000); - }, - - talk: function(texts, position) { - if (texts.length === 0) return; - var text = texts.shift(); - var delay = Math.ceil(text.length/13); - muri.bubble.show(text, position, delay, function() { - muri.bubble.talk(texts, position); - }); - }, - - render: function() { - if (muri.bubble.isActive) { - muri.bubble.playerSprite.render(); - } - } - } -}; +window.onload = muri.start;