Snake Head Orientation
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 52 KiB |
BIN
assets/snake/snake_head_left.png
Normal file
After Width: | Height: | Size: 55 KiB |
BIN
assets/snake/snake_head_right.png
Normal file
After Width: | Height: | Size: 54 KiB |
BIN
assets/snake/snake_head_up.png
Normal file
After Width: | Height: | Size: 54 KiB |
23
script.js
@ -79,10 +79,17 @@ const imgWall = new Image();
|
|||||||
imgWall.src = './assets/wall.jpg';
|
imgWall.src = './assets/wall.jpg';
|
||||||
const imgApple = new Image();
|
const imgApple = new Image();
|
||||||
imgApple.src = './assets/apple.png';
|
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();
|
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) {
|
if(headPos[0] == y && headPos[1] == x) {
|
||||||
ctx.clearRect(x*cell_width, y*cell_height, cell_width, cell_height);
|
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(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;
|
break;
|
||||||
|