diff --git a/index.html b/index.html index 24591c9..e280e0a 100644 --- a/index.html +++ b/index.html @@ -1,7 +1,7 @@ - Adventures with Anxiety! + Anxiety Adventure! @@ -18,16 +18,17 @@ - + + - - + - - + + + \ No newline at end of file diff --git a/scenes/attack.md b/scenes/attack.md new file mode 100644 index 0000000..2e6d2eb --- /dev/null +++ b/scenes/attack.md @@ -0,0 +1,59 @@ +# demo + +`SceneSetup.demo()` + +> Prepare for trouble! + +Oh no! + +(#demo-attacks) + +# demo-attacks + +`publish("beebee",["normal"])` + +[Attack 10 points](#demo-attack-low) + +[Attack 20 points](#demo-attack-med) + +[Attack 50%](#demo-attack-hi) + +# attack + +`publish("beebee",["scream"])` + +`publish("hong",["shock"])` + +(...1500) + +{{if HP.hong==0}} (#dead) {{/if}} + +`publish("hong",["normal"])` + +(#demo-attacks) + +# demo-attack-low + +`HP.attackHong("10p")` + +(#attack) + +# demo-attack-med + +`HP.attackHong("20p")` + +(#attack) + +# demo-attack-hi + +`HP.attackHong("50%")` + +(#attack) + +# dead + +`publish("beebee",["normal_speak"])` + +i am ded + +> u r ded diff --git a/scenes/demo.md b/scenes/demo.md index 2e6d2eb..1c8c2c7 100644 --- a/scenes/demo.md +++ b/scenes/demo.md @@ -1,59 +1,42 @@ # demo -`SceneSetup.demo()` +``` +SceneSetup.demo(); +publish("beebee",["normal_down"]); +``` -> Prepare for trouble! +> So... scrolling your life away on Twitter, huh? -Oh no! +``` +publish("beebee",["normal"]); +publish("hong",["sarcasm"]); +``` -(#demo-attacks) +Yeah, I wonder why I don't just sit alone with my thoughts more often. -# demo-attacks +`publish("beebee",["normal_down"]);` -`publish("beebee",["normal"])` +> ... -[Attack 10 points](#demo-attack-low) +`publish("beebee",["normal_down_vexed"]);` -[Attack 20 points](#demo-attack-med) +[Oh god, look at that awful news!](#derp) -[Attack 50%](#demo-attack-hi) +[Ugh, look at that troll comment.](#derp) -# attack +[hey, a GIF of a cat drinking milk](#milk) `publish("beebee",["normal_speak"])` -`publish("beebee",["scream"])` +# milk -`publish("hong",["shock"])` +`publish("hong",["smile"])` -(...1500) +Heh, yeah that is pretty cu- -{{if HP.hong==0}} (#dead) {{/if}} +``` +publish("beebee",["scream"]); +publish("hong",["shock"]); +HP.attackHong("60p"); +Game.OVERRIDE_TEXT_SPEED = 1.5; +``` -`publish("hong",["normal"])` - -(#demo-attacks) - -# demo-attack-low - -`HP.attackHong("10p")` - -(#attack) - -# demo-attack-med - -`HP.attackHong("20p")` - -(#attack) - -# demo-attack-hi - -`HP.attackHong("50%")` - -(#attack) - -# dead - -`publish("beebee",["normal_speak"])` - -i am ded - -> u r ded +> CATS CAN'T DIGEST COW'S MILK AND YOU'RE A HORRIBLE PERSON FOR ENJOYING ANIMAL ABUSE \ No newline at end of file diff --git a/scripts/game/Beebee.js b/scripts/demo/Demo_Beebee.js similarity index 83% rename from scripts/game/Beebee.js rename to scripts/demo/Demo_Beebee.js index cadf6cd..a9b9775 100644 --- a/scripts/game/Beebee.js +++ b/scripts/demo/Demo_Beebee.js @@ -1,10 +1,10 @@ -function Beebee(){ +function Demo_Beebee(){ var self = this; // Sprite! var beebeeImage = new Image(); - beebeeImage.src = "sprites/beebee.png"; + beebeeImage.src = "sprites/demo_beebee.png"; self.sprite = new Sprite({ image: beebeeImage, grid:{ @@ -20,10 +20,10 @@ function Beebee(){ y: 325/2 }, frameNames:[ - "normal_look_phone", "normal", + "normal_down", + "normal_down_vexed", "normal_speak", - "", "scream", "scream_2" ], @@ -31,6 +31,9 @@ function Beebee(){ y: 405 }); + // First frame + self.sprite.gotoFrameByName("normal"); + // Draw var ticker = 0; self.draw = function(ctx){ @@ -67,7 +70,9 @@ function Beebee(){ self.sprite.gotoFrameByName(fname); // Bounce transition - self.sprite.bounce = 1.1; + if(fname=="normal_speak"){ + self.sprite.bounce = 1.1; + } if(fname=="scream"){ self.sprite.bounce = 1.6; } diff --git a/scripts/game/Hong.js b/scripts/demo/Demo_Hong.js similarity index 76% rename from scripts/game/Hong.js rename to scripts/demo/Demo_Hong.js index 64f27e1..c84be81 100644 --- a/scripts/game/Hong.js +++ b/scripts/demo/Demo_Hong.js @@ -1,14 +1,14 @@ -function Hong(){ +function Demo_Hong(){ var self = this; // Sprite! var beebeeImage = new Image(); - beebeeImage.src = "sprites/hong.png"; + beebeeImage.src = "sprites/demo_hong.png"; self.sprite = new Sprite({ image: beebeeImage, grid:{ - width: 3, + width: 4, height: 2 }, frame:{ @@ -23,11 +23,13 @@ function Hong(){ "_body_1", "_body_2", "", + "", "normal", + "sarcasm", "smile", "shock" ], - x: 80, + x: 70, y: 400 }); @@ -40,7 +42,7 @@ function Hong(){ self.sprite.bounceDamp = 0.9; // First frame - self.sprite.gotoFrameByName("smile"); + self.sprite.gotoFrameByName("normal"); // Draw var ticker = 0; @@ -48,6 +50,15 @@ function Hong(){ var fname = self.sprite.currentFrameName; + // Breathe, unless shocked + if(fname=="shock"){ + self.sprite.breatheSpeed = 0; + self.sprite.breatheAmp = 0; + }else{ + self.sprite.breatheSpeed = 0.017; + self.sprite.breatheAmp = 0.014; + } + // Draw body FIRST var bod_frame = (Math.floor(ticker/30)%2 == 0) ? "_body_1" : "_body_2"; ticker++; diff --git a/scripts/demo/Demo_SceneSetup.js b/scripts/demo/Demo_SceneSetup.js new file mode 100644 index 0000000..fd5f8ab --- /dev/null +++ b/scripts/demo/Demo_SceneSetup.js @@ -0,0 +1,19 @@ +SceneSetup.demo = function(){ + + Game.resetScene(); + + HP.hong = 80; + + // Background + var bg = new BG_Anxiety(); + Game.scene.children.push(bg); + + // Hong + var hong = new Demo_Hong(); + Game.scene.children.push(hong); + + // Beebee + var beebee = new Demo_Beebee(); + Game.scene.children.push(beebee); + +}; \ No newline at end of file diff --git a/scripts/game/BGAnxiety.js b/scripts/game/BG_Anxiety.js similarity index 98% rename from scripts/game/BGAnxiety.js rename to scripts/game/BG_Anxiety.js index 6146306..515f590 100644 --- a/scripts/game/BGAnxiety.js +++ b/scripts/game/BG_Anxiety.js @@ -5,7 +5,7 @@ or maybe CA? ******************************/ -function BGAnxiety(){ +function BG_Anxiety(){ var self = this; diff --git a/scripts/game/Game.js b/scripts/game/Game.js index fa5eb34..3094c3f 100644 --- a/scripts/game/Game.js +++ b/scripts/game/Game.js @@ -8,18 +8,31 @@ Game.dom = document.querySelector("#game_container"); Game.wordsDOM = document.querySelector("#game_words"); Game.choicesDOM = document.querySelector("#game_choices"); +Game.startSectionID = null; Game.queue = []; -// Parse data! -Game.onload = function(data){ +window.SceneSetup = {}; // A big ol' singleton class that just makes it easy to create scenes. - // THE FIRST ID - Game.startSectionID = null; +// Init +Game.init = function(){ + + // Animation! + Game.wordsDOM.style.top = "80px"; + var animloop = function(){ + Game.update(); + requestAnimationFrame(animloop); + }; + requestAnimationFrame(animloop); + +}; + +// Parse scene markdown! +Game.parseSceneMarkdown = function(md){ // Split into sections... - data = data.trim(); - data = "\n" + data; - var sections = data.split(/\n\#\s*/); + md = md.trim(); + md = "\n" + md; + var sections = md.split(/\n\#\s*/); sections.shift(); sections.forEach(function(section){ @@ -43,18 +56,7 @@ Game.onload = function(data){ }); - // Animation! - Game.wordsDOM.style.top = "80px"; - var animloop = function(){ - Game.update(); - requestAnimationFrame(animloop); - }; - requestAnimationFrame(animloop); - - // Let's go! - Game.start(); - -} +}; //////////////////////////////////////////////////////////////////////////////////////////////// // SCENE MANAGEMENT //////////////////////////////////////////////////////////////////////////// @@ -98,8 +100,7 @@ Game.executeNextLine = function(){ var promiseNext; if(line==""){ // If no line, get immediate promise... - promiseNext = new pinkySwear(); - promiseNext(true, []); + promiseNext = Game.immediatePromise(); }else{ // Execute based on what type it is! @@ -148,6 +149,13 @@ Game.addToQueue = function(line){ // TEXT AND STUFF ////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////// +// Immediate Promise +Game.immediatePromise = function(){ + return new RSVP.Promise(function(resolve){ + resolve(); + }); +}; + // Move the text DOM to latest Game.updateText = function(){ var wordsHeight = 80 + Game.wordsDOM.getBoundingClientRect().height; @@ -159,81 +167,92 @@ Game.updateText = function(){ }; // Execute text! Just add it to text DOM. +Game.OVERRIDE_TEXT_SPEED = 1; Game.executeText = function(line){ - var div = document.createElement("div"); - var promiseDone = pinkySwear(); + return new RSVP.Promise(function(resolve){ - // Is it human or wolf? - var dialogue; - var isWolf = /^\>(.*)/.test(line); - if(isWolf){ - div.className = "wolf-bubble"; - dialogue = line.match(/^\>(.*)/)[1].trim(); - }else{ - div.className = "human-bubble"; - dialogue = line; - } + // Is it human or wolf? + var isWolf = /^\>(.*)/.test(line); + var dialogue = isWolf ? line.match(/^\>(.*)/)[1].trim() : line; // Remove the > for wolf - // Add the bubble, with animation - Game.wordsDOM.appendChild(div); - requestAnimationFrame(function(){ + // Add the bubble, with animation + var div = document.createElement("div"); + Game.wordsDOM.appendChild(div); + div.className = isWolf ? "wolf-bubble" : "human-bubble"; requestAnimationFrame(function(){ - div.style.opacity = 1; - div.style.left = 0; + requestAnimationFrame(function(){ + div.style.opacity = 1; + div.style.left = 0; + }); }); - }); - // Add the text, letter by letter! - var interval = 0; - var SPEED = 40; - for(var i=0; i "+choiceText); + + // Any pre-choice code? + if(preChoiceCodeIfAny) Game.executeCode(preChoiceCodeIfAny); + + // Override line... ONCE + if(!Game.OVERRIDE_CHOICE_LINE){ + Game.addToQueue("> "+choiceText); + } + Game.OVERRIDE_CHOICE_LINE = true; + + // Goto that choice, now! Game.goto(choiceID); + }; Game.choicesDOM.appendChild(div); - // Return promise - var promiseImmediate = new pinkySwear(); - promiseImmediate(true, []); - return promiseImmediate; + // Return immediate promise + return Game.immediatePromise(); } @@ -247,10 +266,8 @@ Game.executeCode = function(line){ console.log(e); } - // Return promise - var promiseImmediate = new pinkySwear(); - promiseImmediate(true, []); - return promiseImmediate; + // Return immediate promise + return Game.immediatePromise(); } @@ -261,11 +278,9 @@ Game.executeWait = function(line){ var waitTime = parseInt(line.match(/^\(\.\.\.(\d+)\)/)[1].trim()); // Delayed promise - var promiseDelayed = new pinkySwear(); - setTimeout(function(){ - promiseDelayed(true, []); - }, waitTime); - return promiseDelayed; + return RSVP.Promise(function(resolve){ + setTimeout(resolve, waitTime); + }); }; diff --git a/scripts/game/Loader.js b/scripts/game/Loader.js new file mode 100644 index 0000000..cd66d38 --- /dev/null +++ b/scripts/game/Loader.js @@ -0,0 +1,64 @@ +window.Loader = {}; +window.Library = { + images: {} +}; +Loader.load = function(){ + return new RSVP.Promise(function(resolve){ + + var loadPromises = []; + + // All scenes + Loader.sceneSources.forEach(function(src){ + loadPromises.push( Loader.loadScene(src) ); + }); + + // All images + Loader.imageConfigs.forEach(function(config){ + loadPromises.push( Loader.loadImage(config) ); + }); + + // Go go go! + RSVP.all(loadPromises).then(resolve); + + }); +}; + +///////////////////////////// +// IMAGES /////////////////// +///////////////////////////// + +Loader.imageConfigs = []; +Loader.addImages = function(imageConfigs){ + Loader.imageConfigs = Loader.imageConfigs.concat(imageConfigs); +}; +Loader.loadImage = function(imageConfig){ + return new RSVP.Promise(function(resolve){ + var img = new Image(); + var id = imageConfig.id; + Library.images[id] = img; // ADD TO LIBRARY + img.onload = resolve; + img.src = imageConfig.src; + }); +}; + +///////////////////////////// +// SCENES /////////////////// +///////////////////////////// + +Loader.sceneSources = []; +Loader.addScenes = function(sceneSources){ + Loader.sceneSources = Loader.sceneSources.concat(sceneSources); +}; +Loader.loadScene = function(src){ + var loadDataPromise = new RSVP.Promise(function(resolve){ + var xhr = new XMLHttpRequest(); + xhr.open("GET", src); + xhr.onload = function() { + if(xhr.status===200){ + Game.parseSceneMarkdown(xhr.responseText); // PARSE INTO GAME + resolve(); + } + }; + xhr.send(); + }); +}; diff --git a/scripts/game/SceneSetup.js b/scripts/game/SceneSetup.js deleted file mode 100644 index 15bbe9f..0000000 --- a/scripts/game/SceneSetup.js +++ /dev/null @@ -1,25 +0,0 @@ -/********************************** - -A big ol' singleton class that just makes it easy to create scenes. - -**********************************/ - -window.SceneSetup = {}; - -SceneSetup.demo = function(){ - - Game.resetScene(); - - // Background - var bg = new BGAnxiety(); - Game.scene.children.push(bg); - - // Hong - var hong = new Hong(); - Game.scene.children.push(hong); - - // Beebee - var beebee = new Beebee(); - Game.scene.children.push(beebee); - -}; \ No newline at end of file diff --git a/scripts/lib/rsvp.min.js b/scripts/lib/rsvp.min.js new file mode 100644 index 0000000..29c7f0a --- /dev/null +++ b/scripts/lib/rsvp.min.js @@ -0,0 +1 @@ +(function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.RSVP={})})(this,function(t){"use strict";function e(t){var e=t._promiseCallbacks;e||(e=t._promiseCallbacks={});return e}function r(t,e){if(2!==arguments.length)return dt[t];dt[t]=e}function n(){setTimeout(function(){for(var t=0;t2&&void 0!==arguments[2])||arguments[2],o=arguments[3];return G(this,t.call(this,e,r,n,o))}L(e,t);e.prototype._init=function(t,e){this._result={};this._enumerate(e);0===this._remaining&&v(this.promise,this._result)};e.prototype._enumerate=function(t){var e=this.promise,r=[];for(var n in t)St.call(t,n)&&r.push({position:n,entry:t[n]});var o=r.length;this._remaining=o;for(var i=void 0,s=0;e._state===mt&&s