xxxxxxxxxx
97
//bacteria image by https://www.flaticon.com/br/autores/smashiconsSmashicons from flaticon.com
let bacteria;
let bubbles = [];
let finish = false;
function preload(){
bacteria = loadImage('bacterias.png');
}
function setup() {
createCanvas(1250, 940);
}
function mousePressed(){
if(finish === true) bubbles.splice(0, 1);
finish = false;
for(let i = 0; i < 50; i++){
let b = new Bubble(random(width), random(height), random(20, 40), bacteria, bubbles.length + 1);
bubbles.push(b);
}
}
function testFinish(biggest){
if(bubbles[biggest]){
if(bubbles[biggest].score > 1000){
finish = true;
bubbles[0] = bubbles[biggest];
}
}
}
function checksBubbles(bubble, bubble2){
let smallest = 0;
let biggest = 0;
if(bubble != bubble2){
if(bubble.intersects(bubble2.x, bubble2.y)){
if(bubble.d > bubble2.d){
smallest = bubbles.indexOf(bubble2);
biggest = bubbles.indexOf(bubble);
}else{
smallest = bubbles.indexOf(bubble);
biggest = bubbles.indexOf(bubble2)
}
if(bubbles[biggest] && bubbles[smallest]){
bubbles[biggest].d += bubbles[smallest].d / 2;
bubbles[biggest].score += ceil(bubbles[smallest].d / 2);
bubbles[biggest].eatedBalls++;
bubbles.splice(smallest, 1);
testFinish(biggest);
}
}
}
if(bubbles.length === 1) finish = true;
}
function winner(score, eatedBalls, n){
let text1 = `We have a survivor!!
The Bacteria nº ${n} ate ${eatedBalls} enemies
and finished with ${score} score points!!`;
textSize(60);
textAlign(CENTER);
noStroke();
fill(255);
text(text1, width / 2, height / 2);
}
function quantityOfBubbles(){
let text1 = bubbles.length + " bacterias on the screen";
fill(235, 100, 200, 70);
rect(10, 10, 420, 40);
textSize(30);
textAlign(LEFT);
textStyle(BOLD);
noStroke();
fill(255);
text(text1, 20, 40);
}
function draw() {
background(0);
if(finish) winner(bubbles[0].score, bubbles[0].eatedBalls, bubbles[0].n);
else{
for(let bubble of bubbles){
//Stalker(bubble, bubbles);
bubble.move();
bubble.show();
for(let bubble2 of bubbles){
checksBubbles(bubble, bubble2);
}
}
quantityOfBubbles();
}
}