From 569669da195d572f6a03e4e200fee25bb64f8369 Mon Sep 17 00:00:00 2001 From: elioat Date: Mon, 30 Oct 2023 17:10:18 -0400 Subject: * --- js/canvas/chickadee.png | Bin 0 -> 189 bytes js/canvas/chickadee.svg | 259 ++++++++++++++++++++++++++++++++++++++++++++++++ js/canvas/game.js | 16 ++- 3 files changed, 270 insertions(+), 5 deletions(-) create mode 100644 js/canvas/chickadee.png create mode 100644 js/canvas/chickadee.svg diff --git a/js/canvas/chickadee.png b/js/canvas/chickadee.png new file mode 100644 index 0000000..2a0c5ce Binary files /dev/null and b/js/canvas/chickadee.png differ diff --git a/js/canvas/chickadee.svg b/js/canvas/chickadee.svg new file mode 100644 index 0000000..faf7be4 --- /dev/null +++ b/js/canvas/chickadee.svg @@ -0,0 +1,259 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/js/canvas/game.js b/js/canvas/game.js index 24f0296..2929f01 100644 --- a/js/canvas/game.js +++ b/js/canvas/game.js @@ -6,17 +6,22 @@ const ctx = canvas.getContext("2d"); ctx.fillStyle = "#e0f8cf"; ctx.fillRect(0, 0, canvas.width, canvas.height); + // our noble avatar into playspace const player = { x: 50, y: 50, - width: 16, - height: 16, - step: 12, + width: 22, + height: 22, + step: 10, color: "#65ff00", - colorAlt: "pink" + colorAlt: "pink", + spriteUrl: "chickadee.svg" }; +const playerSprite = new Image(); +playerSprite.src = player.spriteUrl; + // add keyboard input // FIXME: this input is blocking, allowing for only 1 key to be read at a time // this means that if you wanna do 2 things at 1 time you cannot. @@ -77,7 +82,8 @@ function gameLoop() { // draw ctx.fillStyle = player.color; - ctx.fillRect(player.x, player.y, player.width, player.height); + ctx.fillRect(player.x, player.y, player.width, player.height); + ctx.drawImage(playerSprite, player.x, player.y, player.width, player.height); // next frame requestAnimationFrame(gameLoop); -- cgit 1.4.1-2-gfad0