1
0
forked from sent/waves
chunglloyd_unblocker/public/assets/g/tetris/PreviewGroup.js
2025-04-09 17:11:14 -05:00

47 lines
952 B
JavaScript

function PreviewGroup(baseX, baseY) {
var i;
this.blocks = [];
this.shape = null;
// create the blocks
for (i = 0; i < 4; i += 1) {
this.blocks.push(new Block({
boardOriginX: baseX,
boardOriginY: baseY,
blockX: 0,
blockY: 0,
shape: 'i'
}));
}
}
/**
* Sets the shape and color of the blocks
* @param {Char} shape - the letter of the new shape
* @param {Boolean} preview - true if it should have preview colors
*/
PreviewGroup.prototype.setShape = function(shape) {
var shapeConfig = SHAPES[shape],
i;
this.shape = shape;
for (i = 0; i < 4; i += 1) {
this.blocks[i].setPosition(shapeConfig.pos[i].x, shapeConfig.pos[i].y);
this.blocks[i].setColor(shape, false);
}
};
PreviewGroup.prototype.getShape = function () {
return this.shape;
};
PreviewGroup.prototype.draw = function() {
var i;
for (i = 0; i < 4; i += 1) {
this.blocks[i].draw();
}
};