Make the ice "live"

This commit is contained in:
Pierre HUBERT 2020-03-29 17:05:54 +02:00
parent b84dff7f79
commit b7f1dbf148

View File

@ -333,6 +333,8 @@ async function startGame(gameID) {
ctx.fillStyle = "white"; ctx.fillStyle = "white";
ctx.fillRect(x*cell_width, y*cell_height, cell_width, cell_height) 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) if(map[y][x] == ICE)
break; break;
@ -401,8 +403,15 @@ async function startGame(gameID) {
document.body.addEventListener("keydown", (ev) => { document.body.addEventListener("keydown", (ev) => {
if(!canvas.isConnected) if(!canvas.isConnected)
return; 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; key = ev.key;
}
if(ev.key == "p") { if(ev.key == "p") {
audioEl.pause() audioEl.pause()