Fix play issues
This commit is contained in:
parent
21e1763e3d
commit
ccd4a2e328
@ -6,7 +6,12 @@
|
|||||||
],
|
],
|
||||||
"food": [
|
"food": [
|
||||||
[10,10],
|
[10,10],
|
||||||
[20, 20]
|
[11,10],
|
||||||
|
[12,10],
|
||||||
|
[20, 20],
|
||||||
|
[20, 22],
|
||||||
|
[20, 23],
|
||||||
|
[20, 21]
|
||||||
],
|
],
|
||||||
"snake": [
|
"snake": [
|
||||||
[4,2], [4,1], [3,1], [2,1]
|
[4,2], [4,1], [3,1], [2,1]
|
||||||
|
10
script.js
10
script.js
@ -152,7 +152,6 @@ async function startGame(gameID) {
|
|||||||
newHead[1]++;
|
newHead[1]++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(newHead[0] < 0 || newHead[1] < 0 ||
|
if(newHead[0] < 0 || newHead[1] < 0 ||
|
||||||
newHead[0] >= level.dimensions[0] || newHead[1] >= level.dimensions[1]) {
|
newHead[0] >= level.dimensions[0] || newHead[1] >= level.dimensions[1]) {
|
||||||
@ -167,6 +166,7 @@ async function startGame(gameID) {
|
|||||||
increaseSize = true;
|
increaseSize = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SNAKE:
|
||||||
case WALL:
|
case WALL:
|
||||||
gameOver();
|
gameOver();
|
||||||
break;
|
break;
|
||||||
@ -201,11 +201,11 @@ async function startGame(gameID) {
|
|||||||
|
|
||||||
|
|
||||||
// Now draw the map
|
// Now draw the map
|
||||||
for(let y = 1; y <= map.length; y++) {
|
for(let y = 0; y < map.length; y++) {
|
||||||
for(let x = 1; x <= map[y-1].length; x++) {
|
for(let x = 0; x < map[y].length; x++) {
|
||||||
|
|
||||||
// Adapt rendering to the element to display
|
// Adapt rendering to the element to display
|
||||||
switch(map[y-1][x-1]) {
|
switch(map[y][x]) {
|
||||||
|
|
||||||
case WALL:
|
case WALL:
|
||||||
ctx.fillStyle = "darkRed";
|
ctx.fillStyle = "darkRed";
|
||||||
@ -225,7 +225,7 @@ async function startGame(gameID) {
|
|||||||
// If it is the case, we draw an eye to the snake
|
// If it is the case, we draw an eye to the snake
|
||||||
const headPos = snake[snake.length-1];
|
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.fillStyle = "darkRed";
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.arc(
|
ctx.arc(
|
||||||
|
Loading…
Reference in New Issue
Block a user