Yes I wrote it all myself. I didn’t put the classes in here cause I thought they aren’t important for this part, cause they just have the draw function of the flower etc. And for Loop I didn’t quite know where to place it.
Here’s the full code:
ArrayList gardenObject;
public enum GameState {
LAWN, FLOWER, REMOVE, MOVING
}
GameState state;
void setup () {
size (700, 600);
gardenObject = new ArrayList();
this.state = GameState.FLOWER;
}
void draw () {
background(255);
for (int i = 0; i<gardenObject.size(); i++) {
gardenObject.get(i);
}
//Reihenfolge der GameStates
switch(state) {
case FLOWER:
drawGame();
break;
case LAWN:
drawGame();
break;
case REMOVE:
drawGame();
break;
case MOVING:
drawGame();
break;
}
}
void switchState (GameState newState) {
this.state = newState;
}
void drawGame () {
noFill();
rect (70, 500, 100, 50);
rect (220, 500, 100, 50);
rect (370, 500, 100, 50);
rect (520, 500, 100, 50);
fill(0);
textSize(20);
text(“FLOWER”, 90, 530);
text(“LAWN”, 240, 530);
text(“MOVE”, 390, 530);
text(“REMOVE”, 540, 530);
}
void mousePressed() {
switch(state) {
case FLOWER:
//Listening for mousePressed
if (mouseX >= 70 && mouseX <= 170 &&
mouseY >= 500 && mouseY <= 550) {//condition for mouse to be inside 1st button
switchState(GameState.FLOWER);//action for 1st button
}
case LAWN:
if (mouseX >= 220 && mouseX <= 320 &&
mouseY >= 500 && mouseY <= 550) {//condition for mouse to be inside 2nd button
switchState(GameState.LAWN);//action for 2nd button
}
case MOVING:
if (mouseX >= 370 && mouseX <= 470 &&
mouseY >= 500 && mouseY <= 550) {
switchState(GameState.MOVING);
}
case REMOVE:
if (mouseX >= 520 && mouseX <=620 &&
mouseY >= 500 && mouseY <= 550) {
switchState(GameState.REMOVE);
}
}
}
void mouseClicked () {
if (this.state == GameState.FLOWER) {
gardenObject.add(new Flower(mouseX, mouseY));
}
if (this.state == GameState.LAWN) {
gardenObject.add(new Lawn(mouseX, mouseY));
}
}
public class Flower extends GardenObject{
Flower(float thisx, float thisy) {
x = thisx;
y = thisy;
}
void draw () {
translate(mouseX - 50, mouseY - 50);
scale(0.2);
beginShape();
//stem
fill(44, 191, 83); //make it green
rect(240, 250, 20, 220); //make tall rectangle in center
//petal 1 (bottom left)
fill(random(250), random(250), random(250));
ellipse(175, 250, 150, 150);
//petal 2 (bottom right)
ellipse(325, 250, 150, 150);
//petal 4 (top left)
ellipse(175, 130, 150, 150);
//petal 5 (top right)
ellipse(325, 130, 150, 150);
//petal 3 (bottom)
fill(random(250), random(250), random(250));
ellipse(250, 275, 150, 150);
//petal 6 (top)
ellipse(250, 100, 150, 150);
//petal 7 (left)
ellipse(150, 180, 150, 150);
//petal 8 (right)
ellipse(350, 180, 150, 150);
//center of flower
fill(255, 218, 94); //fill in yellow
ellipse(250, 200, 80, 80); //make circle in the middle
endShape();
}
}
public class GardenObject {
float x;
float y;
void drawGardenObject () {
}
void clicked () {
}
}
public class Lawn extends GardenObject {
Lawn(float thisx, float thisy) {
x = thisx;
y = thisy;
}
void draw () {
fill(70, 200, 80);
rect(mouseX - 50,mouseY - 50,100,100);
}
}
I am not finished yet though, but as I said kinda stuck on how to make the different objects appear depending on which state your on.