diff --git a/assets/apple.png b/assets/apple.png new file mode 100644 index 0000000..b6ff438 Binary files /dev/null and b/assets/apple.png differ diff --git a/assets/wall.jpg b/assets/wall.jpg new file mode 100644 index 0000000..3c88363 Binary files /dev/null and b/assets/wall.jpg differ diff --git a/script.js b/script.js index 9587d33..49eba61 100644 --- a/script.js +++ b/script.js @@ -72,6 +72,12 @@ const stopGameBtn = byId("stopGameBtn") const canvasTarget = byId("canvasTarget") const scoreTarget = byId("scoreTarget") +// Get images +const imgWall = new Image(); +imgWall.src = './assets/wall.jpg'; +const imgApple = new Image(); +imgApple.src = './assets/apple.png'; + /** * Show main screen @@ -257,12 +263,12 @@ async function startGame(gameID) { case WALL: ctx.fillStyle = "darkRed"; - ctx.fillRect(x*cell_width, y*cell_height, cell_width, cell_height) + ctx.drawImage(imgWall, x*cell_width, y*cell_height, cell_width, cell_height); break; case FOOD: ctx.fillStyle = "darkGreen"; - ctx.fillRect(x*cell_width, y*cell_height, cell_width, cell_height) + ctx.drawImage(imgApple, x*cell_width, y*cell_height, cell_width, cell_height); break; case SNAKE: