Levels' background

Some grass + finer grid
This commit is contained in:
Mathieu 2020-03-25 19:19:02 +01:00
parent 278d13cfa1
commit 2e345be0ea

View File

@ -73,6 +73,8 @@ const canvasTarget = byId("canvasTarget")
const scoreTarget = byId("scoreTarget") const scoreTarget = byId("scoreTarget")
// Get images // Get images
const imgGrass = new Image();
imgGrass.src = './assets/grass.png';
const imgWall = new Image(); const imgWall = new Image();
imgWall.src = './assets/wall.jpg'; imgWall.src = './assets/wall.jpg';
const imgApple = new Image(); const imgApple = new Image();
@ -244,8 +246,13 @@ async function startGame(gameID) {
// Redraw screen // Redraw screen
ctx.clearRect(0, 0, canvas.width, canvas.height) 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 // First, draw the grid
ctx.lineWidth = 0.3;
for(let i = 0; i <= level.dimensions[1]; i++) { for(let i = 0; i <= level.dimensions[1]; i++) {
drawLine(ctx, i*cell_width, 0, i*cell_width, canvas.height) drawLine(ctx, i*cell_width, 0, i*cell_width, canvas.height)
} }