xxxxxxxxxx
97
let sneak, boo;
let mummy,mummyState;
let countDownTurned = -1;
let girl, girlGliding = -1, girlPosition = 0;
let displayBoo = -1, booImg;
let candies = 0;
function preload() {
mummy = loadImage("mummy_small_transp.png");
mummyState = "unaware";
girl = loadImage("girl.png");
booImg = loadImage("boo.png");
}
function setup() {
createCanvas(400, 300);
sneak = select("#sneakBtn");
boo = select("#scareBtn");
sneak.mousePressed(()=>{
girlGliding = 30;
});
boo.mousePressed(()=>{
displayBoo = 90;
mummyState="scared";
});
}
function draw() {
background(color("#8C71BB"));
noStroke();
fill("white");
textSize(20);
text("🍬 "+candies,10,30);
// street
fill("lightgray");
rect(0,270,width,60);
if (mummyState=="unaware"){
image(mummy,250,55,150,238,
214,0,150,238);
} else if (mummyState=="turned"){
image(mummy,250,55,110,238,
106,0,110,238);
} else if (mummyState=="scared"){
image(mummy,250,55,107,238,
0,0,107,238);
}
if (displayBoo>0){
displayBoo--;
image(booImg,
girlPosition+cos(frameCount/10)*5,
100+sin(frameCount/30)*10);
}
if (displayBoo==0){
candies += ~~(random(1,10)* 2*girlPosition/30 );
girlPosition = 0;
mummyState="unaware";
displayBoo = -1;
}
if (girlGliding>0){
girlGliding--;
image(girl,girlPosition+30-girlGliding,160);
} else {
image(girl,girlPosition,160);
}
if (girlGliding==0){
// done gliding
girlPosition += 30;
girlGliding = -1;
if (random()+girlPosition/30/6>1.0){
//console.log("mummy turns");
mummyState = "turned";
countDownTurned = 30;
}
}
if (countDownTurned>0){
countDownTurned--;
}
if (countDownTurned==0){
girlPosition = 0;
mummyState="unaware";
candies = candies - ~~(candies*.1);
countDownTurned = -1;
}
}