xxxxxxxxxx
91
let bckg;
let bloodSpots = [];
let spotImage;
let score = 0;
let spongeSize = 30;
let timer = 30;
function bloodySpotSetup() {
createCanvas(windowWidth, windowHeight);
bckg.play();
// Generate the spots
for (let i = 0; i < 10; i++) {
bloodSpots.push(new BloodySpot());
}
}
function bloodySpotDraw() {
background(220);
if (frameCount % 60 == 0 && timer > 0) {
timer--;
} else if (timer == 0) {
gameOver();
return;
}
for (let spot of bloodSpots) {
spot.update();
spot.show();
}
// Text
noFill();
stroke(0);
ellipse(mouseX, mouseY, spongeSize);
fill('black');
textSize(15);
textFont(paraFont);
textAlign(CENTER, CENTER);
text("Lady Macbeth is driven mad by guilt", windowWidth/2, 50);
text("She attempts to wash off the blood of the king.", windowWidth/2, 70);
text("Press on the spots to wash them off.", windowWidth/2, 100);
fill(0);
textSize(24);
textAlign(LEFT, TOP);
text("Score: " + score, 50, 30);
text("Time: " + timer, windowWidth - 200, 30);
}
function gameOver() {
background(220);
fill('black');
textSize(20);
textAlign(CENTER, CENTER);
text("GAME OVER", windowWidth/2, windowHeight/2);
text("Final Score: " + score, windowWidth/2, 360);
textSize(20)
text("Lady Macbeth wasn't able to wash off all of her spots!", windowWidth/2, 30)
text("Engulfed by her guilt, she commits suicide", windowWidth/2, 60)
noLoop(); // Stop the game loop
}
class BloodySpot {
constructor() {
this.spawn();
}
spawn() {
this.x = random(10, windowWidth - 100);
this.y = random(10, windowHeight - 100);
this.size = random(50, 150);
this.fadeDirection = 1;
}
show() {
push();
image(spotImage, this.x, this.y, this.size, this.size);
pop();
}
update() {
this.checkWashed();
}
checkWashed() {
if (mouseX > this.x && mouseX < this.x + this.size && mouseY > this.y && mouseY < this.y + this.size &&
mouseIsPressed) {
score++;
this.spawn();
}
}
}