From 86b992bbc1de37f00309483954ec3d3d617af165 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Fri, 27 Mar 2020 16:41:17 +0100 Subject: [PATCH] Grid around the snake head fixed --- script.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/script.js b/script.js index 7598de2..2accbff 100644 --- a/script.js +++ b/script.js @@ -295,9 +295,11 @@ async function startGame(gameID) { const headPos = snake[snake.length-1]; if(headPos[0] == y && headPos[1] == x) { - ctx.clearRect(x*cell_width, y*cell_height, cell_width, cell_height); - ctx.drawImage(imgGrass, x*cell_width, y*cell_height, cell_width, cell_height); + ctx.clearRect(x*cell_width+1, y*cell_height+1, cell_width-2, cell_height-2); + // Restore the background + ctx.drawImage(imgGrass, x*cell_width+1, y*cell_height+1, cell_width-2, cell_height-2); + // Head Orientation if(key == "ArrowDown") ctx.drawImage(imgSnakeHeadDown, x*cell_width, y*cell_height, cell_width, cell_height); if(key == "ArrowUp" || !key)