jQuery toggleClass example
Toggle class name on click in jQuery
by nikolya223
HTML
<canvas height='1200' width='1600' id='canva'>FX</canvas>
CSS
canvas{
background: #ffffff;
}
JavaScript
class Tetris {
constructor(opt={}) {
this.config = Object.assign(this.config, opt);
this.core = new TetrisCore(this);
this.init();
}
config = {
canvas : '#canva',
fps : 30,
cells : [13,20],
cellWidth : 20,
leftOffset : 40,
topOffset : 40
}
data = {
workspace : {
left: null,
right: null,
top: null,
bottom: null,
width: null,
height: null
},
matrix : [],
interface : {
color : '#2c97f9',
borderColor : 'rgba(255,255,255, .6)',
backgroundColor : 'rgba(0,0,0, 1)'
}
}
core = null;
init() {
this.startLvl();
this.core.run();
}
startLvl() {
this.data.workspace['width'] = this.config.cells[0] * this.config.cellWidth;
this.data.workspace['height'] = this.config.cells[1] * this.config.cellWidth;
this.data.workspace['left'] = this.config.leftOffset + this.config.cellWidth;
this.data.workspace['top'] = this.config.topOffset + this.config.cellWidth;
this.data.workspace['right'] = this.data.workspace['left'] + this.data.workspace['width'];
this.data.workspace['bottom'] = this.data.workspace['top'] + this.data.workspace['height'];
//строим матрицу стакана
this.data.matrix = Array.from({
length: this.config.cells[0]
}, () => new Array(this.config.cells[1]).fill(null));
console.log(this.data.matrix)
this.drawInterface();
// тут просто для примера нарисовал. но в игре это должно быть по другому
// должны быть пресеты для каждого уровня
this.core.drawCellByPos({
position : [1, 1],
width : this.config.cellWidth,
color : 'red',
border : this.data.interface.borderColor,
});
this.core.drawCellByPos({
...