xxxxxxxxxx
//This is a simple version of mbti test, one kind of personality test
//To get to the next scene, press any key.
//Plz press 1 or 2 in the situation of choices.
//the first trial starts right away
var thestuff;
var s = 0;
var thediv;
var end = false;
var feature = {}
function preload() {
thestuff = loadJSON("adventure11.json");
}
function setup() {
createCanvas(windowWidth, windowHeight);
thediv = createDiv('this is a test');
thediv.style('font-size', '48px');
thediv.style('font-family', 'Courier');
thediv.position(50, 50);
thediv.size(width-50, height-50);
noLoop(); // turn of auto drawing
redraw();
}
function draw() {
s = (s+1)%thestuff.scenes.length
background(255);
fill(0);
{// draw the main text:
var t = thestuff.scenes[s].text;
// draw the picture if it exists:
if(thestuff.scenes[s].image) {
t+= "<br><img src="+thestuff.scenes[s].image+" width=30%>";
}
// render the options if they exist:
if(thestuff.scenes[s].choices){
for(let i = 0;i<thestuff.scenes[s].choices.length;i++){
t+="<br/>"+"<b>"+(i+1)+"</b>" + ": " + thestuff.scenes[s].choices[i].text;
}
}
// play the sound:
if(thestuff.scenes[s].sound) {
let a="<audio autoplay><source src="+thestuff.scenes[s].sound+" type=\"audio/mpeg\"></audio>";
t+=a;
}
}
// show the html:
thediv.elt.innerHTML = t;
}
function keyPressed() {
if(thestuff.scenes[s].choices){
for(let i = 0;i<thestuff.scenes[s].choices.length;i++) //execute the code
{
if(key==i+1){
let c = thestuff.scenes[s].choices[i].code; //put the value in the object literal
eval(c);
}
}
}
redraw()
if(thestuff.scenes[s].code) {
let c = thestuff.scenes[s].code;
eval(c);
}
}