My goal is to create a game similar to Tetris, where the pieces are composed of smaller blocks that share attributes.
My current progress includes:
export class SquareTetromino {
[x: string]: any;
constructor(x, y, w, h) {
...
}
show(p5) {
p5.push();
p5.translate(this.posX, this.posY);
p5.fill("#D8B6FF")
p5.rect(0,0,this.w, this.h);
p5.pop();
}
...
}
and:
export class BlockTetromino {
[x: string]: any;
constructor(x, y, w, h) {
...
}
test(p5) {
this.testArray.push(new SquareTetromino(this.posX,this.posY,this.w,this.h));
this.testArray.push(new SquareTetromino(this.posX - 50,this.posY,this.w,this.h));
this.testArray.push(new SquareTetromino(this.posX - 50,this.posY + 50,this.w,this.h));
this.testArray.push(new SquareTetromino(this.posX,this.posY + 50,this.w,this.h));
}
show(p5) {
p5.push();
this.testArray.forEach((block) => {
block.show(p5)
})
p5.pop();
}
}
In my main component:
s.setup = () => {
...
bodies.push(new BlockTetromino(200,-50,50,50))
bodies[0].test(s);
...
}
s.draw = () => {
...
for (let i = 0; i < bodies.length; i++) {
bodies[i].show(s)
}
I envision having a Block class to draw a small block, then utilizing that within a Square class to draw 4 small blocks. By creating an instance of Square, I aim to have 4 blocks connected as one object.
I suspect there may be a need for a for loop somewhere in my code.