xxxxxxxxxx
let div;
let juiceboxes = []
let title;
let font;
function preload() {
g = loadImage('0.png');
ggif = loadImage("juicebox.gif")
s = loadImage("sushi.png")
sgif = loadImage("sushi-small.gif")
font = loadFont('Silkscreen-Bold.ttf')
}
function setup() {
background('#e35153')
createCanvas(windowWidth, windowHeight);
textFont(font)
// div = createDiv('Juicebox Collective').size(width/2, height/2);
// div.style('background-color', '#e35153');
// div.center();
//textWrap(WORD);
let bbox = font.textBounds('JUICEBOX COLLECTIVE', 0, 0, 60);
title = new Sprite();
title.width = bbox.w;
title.heigth = bbox.h;
title.textSize = 60;
title.text = "Juicebox collective"
title.collider = 'static'
juiceboxes.push(new Juicebox(true));
juiceboxes.push(new Juicebox(false));
juiceboxes.push(new Juicebox(true));
juiceboxes.push(new Juicebox(true));
juiceboxes.push(new Juicebox(false));
juiceboxes.push(new Juicebox(false));
}
function draw() {
//background('#e35153')
juiceboxes.forEach((j) => {
j.checks();
})
}
function mouseClicked(){
juiceboxes.push(new Juicebox(random([true, false])));
}
class Juicebox {
constructor(sel) {
this.sp = new Sprite(random(width), random(height), 300, 300);
this.sp.collider = 'dynamic';
this.sp.scale = 0.2;
this.sp.vel.x = random(-7, 7);
this.sp.vel.y = random(-7, 7);
this.frames = 0;
this.collided = false;
if (sel) {
this.img = g;
this.gif = ggif;
} else {
this.img = s;
this.gif = sgif;
}
this.sp.img = this.img;
}
checks() {
if (this.sp.vel.x < 0) {
this.sp.mirror.x = false;
} else this.sp.mirror.x = true;
if (this.sp.x < 0 || this.sp.x > width) {
this.sp.vel.x *= -1;
}
if (this.sp.y < 0 || this.sp.y > height) {
this.sp.vel.y *= -1;
}
juiceboxes.forEach((j) => {
if (this.sp.collides(j.sp)) {
this.sp.img = this.gif;
this.collided = true;
}
if (this.collided && this.frames == 500) {
this.sp.img = this.img;
this.collided = false;
this.frames = 0;
} else if (this.collided) this.frames++;
})
}
}