xxxxxxxxxx
415
//sound
let ampl;
//SOUNDZ
let drone1;
let drone3;
let bubble1;
let bubble2;
let sliderb1
let blanket1;
let blanket2;
let mouse1;
let x = 0
let grab = false;
let grab1 = false;
let grabr1 = false;
let grabr2 = false;
let bp1;
let bp2;
let blanket1pic;
let blanket2pic;
let b1d = 100
let b2d = 100
//blanket 1 distance
function preload() {
drone1 = loadSound("sounds/drone1.mp3");
play1 = loadSound ("sounds/drone3.mp3");
bp1 = loadImage('pillowicon1.png')
bp2 = loadImage('bucket.png')
blanket1pic = loadImage('blanket1.png')
blanket2pic = loadImage('blanket2.png')
}
function setup() {
createCanvas(1000, 1000);
amp1 = new p5.Amplitude();
// drone1.play();
drone1.loop();
play1.loop();
bubble1 = new Bubble(200, 200, 15, 50, 50)
bubble2 = new Bubble(50, 100, 20, 90, 110)
mouse1 = new mouse()
blanket1 = new Bubble(200, 400, 40, 150, 190)
blanket2 = new Bubble(150, 100, 5, 180, 115)
}
function draw() {
b = dist(mouseX, mouseY, bubble1.x, bubble1.y)
b2 = dist(mouseX, mouseY, bubble2.x, bubble2.y)
// print(b2d)
background(100, x-50, 100)
x = mouseX
// }
//IN BLANKET 1
if (blanket1.inrect(bubble2)) {
background(100, 0, 250)
b1d = dist(blanket1.x, blanket1.y, bubble2.x -50 , bubble2.y -70);
}
else{ b1d =100}
if (blanket1.inrect(bubble1)) {
background(100, 0, 250)
b1d = dist(blanket1.x, blanket1.y, bubble1.x , bubble1.y );
}
// print (b1d)
b1vol = map(b1d, 0, 220^2, 1, 0)
// print(b1vol)
if (blanket1.inrect(bubble2)||blanket1.inrect(bubble1)) {
background(0, 0, 250)
drone1.setVolume(b1vol);
} else {
drone1.setVolume(0);
}
// IN BLANKET 2
if (blanket2.inrect(bubble1)) {
b2d=
dist(blanket2.x, blanket2.y, bubble1.x -50 , bubble1.y -100);
}
if (blanket2.inrect(bubble2)) {
b2d=
dist(blanket2.x, blanket2.y, bubble2.x -50 , bubble2.y -100 );
}
b2vol = map(b2d, 0, 220^2, 1, 0)
if (blanket2.inrect(bubble2)||blanket2.inrect(bubble1)) {
background(100, 0, 250)
play1.setVolume(b2vol);
} else {
play1.setVolume(0);
}
// print(b2d)
if (bubble1.intersects(bubble2)) {
background(200, 0, 100)
}
if (bubble1.intersects(bubble2)) {
background(200, 0, 100)
}
//CLASSS COMMANDZ
// blanket1.showrect()
blanket1.blanket1pic()
blanket1.inrect(mouse1)
// blanket2.showrect()
blanket2.inrect(mouse1)
blanket2.blanket2pic()
bubble1.bp2();
// bubble1.show();
// bubble1.move();
bubble1.move2();
bubble2.show();
bubble2.bp1();
//
bubble2.move();
// bubble2.x = mouseX;
// bubble2.y = mouseY;
//GRABBING !
if (grab) {
bubble1.x = mouseX
}
if (grab) {
bubble1.y = mouseY
}
if (grab1) {
bubble2.x = mouseX
}
if (grab1) {
bubble2.y = mouseY
}
//grabbing Rectangles
if (grabr1) {
blanket1.x = mouseX - 60
}
if (grabr1) {
blanket1.y = mouseY - 90
}
if (grabr2) {
blanket2.x = mouseX - 90
}
if (grabr2) {
blanket2.y = mouseY - 60
}
// if (mouseIsPressed&&b < bubble2.r){
// grab = true
// }
// else { grab = false
// }
// if (mouseIsPressed&&b2 < bubble2.r) {
// grab1 = true
// }
// else{ grab1=false
// }
if (mouseIsPressed && b > bubble1.r&&b2 > bubble2.r &&
mouseX >= blanket1.x && mouseY >= blanket1.y && mouseX <= blanket1.x + blanket1.w && mouseY <= blanket1.h + blanket1.y) {
grabr1 = true
} else {
grabr1 = false
}
if (mouseIsPressed && b > bubble1.r&&b2 > bubble2.r&&
mouseX >= blanket2.x && mouseY >= blanket2.y && mouseX <= blanket2.x + blanket2.w && mouseY <= blanket2.h + blanket2.y) {
grabr2 = true
} else {
grabr2 = false
}
// let vol = amp1.getLevel();
// fill(255, 0, 255)
// ellipse(140, 400, vol, 100)
}
function mousePressed() {
if (b < bubble1.r) {
grab = !grab;
}
if (b2 < bubble2.r) {
grab1 = !grab1;
}
// NO BUBBLES/buckkets : b > bubble1.r&&b2 > bubble2.r
// if (grab) {
// bubble1.x = mouseX
// }
// if (grab) {
// bubble1.y = mouseY
// }
// if (grab1) {
// bubble2.x = mouseX
// }
// if (grab1) {
// bubble2.y = mouseY
// if (grabr1) {
// blanket1.x = mouseX
// }
// if (grabr1) {
// blanket1.y = mouseY
}
class mouse {
constructor(x, y) {
this.x = mouseX
this.y = mouseY
}
}
class Bubble {
constructor(x, y, r = 15, w, h, ) {
this.x = x;
this.y = y;
this.r = r;
this.w = w;
this.h = h;
this.brightness = 0
}
changeColor(bright) {
this.brightness = bright;
}
contains(px, py) {
let d = dist(px, py, this.x, this.y);
if (d < this.r) {
return true;
} else {
return false;
}
}
move() {
this.x = this.x + random(-2, 2);
}
move2() {
this.x = this.x + random(-.5, .5);
this.y = this.y + random(-.5, .5);
}
//inside functions
intersects(other) {
let d = dist(this.x, this.y, other.x, other.y);
return (d < this.r + other.r);
// if (d < this.r +this.r) {
// return true;
// }else{
// return false;
// }
}
inrect(other) {
return (other.x > this.x && other.y > this.y && other.x < this.x + this.w && other.y < this.h + this.y)
}
//show functions
show() {
stroke(255)
fill(this.brightness, 125);
ellipse(this.x, this.y, this.r * 2)
}
showrect() {
noFill();
noStroke();
stroke(250);
rect(this.x, this.y, this.w, this.h, 10);
}
blanket1pic() {
image(blanket1pic, this.x, this.y, this.w, this.h);
}
blanket2pic() {
image(blanket2pic, this.x, this.y, this.w, this.h);
}
bp1() {
image(bp1, this.x - 40, this.y - 50, this.w, this.h);
}
bp2() {
image(bp2, this.x -20, this.y - 20, this.w, this.h);
}
}