Javascript 如何在删除俄罗斯方块前制作完整的俄罗斯方块行闪光灯?
所以我正在做一个俄罗斯方块游戏,到目前为止,它几乎是完整的,除了我不能跟踪当前的分数或高分。如果您完成了一行,该行将被删除。但是,我想在删除行之前给它添加一个好的效果。我希望所有完成的行以黑白闪烁1s。我尝试设置一个间隔,使用for循环来更改行中的所有颜色。但是它不工作,因为游戏引擎在一个时间间隔内运行,所以在另一个时间间隔结束之前调用它。有什么想法吗Javascript 如何在删除俄罗斯方块前制作完整的俄罗斯方块行闪光灯?,javascript,Javascript,所以我正在做一个俄罗斯方块游戏,到目前为止,它几乎是完整的,除了我不能跟踪当前的分数或高分。如果您完成了一行,该行将被删除。但是,我想在删除行之前给它添加一个好的效果。我希望所有完成的行以黑白闪烁1s。我尝试设置一个间隔,使用for循环来更改行中的所有颜色。但是它不工作,因为游戏引擎在一个时间间隔内运行,所以在另一个时间间隔结束之前调用它。有什么想法吗 const J=[[1,0,0], [1, 1, 1], [0, 0, 0]], [[0, 1, 1], [0, 1, 0], [0, 1,
const J=[[1,0,0],
[1, 1, 1],
[0, 0, 0]],
[[0, 1, 1],
[0, 1, 0],
[0, 1, 0]],
[[0, 0, 0],
[1, 1, 1],
[0, 0, 1]],
[[0, 0, 1],
[0, 0, 1],
[0, 1, 1]]]
常数L=[[0,0,1],
[1, 1, 1],
[0, 0, 0]],
[[0, 1, 0],
[0, 1, 0],
[0, 1, 1]],
[[0, 0, 0],
[1, 1, 1],
[1, 0, 0]],
[[1, 1, 0],
[0, 1, 0],
[0, 1, 0]]]
常数O=[[1,1],
[1, 1]],
[[1, 1],
[1, 1]],
[[1, 1],
[1, 1]],
[[1, 1],
[1, 1]]]
常数I=[[0,0,0,0],
[1, 1, 1, 1],
[0, 0, 0, 0],
[0, 0, 0, 0]],
[[0, 0, 1, 0],
[0, 0, 1, 0],
[0, 0, 1, 0],
[0, 0, 1, 0]],
[[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[1, 1, 1, 1]],
[[0, 1, 0, 0],
[0, 1, 0, 0],
[0, 1, 0, 0],
[0, 1, 0, 0]]]
常数S=[[0,1,1],
[1, 1, 0],
[0, 0, 0]],
[[0, 1, 0],
[0, 1, 1],
[0, 0, 1]],
[[0, 0, 0],
[0, 1, 1],
[1, 1, 0]],
[[1, 0, 0],
[1, 1, 0],
[0, 1, 0]]]
常数T=[[0,1,0],
[1, 1, 1],
[0, 0, 0]],
[[0, 1, 0],
[0, 1, 1],
[0, 1, 0]],
[[0, 0, 0],
[1, 1, 1],
[0, 1, 0]],
[[0, 1, 0],
[1, 1, 0],
[0, 1, 0]]]
常数Z=[[1,1,0],
[0, 1, 1],
[0, 0, 0]],
[[0, 0, 1],
[0, 1, 1],
[0, 1, 0]],
[[0, 0, 0],
[1, 1, 0],
[0, 1, 1]],
[[0, 1, 0],
[1, 1, 0],
[1, 0, 0]]]
常数col=10;
常量行=20;
const emptue=“黑色”;
const cvs=document.querySelector(“画布”);
const ctx=cvs.getContext('2d');
常数sq=35;
//从blocks.js收集块并指定颜色
常数块=[[J,'蓝色']],
[L,‘橙色’],
[O,‘黄色’],
[I,‘青色’],
[S,‘limegreen’],
[T,‘紫色’],
[Z,‘红色’]]
让董事会=[];
for(设r=0;r=col | | newY>=row)返回true;
如果(董事会[newY][newX]!=空缺)返回true;
}
}
返回false;
}
}
函数newBlock(){
设r=Math.floor(Math.r
let dropStart = Date.now();
let hlStart = null;
function drop() {
let now = Date.now();
let delta = now - dropStart;
if(delta > 800) {
dropStart = Date.now();
block.moveDown();
}
if(hlStart) {
let hlDelta = Date.now() - hlStart;
if (hlDelta > 600) {
hlStart = null;
checkForPoints();
}
}
requestAnimationFrame(drop);
}
function checkForPoints() {
let newRows = [];
let changed = false;
for(let r = 0; r < board.length; r++) {
// if the row has already been highlighted
// then this time we can remove it
if(board[r].every(isHighlight)) {
for(let c = 0; c < col; c++) {
newRows.unshift(vacant);
}
board.splice(r, 1);
board.unshift(newRows);
changed = true;
}
// Only check for notVacant if the row is not highlighted.
else if(board[r].every(notVacant)) {
for(let c = 0; c < col; c++) {
board[r][c] = highlight;
}
// record the start time for the highlight animation
hlStart = Date.now();
changed = true;
}
}
// because multiple rows could be affected at the same time, moved
// redraw out to a single call for each whole board pass
if (changed)
redraw();
function notVacant(sq) {
if(sq !== vacant) return true;
else return false;
}
function isHighlight(sq) {
if(sq === highlight) return true;
else return false;
}
function redraw() {
for(let r = 0; r < row; r++) {
for(let c = 0; c < col; c++) {
draw(c, r, board[r][c]);
}
}
}
}