xxxxxxxxxx
82
/*
sound example
4/8/2024
sounds used
https://freesound.org/people/JarredGibb/sounds/233096/
https://freemusicarchive.org/genre/Classical/
https://jfxr.frozenfractal.com/
*/
var bgMusic;
var chickenSound;
var jumpSound;
var x = 200;
var y = 200;
var s = 100;
function preload() {
bgMusic = loadSound("chopin.mp3");
chickenSound = loadSound("chicken.wav");
jumpSound = loadSound("jump.wav");
}
function keyPressed() {
if (keyCode == 32) {
// spacebar
if (bgMusic.isPlaying()) {
bgMusic.pause();
} else {
bgMusic.play();
}
}
if (keyCode == 65) {
// "a"
chickenSound.play();
}
if (keyCode == 66) { // b
jumpSound.play();
}
}
function setup() {
createCanvas(400, 400);
chickenSound.playMode("restart");
}
function draw() {
background(220);
if (bgMusic.isPlaying()) {
background("pink");
}
var v = map(mouseY, 0, height, 1, 0, true);
bgMusic.setVolume(v);
var r = map(mouseX, 0, width, 0.1, 3, true);
bgMusic.rate(r);
// chicken
noStroke();
fill("yellow");
circle(x, y, 200);
circle(x - 100, y - 100, 100);
if (chickenSound.isPlaying()) {
fill("red");
triangle(x - 100, y - 100, x - 150, y - 100, x - 150, y - 50);
}
if (jumpSound.isPlaying()) {
y -= 5;
} else {
y = 200;
}
}