let backgroundImg, gameBackgroundImg, gameOverImg;
backgroundImg = loadImage('background.jpg');
gameBackgroundImg = loadImage('game_background.jpg');
gameOverImg = loadImage('game_over.jpg');
mushroomImg = loadImage('mushroom_transparent.png');
basketImg = loadImage('basket_transparent.png');
bombImg = loadImage('bomb_transparent.png');
restartButton = createButton('RESTART');
restartButton.style('font-size', '24px');
restartButton.style('background-color', '#FFD700');
restartButton.style('padding', '12px 24px');
restartButton.style('border-radius', '8px');
restartButton.position(width / 2 - 50, height / 2 + 50);
restartButton.mousePressed(restartGame);
clearInterval(timerInterval);
timerInterval = setInterval(() => {
clearInterval(timerInterval);
for (let i = 0; i < 10; i++) {
mushrooms.push(new Mushroom());
for (let i = 0; i < 3; i++) {
function displayStartScreen() {
image(backgroundImg, 0, 0, width, height);
rect(width / 2 - 300, height / 2 - 150, 600, 250, 20);
text("🌟 WELCOME TO MUSHROOM CATCH! 🌟", width / 2, height / 2 - 120);
text("✨ Catch as many mushrooms as you can!", width / 2, height / 2 - 30);
image(bombImg, width / 2 - 90, height / 2 - 25, 30, 30);
text("💣 But beware of the falling bombs!", width / 2 - 50, height / 2);
text("🕹️ Move the basket with your mouse!", width / 2, height / 2 + 30);
rect(width / 2 - 200, height / 2 + 70, 400, 80, 20);
text("CLICK TO START", width / 2, height / 2 + 110);
function mousePressed() {
image(gameBackgroundImg, 0, 0, width, height);
rect(80, 30, 120, 40, 10);
text(`Score: ${score}`, 140, 55);
rect(80, 80, 120, 40, 10);
text(`Time: ${timer}`, 140, 105);
for (let mushroom of mushrooms) {
if (basket.collect(mushroom)) {
for (let bomb of bombs) {
if (basket.collect(bomb)) {
function displayGameOver() {
clearInterval(timerInterval);
image(gameOverImg, 0, 0, width, height);
rect(width / 2 - 220, height / 2 - 80, 440, 120, 20);
text("GAME OVER!", width / 2, height / 2 - 20);
text(`Final Score: ${score}`, width / 2, height / 2 + 20);
this.y = random(-500, -50);
this.speed = random(2, 5);
this.y = random(-500, -50);
image(mushroomImg, this.x, this.y, this.size, this.size);
this.y = random(-500, -50);
this.speed = random(3, 6);
this.y = random(-500, -50);
image(bombImg, this.x, this.y, this.size, this.size);
this.x = constrain(mouseX, this.width / 2, width - this.width / 2);
image(basketImg, this.x - this.width / 2, this.y, this.width, this.height);
item.y + item.size / 2 > this.y &&
item.x > this.x - this.width / 2 &&
item.x < this.x + this.width / 2