So the aim is to:
Add a background for the game in the form of a grid. The grid “cell” must be 90 pixels in size in both dimensions when the screen is 1280x720. Note: Do not draw your grid with rectangles or squares, draw it with lines only. We will not adjust the size of your screen when marking this assignment, it only needs to work for 1280x720.
Instead of drawing just one square that moves back and forth, have 4 squares in a vertical stack move back and forth. They should move as one and when any of them hit the edge of the window, all of them change direction. NB: You must use a loop to avoid repeating the same code 4 times when drawing 4 squares. Squares should have a black border and be orange (the same orange as assignment one).
The most useful module is loops.
However, my block keeps going down, it wont move back and forth fast…
I’m also unsure how to loop more rectangles…
float counter;
float sizeW;
float sizeH;
float dir;
boolean paused;
float x = 0;
float y = 0;
float spacing = 90;
void setup() {
size(1280, 720);
counter = 0;
dir = (float)height/720;
sizeW = (float)width/14.2;
sizeH = (float)height/8;
paused = true;
}
void draw() {
background(240);
stroke(0);
strokeWeight(1);
fill(255, 147, 79);
// current level
int steppedPos = (int)(counter/sizeH+0.5);
rect(0, steppedPos*sizeH, sizeW, sizeH*4);
// movement
if (paused) {
counter = counter + dir;
if (counter + sizeH > height || counter < 0) {
dir = dir * -1;
counter = counter + dir;
}
x=90;
while (x < width) {
line(x, 0, x, height);
x = x + spacing;
}
y=90;
while (y<height) {
line(0, y, width, y);
y = y + spacing;
}
}
}
void keyPressed() {
if (key == ' '){
paused = !paused;
}
}