xxxxxxxxxx
77
let gameState = 'start'; // Possible states: 'start', 'game', 'end'
let garden = [];
let restartButton;
function setup() {
createCanvas(600, 600);
textAlign(CENTER, CENTER);
// Restart button (hidden initially)
restartButton = createButton('Restart');
restartButton.position(width / 2 - 50, height / 2 + 20);
restartButton.mousePressed(restartGame);
restartButton.hide();
}
function draw() {
background(161, 196, 170);
if (gameState === 'start') {
drawStartScreen();
} else if (gameState === 'game') {
drawGarden();
} else if (gameState === 'end') {
drawEndScreen();
}
}
function drawStartScreen() {
textSize(32);
text('Whimsical Garden: Seasons of Growth', width / 2, height / 3);
textSize(25);
text('Click to start', width / 2, height / 2);
}
function drawGarden() {
for (let plant of garden) {
// Simple representation of plants
fill(20, 180, 60);
ellipse(plant.x, plant.y, 20, 20);
}
// Example end condition: 5 plants
if (garden.length >= 5) {
gameState = 'end';
restartButton.show();
}
}
function drawEndScreen() {
background(47, 54, 50);
textSize(50);
fill(184, 46, 64);
text('Garden is Full!', width / 2, height / 3);
textSize(25);
text('Restart to play again', width / 2, height / 2);
}
function mousePressed() {
if (gameState === 'start') {
gameState = 'game';
} else if (gameState === 'game' && mouseY < height - 100) {
// Allow planting only within the game area (excluding UI elements, e.g., buttons)
plantSeed(mouseX, mouseY);
}
}
function plantSeed(x, y) {
// Add a new plant to the clicked position in the garden
garden.push({x: x, y: y});
}
function restartGame() {
garden = []; // Clear the garden
gameState = 'start'; // Set game state back to start
restartButton.hide();
}