-
-
Save melcor76/7772cdf189c2da78ec4b7577b4e6d8a5 to your computer and use it in GitHub Desktop.
js-tetris - piece draw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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