(currentTime)
| 7 | const gameBoard = document.getElementById('game-board') |
| 8 | |
| 9 | function main(currentTime) { |
| 10 | if (gameOver) { |
| 11 | if (confirm('You lost. Press ok to restart.')) { |
| 12 | window.location = '/' |
| 13 | } |
| 14 | return |
| 15 | } |
| 16 | |
| 17 | |
| 18 | window.requestAnimationFrame(main) |
| 19 | const secondsSinceLastRender = (currentTime - lastRenderTime) / 1000 |
| 20 | if (secondsSinceLastRender < 1 / SNAKE_SPEED) return |
| 21 | |
| 22 | |
| 23 | lastRenderTime = currentTime |
| 24 | |
| 25 | update() |
| 26 | draw() |
| 27 | } |
| 28 | |
| 29 | window.requestAnimationFrame(main) |
| 30 |