Fix play issues

This commit is contained in:
Pierre HUBERT 2020-03-23 15:43:33 +01:00
parent 21e1763e3d
commit ccd4a2e328
2 changed files with 11 additions and 6 deletions

View File

@ -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]

View File

@ -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(