From bb6d861712f2250a0d63af63c62209506427be2a Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Tue, 22 Aug 2017 00:58:41 +0200 Subject: [PATCH] Restructure the modules and finish implementing the bubbles --- src/act1.js | 13 +++++++++++ src/bubble.js | 43 +++++++++++++++++++++++++++++++++++ src/bubbles.js | 38 ------------------------------- src/index_dev.html | 2 ++ src/main.js | 56 ---------------------------------------------- src/muri.js | 52 ++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 108 insertions(+), 96 deletions(-) create mode 100644 src/act1.js create mode 100644 src/bubble.js delete mode 100644 src/bubbles.js delete mode 100644 src/main.js diff --git a/src/act1.js b/src/act1.js new file mode 100644 index 0000000..60051d0 --- /dev/null +++ b/src/act1.js @@ -0,0 +1,13 @@ +(function() { + var act1 = {}; + + muri.get('bubble').talk(['Hi', 'I Think, this works ...', 'This looks kinda cool. I think , I can work with that to build a nice little adventure game with some clicky things.', 'Just need to find out a way to click on things.']); + + act1.update = function() { + }; + + act1.render = function() { + }; + + muri.modules.push(act1); +}()); diff --git a/src/bubble.js b/src/bubble.js new file mode 100644 index 0000000..ad6e139 --- /dev/null +++ b/src/bubble.js @@ -0,0 +1,43 @@ +(function() { + var bubble = {}; + + var isactive = false; + var show = function(text, position, callback) { + isactive = true; + + var dom = document.getElementById('bubble'); + dom.style.display = ''; + dom.style.left = position[0]*8; + dom.style.top = position[1]*8; + dom.innerHTML = ''; + + parts = text.split(' '); + var show = function() { + if (parts.length === 0) { + setTimeout(function() { + isactive = false; + dom.style.display = 'none'; + callback.call(); + }, 4000); + return; + } + dom.innerHTML += parts.shift() + ' '; + setTimeout(show, 150); + }; + show(); + }; + + bubble.talk = function(texts, position, callback) { + if (texts.length === 0) { + if (callback !== undefined) callback.call(); + return; + } + var text = texts.shift(); + show(text, position || [5, 40], function() { + bubble.talk(texts, position); + }); + }; + + bubble.name = 'bubble'; + muri.modules.push(bubble); +}()); diff --git a/src/bubbles.js b/src/bubbles.js deleted file mode 100644 index c1d723e..0000000 --- a/src/bubbles.js +++ /dev/null @@ -1,38 +0,0 @@ -// 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_dev.html b/src/index_dev.html index cc0b2e3..358aa74 100644 --- a/src/index_dev.html +++ b/src/index_dev.html @@ -13,3 +13,5 @@ + + diff --git a/src/main.js b/src/main.js deleted file mode 100644 index 22b2cf9..0000000 --- a/src/main.js +++ /dev/null @@ -1,56 +0,0 @@ -"use strict"; - -// Plot: You are in the dark, and you have no clue where you are -// and what happened. You wake up in completely dark and stumble -// around. You explore the area and you find out you are on a -// old space ship. You need to find out whats going on here and -// why you are here. After finding and combining some items, you -// find out that your stasis capsule had some malfunctioning and -// you are the only one on this mission. But what mission? And -// where are your crew members? Where are you? You are drifting -// along, lost in space with no hope of rescue. But you want to -// surrender. -// You find out that you are the only surrender on an ancient -// space ship, carring cargo from one place to another when -// space pirates killed the crew except you. You want to fly -// home, but you need to bring the ship back to life. - -// Ship: -// Statis capsule room -// Cargo room -// Command station -// Crew quarters -// Machine/Engine room - -// Act 1: No light at all. Only player. Can walk. If the player -// hit a wall (he stands in a corridor), he can switch on the light. -// He sees the room and the stasis capsule. Explore the room, -// find out more details about your current situation (statis -// no one is here, ship don't move, warning signs everywhere). - -// Act 2: Open the pressure door, find a space suite, get a map -// fix a leak in the ship. - -// Act 3: Go into the command station, find out more on the -// terminals, fix some things by exploring the rest of the ship. - -// Act 4: Bring the ship back to operation, find the way home, -// end. - - - -// TODO: draw the different rooms -// TODO: Put it on the screen, "player" movement (mouse is the player) -// TODO: "speech bubbles" for text -// TODO: Item store - -// (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 4e41f03..42f0d0e 100644 --- a/src/muri.js +++ b/src/muri.js @@ -1,4 +1,43 @@ +// Plot: You are in the dark, and you have no clue where you are +// and what happened. You wake up in completely dark and stumble +// around. You explore the area and you find out you are on a +// old space ship. You need to find out whats going on here and +// why you are here. After finding and combining some items, you +// find out that your stasis capsule had some malfunctioning and +// you are the only one on this mission. But what mission? And +// where are your crew members? Where are you? You are drifting +// along, lost in space with no hope of rescue. But you want to +// surrender. +// You find out that you are the only surrender on an ancient +// space ship, carring cargo from one place to another when +// space pirates killed the crew except you. You want to fly +// home, but you need to bring the ship back to life. + +// Ship: +// Statis capsule room +// Cargo room +// Command station +// Crew quarters +// Machine/Engine room + +// Act 1: No light at all. Only player. Can walk. If the player +// hit a wall (he stands in a corridor), he can switch on the light. +// He sees the room and the stasis capsule. Explore the room, +// find out more details about your current situation (statis +// no one is here, ship don't move, warning signs everywhere). + +// Act 2: Open the pressure door, find a space suite, get a map +// fix a leak in the ship. + +// Act 3: Go into the command station, find out more on the +// terminals, fix some things by exploring the rest of the ship. + +// Act 4: Bring the ship back to operation, find the way home, +// end. + var muri = (function() { + 'use strict'; + kontra.init('js13k-2017'); kontra.assets.imagePath = 'assets/images'; @@ -11,6 +50,11 @@ var muri = (function() { }); }; muri.modules = []; + muri.get = function(moduleName) { + for (var i in muri.modules) + if (muri.modules[i].name === moduleName) + return muri.modules[i]; + }; muri.start = function() { kontra.assets.load( @@ -31,12 +75,16 @@ var muri = (function() { update: function() { var currentRoom = kontra.store.get('current-room'); rooms[currentRoom].update(); - for (m in muri.modules) m.update(); + muri.modules.forEach(function(m) { + if (m.update !== undefined) m.update(); + }); }, render: function() { var currentRoom = kontra.store.get('current-room'); rooms[currentRoom].render(); - for (m in muri.modules) m.render(); + muri.modules.forEach(function(m) { + if (m.render !== undefined) m.render(); + }); } }).start(); });