Hey I’m trying to create a match 3 game with blocks that dont just drop downwards. I’ve tried several ways to get my blocks to do as i want but my booleans ain’t working correctly. The enemy should check below till it reaches the bottom or another block then if on top of another block it checks left or right, but one block below to see if it should drop down.
Here a picture of the game so far
this one shows the booleans as you can see left and right are false but should be true
that top block should have left and right being true
here the main code:
ArrayList<Block> block = new ArrayList<Block>();
Control con = new Control();
int s = 25;
int sx = 50;
void setup(){
size(600,600);
block.add(new Block(sx,height-(s*2),0));
}
void draw(){
background(0);
textSize(20);
text("Size: " + block.size(), 5,20);
for (Block b: block){
b.show();
b.check();
}
//con.show();
}
void keyPressed(){
if (key == 'n'){
con.update();
}
if (key == ' '){
for (Block b: block){
b.move();
b.timer = 5;
}
}// n
}// keyPressed
here the block code:
class Block{
int x,y,type;
int timer = 0;
int yspd = 0;
int xspd = 0;
boolean left, right, down,moved;
Block(int x, int y, int type){
this.x = x;
this.y = y;
this.type = type;
}
void show(){
if (type == 0){fill(255,0,0);}
if (type == 1){fill(0,255,0);}
rect(x,y,s,s);
textSize(20);
/*text("L: " + left, x + 25, y);
text("R: " + right, x + 125, y);
text("D: " + down, x + 225, y);
text("M: " + moved, x + 325, y);
text("Xspd: " + xspd, 5, 60);
text("Yspd: " + yspd, 5, 80);*/
}// show
void res(){
if (timer > -1){timer -= 1;}
down = true;
left = true;
right = true;
xspd = 0;
yspd = 0;
}
void check(){
res();
for (int i = 0; i < block.size(); i++){
Block b = block.get(i);
if (y + s == height || b.y - s == y && b.x == x){down = false;}
if (x - s == 0 || b.x - s == x && b.y + s == y || b.y + s == height){left = false;}
if (x + s == width || b.x + s == x && b.y + s == y || b.y + s == height){right = false;}
}
if (down == true){yspd = 1;}
if (right == true && left == true && down == false){
float r = random(1);
r = round(r);
if (r == 0){xspd = 1;}
if (r == 1){xspd = -1;}
}
if (left == false && right == false && down == false){moved = true;}
}// check
void move(){
if (timer > -2 && timer <= 0){
y += yspd * s;
x += xspd * s;
timer = -3;
}// timer
}// move
}
i made the timer reset when press space, so i can control it better & instead of using my controller i press n for next for more control.