(time = 0)
| 183 | let count = 0; |
| 184 | |
| 185 | function update(time = 0) { |
| 186 | |
| 187 | const dt = time - lastTime; |
| 188 | lastTime = time; |
| 189 | count += dt; |
| 190 | |
| 191 | if (count >= interval) { |
| 192 | player.pos.y++; |
| 193 | count = 0; |
| 194 | } |
| 195 | |
| 196 | if (collides(player, arena)) { |
| 197 | mergeArena(player.matrix, player.pos.x, player.pos.y-1); |
| 198 | clearBlocks(); |
| 199 | gameOver(); |
| 200 | |
| 201 | player.pos.y = 1; |
| 202 | player.pos.x = 0; |
| 203 | |
| 204 | rand = Math.floor(Math.random() * pieces.length); |
| 205 | player.matrix = pieces[rand]; |
| 206 | player.color = colors[rand+1]; |
| 207 | |
| 208 | interval = 1000; |
| 209 | } |
| 210 | |
| 211 | ctx.fillStyle = "#000"; |
| 212 | ctx.fillRect(0, 0, canvas.width, canvas.height); |
| 213 | |
| 214 | drawArena(); |
| 215 | ctx.fillStyle = player.color; |
| 216 | drawMatrix(player.matrix, player.pos.x, player.pos.y); |
| 217 | |
| 218 | requestAnimationFrame(update); |
| 219 | } |
| 220 | |
| 221 | document.addEventListener("keydown", event => { |
| 222 |
no test coverage detected