xxxxxxxxxx
25
let sound;
let m1;
let playing;
function setup() {
createCanvas(600, 600);
m1 = new Monsters(width / 2, height / 2, 20);
playing = false;
sound = new Audio("footsteps.mp3");
}
function draw() {
background(0);
m1.show();
}
function mousePressed() {
if (m1.collision(mouseX, mouseY) && !playing) {
playing = true;
sound.play();
} else if (m1.collision(mouseX, mouseY) && playing) {
playing = false;
sound.pause();
}
}