From ccd4a2e328b0a596b25ab86c24b7e79220e3bd81 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Mon, 23 Mar 2020 15:43:33 +0100 Subject: [PATCH] Fix play issues --- levels/1.json | 7 ++++++- script.js | 10 +++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/levels/1.json b/levels/1.json index a226939..b656af7 100644 --- a/levels/1.json +++ b/levels/1.json @@ -6,7 +6,12 @@ ], "food": [ [10,10], - [20, 20] + [11,10], + [12,10], + [20, 20], + [20, 22], + [20, 23], + [20, 21] ], "snake": [ [4,2], [4,1], [3,1], [2,1] diff --git a/script.js b/script.js index e8f3986..792fb04 100644 --- a/script.js +++ b/script.js @@ -152,7 +152,6 @@ async function startGame(gameID) { newHead[1]++; break; } - if(newHead[0] < 0 || newHead[1] < 0 || newHead[0] >= level.dimensions[0] || newHead[1] >= level.dimensions[1]) { @@ -167,6 +166,7 @@ async function startGame(gameID) { increaseSize = true; break; + case SNAKE: case WALL: gameOver(); break; @@ -201,11 +201,11 @@ async function startGame(gameID) { // Now draw the map - for(let y = 1; y <= map.length; y++) { - for(let x = 1; x <= map[y-1].length; x++) { + for(let y = 0; y < map.length; y++) { + for(let x = 0; x < map[y].length; x++) { // Adapt rendering to the element to display - switch(map[y-1][x-1]) { + switch(map[y][x]) { case WALL: ctx.fillStyle = "darkRed"; @@ -225,7 +225,7 @@ async function startGame(gameID) { // If it is the case, we draw an eye to the snake const headPos = snake[snake.length-1]; - if(headPos[0] == y-1 && headPos[1] == x-1) { + if(headPos[0] == y && headPos[1] == x) { ctx.fillStyle = "darkRed"; ctx.beginPath(); ctx.arc(