diff --git a/script.js b/script.js index 9f17325..f793aaf 100644 --- a/script.js +++ b/script.js @@ -333,6 +333,8 @@ async function startGame(gameID) { ctx.fillStyle = "white"; ctx.fillRect(x*cell_width, y*cell_height, cell_width, cell_height) + // If the snake is on the cell, we must render it too. + // That's why I put a condition to this break if(map[y][x] == ICE) break; @@ -401,8 +403,15 @@ async function startGame(gameID) { document.body.addEventListener("keydown", (ev) => { if(!canvas.isConnected) return; - if(["ArrowDown", "ArrowLeft", "ArrowRight", "ArrowUp"].includes(ev.key)) + if(["ArrowDown", "ArrowLeft", "ArrowRight", "ArrowUp"].includes(ev.key)) { + + // Check if the snake is on some ice + const headPos = snake[snake.length-1]; + if(map[headPos[0]][headPos[1]] == ICE_SNAKE) + return; + key = ev.key; + } if(ev.key == "p") { audioEl.pause()