Stacking shapes

Hi, so I am replicating the game ’ Stack’ on processing. I was wondering if anyone knew how to make the shapes stack on top of each other when the mouse is clicked. When the mouse is clicked, the rectangle that is moving stops and then on top of that another rectangle appears and this one moves.

Please let me know as soon as you can
Thanks!

2 Likes

That a lot to help you with. What’s the problem? Working out the part of the rectangle that overlaps? Drawing rectangles in 3D? Changing game states? Animating things?

It’s not exactly clear what you’re having trouble with, because…

YOU HAVEN’T SHARED ANY OF YOUR CODE WITH US.

To even START trying to help you with a demonstration, I have NOTHING to work with. I literally have to start coding THE WHOLE GAME FROM SCRATCH to START helping you. That is a TON of work, and way more effort than I -and I imagine anyone else - is willing to put in.

So.

POST. YOUR. CODE!

1 Like

Please post a link so we can see it

1 Like

Although this is 3D, it might be easier for you to do in 2D first.

Also not with diagonally flying rects but with straight flying rectangles, from left and top

2 Likes

This game?

int rx=200; //x coordinate of moving rectangle
String start="start";
String instruct="instructions"
  int ry=380;
int l=50;
int w=140;
int sx=140;
int sy=410;
int minX=200; 
int maxX=350;
int gamestart=0; 
int a = 20;
//int rx2=
String start="start";
String instruct="instructions";
color turquoise= color(105, 247, 203);
color blue= color(78, 153, 242);
color darkblue= color(17, 180, 237);
color orange= color(237, 211, 12);

void setup() {
  size(640, 480);
  textSize(25);
  startbutton();
  instructbutton();
}

void draw() {
  background(105, 247, 203);
  fill(0);
  //starting rectangle
  rect(200, 430, 140, 50);
  //moving rectangle
  noStroke();
  fill(47, 227, 232);
  rect(rx, ry, 140, 50);
  println(rx+" "+ry);
  rx=rx+3;
  if (rx>=width)
    rx=0;
  if (ry==620) {
    rect(a, 20, 20, 20);
    a=a+1;
  }
  mouseClicked();//go to mouseclicked function
}
void instruct() {//function used to show the instructions when the button is clicked
  fill(darkblue);
  rect(0, 0, width, height);
  fill(orange);
  textSize(22);
  //text
  String begin= "Game Instructions";
  String line 1=" In Stack it Up, the player the player will attempt to stack";
  String line2= "the moving rectangles on top of each other."
    String line3= "if the stack and the moving square align, the player will";
  String line 4= "receive an extra point.";
  String line 5= "if you miss a block, you will have to try again!";

  //text position on the screen
  text(begin, 50, 50);
  text(line1, 50, 80);
  text(line2, 50, 110);
  text(line3, 50, 140);
  text(line4, 50, 170);
  text(line5, 50, 190);
  mouseClicked();// this refers to the mouseCLick function

  void startbutton() {
    fill(orange);
    rect(sx, sy, 110, 60);
    fill(0);
    text(start, sx+20, sy+40);//text that's found on the start rectangle
  }

  void instructbutton() {
    fill(255);
    rect(sx+180, sy, 110, 60);
    fill(0);
    text(instruct, rx+180, sy+40);//text on instruction button
  }
  void mousePressed() {
    if (mousePressed==true) {
      noLoop();
      if (ry<=380) {
        fill(turquoise);
        rect(200+w, ry, w, l);
        fill(blue);
        ry=ry+200;
      }
    }
  }

please format your code in above post, using the forum post editor feature

</> code tag

looks like
```
type or paste code here
```

If you put it into the Processing editor (PDE) then you get a long list of error messages.

You can start by going through one at a time and fixing them. Don’t define the start variable twice. Don’t name a variable “line 1” – it has to be a single word, like line1 or line_1. Semicolons are missing. Look at each error in the errors tab, click to go to that line, and fix the problem. If you get stuck on how to fix a problem, ask for help here…

But before you do any of that, add a } on the line before void startbutton() {. Without it you get many, many errors that aren’t really errors.

1 Like