From 2e345be0eae67f1176344f6a238cb82938a761b4 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Wed, 25 Mar 2020 19:19:02 +0100 Subject: [PATCH] Levels' background Some grass + finer grid --- script.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/script.js b/script.js index 49eba61..7dab706 100644 --- a/script.js +++ b/script.js @@ -73,6 +73,8 @@ const canvasTarget = byId("canvasTarget") const scoreTarget = byId("scoreTarget") // Get images +const imgGrass = new Image(); +imgGrass.src = './assets/grass.png'; const imgWall = new Image(); imgWall.src = './assets/wall.jpg'; const imgApple = new Image(); @@ -244,8 +246,13 @@ async function startGame(gameID) { // Redraw screen ctx.clearRect(0, 0, canvas.width, canvas.height) + let pattern = ctx.createPattern(imgGrass, 'repeat'); + ctx.fillStyle = pattern; + ctx.fillRect(0, 0, canvas.width, canvas.height); // First, draw the grid + ctx.lineWidth = 0.3; + for(let i = 0; i <= level.dimensions[1]; i++) { drawLine(ctx, i*cell_width, 0, i*cell_width, canvas.height) }