MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / update

Function update

assets/js/TetrisGame.js:185–219  ·  view source on GitHub ↗
(time = 0)

Source from the content-addressed store, hash-verified

183let count = 0;
184
185function 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
221document.addEventListener("keydown", event => {
222

Callers 1

TetrisGame.jsFile · 0.70

Calls 6

collidesFunction · 0.85
mergeArenaFunction · 0.85
clearBlocksFunction · 0.85
drawArenaFunction · 0.85
drawMatrixFunction · 0.85
gameOverFunction · 0.70

Tested by

no test coverage detected