Skip to content

Commit

Permalink
added tube image to mario
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielFitzwilliam committed Nov 18, 2023
1 parent 8ef9a5e commit db4f392
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions assets/js/mario/player.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {platform} from "./platform.js"
import {tube} from "./tube.js"

// Get text element for Mario's health
let marioStateMessage = document.getElementById("Mario_State");
Expand Down Expand Up @@ -112,6 +113,7 @@ function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
platform.draw();
player.update();
tube.draw();
};
animate();
// Event listener for keydown events
Expand Down
25 changes: 25 additions & 0 deletions assets/js/mario/tube.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import{ctx} from "./player.js"

class Tube {
constructor(image) {
// Initial position of the tube
this.position = {
x: 500,
y: 180
};
this.image = image;
this.width = 100;
this.height = 120;
};
// Method to draw the tube on the canvas
draw() {
ctx.drawImage(this.image, this.position.x, this.position.y, this.width, this.height);
};
};

//Load image
let imageTube = new Image();
imageTube.src = 'https://samayass.github.io/samayaCSA/images/tube.png'
let tube = new Tube(imageTube);

export {tube}

0 comments on commit db4f392

Please sign in to comment.