Skip to content

Instantly share code, notes, and snippets.

@melcor76
Created November 19, 2019 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melcor76/7772cdf189c2da78ec4b7577b4e6d8a5 to your computer and use it in GitHub Desktop.
Save melcor76/7772cdf189c2da78ec4b7577b4e6d8a5 to your computer and use it in GitHub Desktop.
js-tetris - piece draw
draw() {
this.ctx.fillStyle = this.color;
this.shape.forEach((row, y) => {
row.forEach((value, x) => {
// this.x, this.y gives the left upper position of the shape
// x, y gives the position of the block in the shape
// this.x + x is then the position of the block on the board
if (value > 0) {
this.ctx.fillRect(this.x + x, this.y + y, 1, 1);
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment