xxxxxxxxxx
125
let fontFile = "InkVerse.ttf";
let walkTimer = 0;
let currentFoot = 0; //0 is left foot, 1 is right foot
let exhaustion = 0;
let currentScene = 0;
let endScene,exhaustBar;
let fillValue = 0.0;
let walkScenes = [];
function setup() {
createCanvas(500, 500);
myFont = loadFont(fontFile);
}
function preload() {
for(let i = 0;i<6;i++) { //i less than number of testx scenes
walkScenes[i] = loadImage("scenes/testt"+i+".png");
}
endScene = loadImage("end.png");
tiredScene = loadImage("tired.png");
exhaustBar = loadImage("bar.png");
}
function draw() {
background(220);
step();
thoughts();
}
function step() {
walkTimer++;
//print(walkTimer);
//have a bar to show exhaustion points out of 3
if(exhaustion==3) {
image(tiredScene,0,0,width,height);
if(walkTimer==240) { //
//walkTimer = 0;
exhaustion = 0;
}
} else { //could zoom in on a scene 3 times to avoid adding like, 10 scene images
if(currentScene!=walkScenes.length) {
image(walkScenes[currentScene],0,0,width,height);
}
else {
image(endScene,0,0,width,height);
}
}
}
function switchFoot(foot) {
if(walkTimer<=80) { //
exhaustion++;
}
walkTimer = 0;
if(currentFoot != foot) { //checks that the foot moved is not the same as the current foot
if(currentScene != walkScenes.length) {
currentScene++;
print('hi');
}
currentFoot = foot;
}
}
function thoughts() {
//exhaustion bar
push();
fill('gray');
rect(29,70,450,28);
fill('coral');
if(exhaustion==1) {
rect(29,70,138,28);
} else {
if(exhaustion==2) {
rect(29,70,304,28);
} else {
if(exhaustion==3) {
rect(29,70,450,28);
}
}
}
image(exhaustBar,16,18);
pop();
//text
if(exhaustion!=3) {
push()
textFont(myFont);
textSize(28);
text("Left foot forward, then right", 40, 60);
pop();
} else {
push()
textFont(myFont);
textSize(30);
text("Can't walk, too exhausted", 45, 60);
pop();
}
if(currentScene==walkScenes.length) {
noStroke();
fill('hsla(0,0%,0%,'+fillValue+')');
rect(0,0,width,height);
if(fillValue<1.5) {
fillValue+=0.01;
}
}
}
function keyPressed() { //could play sound when taking step
if(exhaustion!=3) {
if((keyCode==LEFT_ARROW)||(keyCode==83)) {
switchFoot(0);
}
if((keyCode==RIGHT_ARROW)||(keyCode==68)) {
switchFoot(1);
}
}
}
/*function mouseClicked() {
follow = false;
print(mouseX+"," +mouseY);
}*/