xxxxxxxxxx
141
//var bg;//background image
//var clouds;
//var plantpot;
//var serial;
//var latestdata = "waiting for data";
//var sensors;
//var pot;
//var fsr;
//var wat;
//start
let startBG;
let startCactus;
let startPalmtree;
let startGreenplant;
let i = 0;
let startButton;
//
//plant
//var plant = [0,1,2];
//var plantSizeX;
//var plantSizeY;
//var plantPosX;
//var plantPosY;
//var plantPos;
//var plantSize;
//var cloudsData;
//var plantText;
//var plantDone;
//var sizeChange = false;
//end
//var endBG;
//var endRestart;
//var screenvalue = 0;
function preload() {
// endBG = loadImage('');
startBG = loadImage('background.png');
startCactus = loadImage('cactus.png');
startPalmtree = loadImage('palm_tree.png');
startGreenplant = loadImage('greenplant.png');
// bg = loadImage();
//clouds = loadImage();
//plantpot = loadImage();
// watering[0] = loadImage();
//watering[1] = loadImage();
//watering[2] = loadImage();
//wateringText = loadImage();
//waterOut = loadImage();
//waterIn = loadImage();
//plant[0] = loadImage();
//plant[1] = loadImage();
//plant[2] = loadImage();
//plantText = loadImage();
}
function setup() {
createCanvas(7000,5000);
serial = new p5.SerialPort();
serial.open();
serial.on('data', gotData);
startButton = createButton('Next');
startButton.position(300, 400);
startButton.size(100, 50);
startButton.mousePressed(startButtonClick);
}
function gotData () {
var currentString = readStringUntil("\r\n");
if (currentString) {
sensors = split(currentString, ",");
if (sensors.length == 3){
pho = int (sensors[0]);
fsr = int (sensors[1]);
wat = int (sensors[2]);
}
console.log(pho,fsr,wat);
}
}
function draw() {
if (screenNum == 0){
startGame();
} else if (screenNum == 1) {
removeElements();
wateringGame();
} else if (screenNum == 2) {
removeElements();
clear();
plantGame();
cloudsDisappear();
} else {
removeElements();
clear();
endGame();
}
}
function startGame() {
noTint();
image(startBG,0,0,7000,5000);
startDone = createImg();
startDone.position(4000,3000);
startDone.size(4000,3000);
startDone.mousePressed(screenAdd);
noTint();
image(startBG, 0, 0, 7000, 5000);
// Display cactus image
tint(255, 255, 255); // Reset tint
image(startCactus, 0, 0, 7000, 5000);
// Check if the mouse is over the cactus image
if (mouseX >= 0 && mouseX <= 7000 && mouseY >= 0 && mouseY <= 5000) {
if (mouseIsPressed) {
// Tint the cactus with a different color when clicked
tint(255, 0, 0); // Red tint
image(startCactus, 0, 0, 7000, 5000);
// Handle the click event for the cactus
chosenPlant = 0; // Set the chosen plant (you can use a different value)
screenNum = 1; // Move to the next screen
} else {
// Highlight the cactus with a different color when hovered
tint(0, 255, 0); // Green tint
image(startCactus, 0, 0, 7000, 5000);
}
}
}