From a54812ed50379bd8baacce53c16aeccdff752327 Mon Sep 17 00:00:00 2001 From: phat_sumo Date: Wed, 6 Apr 2022 18:26:03 -0600 Subject: convert hedge to grayscale, fix lava entity to use the new sprites, wordIs is pushable, dynamically color sprites --- src/render/graphics.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/render/graphics.js') diff --git a/src/render/graphics.js b/src/render/graphics.js index 6a199f0..8a4cb1c 100644 --- a/src/render/graphics.js +++ b/src/render/graphics.js @@ -6,7 +6,7 @@ game.graphics = ( context.clearRect(0, 0, game.canvas.width, game.canvas.height); }; - const Sprite = ({image, spriteX, spriteY, spriteWidth, spriteHeight, timePerFrame, cols, rows, numFrames, drawFunction}) => { + const Sprite = ({image, spriteX, spriteY, spriteWidth, spriteHeight, timePerFrame, cols, rows, numFrames, color, drawFunction}) => { timePerFrame = timePerFrame ?? 100; numFrames = numFrames ?? 1; cols = cols ?? numFrames; @@ -33,6 +33,15 @@ game.graphics = ( const row = currentFrame % rows; const col = Math.floor(currentFrame / rows); context.drawImage(image, spriteX+col*spriteWidth, spriteY+row*spriteHeight, spriteWidth, spriteHeight, x, y, width, height); + + // apply color to sprite + if (color) { + context.globalAlpha=0.7; + context.globalCompositeOperation="source-atop"; + context.fillStyle=color; + context.fillRect(x, y, width, height); + } + context.restore(); }; } else { @@ -43,4 +52,4 @@ game.graphics = ( return { clear, Sprite }; } -)(document.getElementById("game-canvas").getContext("2d")); \ No newline at end of file +)(document.getElementById("game-canvas").getContext("2d")); -- cgit v1.2.3-70-g09d2