使用循环使堆栈逐步移动

问题描述 投票:0回答:1

我正在尝试使4个盒子的堆栈逐步移动。目前,我只能以4叠显示它,但是它无法移动。有人可以通过使用循环且没有任何类来帮助我使4个堆栈的堆栈逐步移动吗?

//Declare variables
boolean move = true;
float loc;
float sizeW;
float sizeH;
float dir;
float y;


void setup() {
  //Set screen size
  size (1280, 720);
  loc = 0;
  dir = (float)height/720;
  sizeW = (float)width/14.2;
  sizeH = (float)height/8;
  move= true;
}

void draw() {  
  //Set Background to white
  background (240, 240, 240);
  //Set grid on x and y axis
  for (int i = 0; i < width; i = i + 90) {
    line(0, i, 1280, i);
    line(i, 0, i, 720);
    //rectangle fill
    fill(255, 147, 79); 

    //rectangle moving in steps
    int steppedPos = (int)(loc/sizeH+0.5);
    for (int y = 0; y < 4; ++y) {
      rect(0, (y*sizeH), sizeW, sizeH);
      dir++;
    }
    //IF statement that will only run if the move variable is true
    if (move) {
      loc = loc + dir;
      if (loc + sizeH > height || loc < 0) {
        dir = dir * -1;
        loc = loc + dir;
      }
    }
  }
}

void keyPressed() {
  //IF statement that will only run if keyCode variable is equal to 32 (SpaceBar)
  if (keyCode == 32) {
    //Flip the move variable
    move = !move;
  }
}
processing
1个回答
0
投票

您将在我周一的演讲中找到所有答案。我无法链接到它,因为它仅适用于COMP1000学生,但是其中包括您吗?

© www.soinside.com 2019 - 2024. All rights reserved.