SS ready DONE

This commit is contained in:
Nicky Case 2019-02-18 15:59:10 -05:00
parent b1aa4a4406
commit 45b2fe1814
16 changed files with 307 additions and 170 deletions

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Adventures with Anxiety!</title>
<title>Anxiety Adventure!</title>
<link rel="stylesheet" type="text/css" href="styles/game.css">
<meta name="viewport" content="width=device-width">
</head>
@ -18,16 +18,17 @@
</html>
<!-- SCRIPTS -->
<script src="scripts/lib/pinkyswear.min.js"></script>
<script src="scripts/lib/rsvp.min.js"></script>
<script src="scripts/lib/minpubsub.min.js"></script>
<script src="scripts/game/Game.js"></script>
<script src="scripts/game/Loader.js"></script>
<script src="scripts/game/Sprite.js"></script>
<script src="scripts/game/HP.js"></script>
<script src="scripts/game/SceneSetup.js"></script>
<script src="scripts/game/BGAnxiety.js"></script>
<script src="scripts/game/BG_Anxiety.js"></script>
<script src="scripts/game/Hong.js"></script>
<script src="scripts/game/Beebee.js"></script>
<script src="scripts/demo/Demo_SceneSetup.js"></script>
<script src="scripts/demo/Demo_Hong.js"></script>
<script src="scripts/demo/Demo_Beebee.js"></script>
<script src="scripts/main.js"></script>

59
scenes/attack.md Normal file
View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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++;

View File

@ -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);
};

View File

@ -5,7 +5,7 @@ or maybe CA?
******************************/
function BGAnxiety(){
function BG_Anxiety(){
var self = this;

View File

@ -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<dialogue.length; i++){
// Add the text, letter by letter!
var interval = 0;
var SPEED = Math.round(40 / Game.OVERRIDE_TEXT_SPEED);
for(var i=0; i<dialogue.length; i++){
var ch = dialogue[i];
var ch = dialogue[i];
// for scopin'
(function(ch, interval){
setTimeout(function(){
div.innerHTML += ch;
}, interval);
})(ch, interval);
// for scopin'
(function(ch, interval){
setTimeout(function(){
div.innerHTML += ch;
}, interval);
})(ch, interval);
// Bigger interval
if(ch=="."){
interval += SPEED*10;
}else{
interval += SPEED;
}
// Bigger interval
if(ch=="."){
interval += SPEED*10;
}else{
interval += SPEED;
}
}
// Return promise
var nextLineDelay = 300;
if(dialogue.slice(-1)=="-") nextLineDelay=0; // sudden interrupt!
setTimeout(resolve, interval+nextLineDelay);
// Return promise
setTimeout(function(){
promiseDone(true, []);
}, interval+200);
return promiseDone;
});
}
// Execute choice! Add it to choice DOM.
Game.OVERRIDE_CHOICE_LINE = false;
Game.executeChoice = function(line){
var choiceText = line.match(/\[(.*)\]/)[1].trim();
var choiceID = line.match(/\(\#(.*)\)/)[1].trim().toLocaleLowerCase();
var choiceText = line.match(/\[([^\]]*)\]/)[1].trim();
var choiceID = line.match(/\(\#([^\)]*)\)/)[1].trim().toLocaleLowerCase();
var preChoiceCodeIfAny = null;
if(/\`(.*)\`/.test(line)){
preChoiceCodeIfAny = line.match(/\`(.*)\`/)[0]; // 0, with backticks
}
var div = document.createElement("div");
div.innerHTML = choiceText;
div.onclick = function(){
Game.addToQueue("> "+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);
});
};

64
scripts/game/Loader.js Normal file
View File

@ -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();
});
};

View File

@ -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);
};

1
scripts/lib/rsvp.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,12 @@
var xhr = new XMLHttpRequest();
xhr.open('GET', 'scenes/demo.md?v='+Math.random());
xhr.onload = function() {
if(xhr.status===200){
Game.onload(xhr.responseText);
}
};
xhr.send();
// Load assets
Loader.addScenes([
"scenes/demo.md"
]);
Loader.addImages([
{ id:"demo_beebee", src:"sprites/demo_beebee.png" },
{ id:"demo_hong", src:"sprites/demo_hong.png" }
]);
Loader.load().then(function(){
Game.init();
Game.start();
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

BIN
sprites/demo_beebee.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
sprites/demo_hong.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB