I have a homework assignment due on friday and I need help! I've only started using processing this week so please be nice :p
My idea is a simple game where the user would use the mouse (wateringcan.png) and click within the image (grass) and another image (bulb) will pop up and then when you click on the image (grass) again, a 2nd image will pop up (flower).
Problem: I can click anywhere on the background and the bulb and flower will pop up. I want to only be able to click the "grass" image and the bulb and flower will pop up.
thank you for your help!
Here is my code:
PImage pot, grass, flower,bulb;
int potx, poty, potw, poth;
int grassx, grassy, grassw, grassh;
int flowerx, flowery, flowerw, flowerh;
int bulbx, bulby, bulbw, bulbh;
int state = 0;
void setup() {
size (400, 400);
pot = loadImage("wateringcan.png");
grass=loadImage("PLANT.png");
flower = loadImage("flower.png");
bulb = loadImage("bulb.png");
//grass
image(grass, width/2, height/2);
flowerx = height/2 - flowerw/2;
flowery = width/2 - 15;
flowerw = 25;
flowerh = 25;
bulbx = height/2 - bulbw/2;
bulby = width/2 - 10;
bulbw = 20;
bulbh = 20;
}
void draw() {
background (51, 173, 70);
//grass
image(grass, width/2, height/2);
//water pot and water droplets
image(pot, mouseX+2, mouseY-120);
if (mousePressed == false) {
fill (0);
}
else {
//droplets
noStroke();
fill(52, 232, 215);
ellipse (mouseX, mouseY -30, 1, 9);
ellipse (mouseX - 10, mouseY - 20, 1, 9);
ellipse ( mouseX, mouseY - 15, 1, 10);
ellipse (mouseX - 15, mouseY - 5, 1, 9);
ellipse (mouseX + 3, mouseY -6, 1, 10);
ellipse (mouseX -6, mouseY - 8, 1, 10 );
loop();
}
if(state == 1) {
image(bulb, bulbx, bulby, bulbw, bulbh);
}
if(state >= 2) {
image(flower, flowerx, flowery, flowerw, flowerh);
}
if (state == 0);
}
void mousePressed() {
state = state + 1;
}
1