Snake Head Orientation

This commit is contained in:
Mathieu 2020-03-27 16:17:15 +01:00
parent a7a45e5874
commit 655008ee68
6 changed files with 19 additions and 4 deletions

View File

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

View File

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

@ -79,10 +79,17 @@ const imgWall = new Image();
imgWall.src = './assets/wall.jpg';
const imgApple = new Image();
imgApple.src = './assets/apple.png';
const imgSnakeHead = new Image();
imgSnakeHead.src = './assets/snake_head.png';
let imgSnakeHeadUp = new Image();
imgSnakeHeadUp.src = './assets/snake/snake_head_up.png';
let imgSnakeHeadLeft = new Image();
imgSnakeHeadLeft.src = './assets/snake/snake_head_left.png';
let imgSnakeHeadRight = new Image();
imgSnakeHeadRight.src = './assets/snake/snake_head_right.png';
let imgSnakeHeadDown = new Image();
imgSnakeHeadDown.src = './assets/snake/snake_head_down.png';
const imgSnakeBody = new Image();
imgSnakeBody.src = './assets/snake_body.png';
imgSnakeBody.src = './assets/snake/snake_body.png';
/**
@ -290,7 +297,15 @@ async function startGame(gameID) {
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.drawImage(imgSnakeHead, x*cell_width, y*cell_height, cell_width, cell_height);
if(key == "ArrowDown")
ctx.drawImage(imgSnakeHeadDown, x*cell_width, y*cell_height, cell_width, cell_height);
if(key == "ArrowUp" || !key)
ctx.drawImage(imgSnakeHeadUp, x*cell_width, y*cell_height, cell_width, cell_height);
if(key == "ArrowLeft")
ctx.drawImage(imgSnakeHeadLeft, x*cell_width, y*cell_height, cell_width, cell_height);
if(key == "ArrowRight")
ctx.drawImage(imgSnakeHeadRight, x*cell_width, y*cell_height, cell_width, cell_height);
}
break;