Hi,
I’m making a click and point type of game. I want to sort fishes by their color. I want to remove the blue fishes from the big aquarium and “store” them for further use in the small aquarium.
I putting here what I’ve done so far. I can click on the pink fishes and make them disappear. But it ist not what I want to do and I can’t find the way to do it for the blue ones.
Here is my code :
let aquarium;
let inventaireblue;
let fishs = [];
let fishblue1;
let fishblue2;
function setup() {
createCanvas(1200, 700);
inventaireblue = new Inventaire(1060, 150, 150);
aquarium = new Aquarium(600, 350, 650);
for (let i = 0; i < 10; i++) {
let x = random(500, 700);
let y = random(200, 500);
let xspeed = random(1, 3);
let yspeed = random(1, 3);
let rbody = 100;
let fscale = random(0.6, 0.8);
fishs[i] = new Fish(x, y, rbody, color(255, 0, 204), xspeed, yspeed, fscale);
}
fishblue1 = new Fish(random(500, 700), random(200, 500), 100, color(51, 153, 255), random(1, 3), random(1, 3), random(0.6, 0.8));
fishblue2 = new Fish(random(500, 700), random(200, 500), 100, color(51, 153, 255), random(1, 3), random(1, 3), random(0.6, 0.8));
}
function mousePressed() {
for (let i = fishs.length - 1; i >= 0; i--) {
if (fishs[i].inside(mouseX, mouseY)) {
fishs.splice(i, 1);
}
}
}
function draw() {
inventaireblue.show();
aquarium.show();
//Fishes that stay in the aquarium
for (let i = 0; i < fishs.length; i++) {
push();
fishs[i].move();
fishs[i].show();
pop();
}
//Fisches that go into the Inventory
//Fish blue #1
if (fishblue1.inside(mouseX, mouseY)){
fishblue1.changeColor(color(10, 150, 30));
}else {
fishblue1.changeColor(color(51, 153, 255));
}
push();
fishblue1.show();
fishblue1.move();
pop();
//Fish blue #2
if (fishblue2.inside(mouseX, mouseY)){
fishblue2.changeColor(color(10, 150, 30));
}else {
fishblue2.changeColor(color(51, 153, 255));
}
push();
fishblue2.show();
fishblue2.move();
pop();
}
//INVENTORY
class Inventaire {
constructor(tempX, tempY, tempR) {
this.x = tempX;
this.y = tempY;
this.r = tempR;
}
show() {
fill(171, 252, 255);
stroke(51, 153, 255);
strokeWeight(10);
ellipse(this.x, this.y, this.r);
}
}
//AQUARIUM
class Aquarium {
constructor(tempX, tempY, tempR) {
this.x = tempX;
this.y = tempY;
this.r = tempR;
}
show() {
fill(171, 252, 255);
stroke(255, 0, 204);
strokeWeight(20);
ellipse(this.x, this.y, this.r);
}
}
//FISH
class Fish {
constructor(tempX, tempY, tempRbody, tempColor, tempXspeed, tempYspeed, tempScale) {
this.x = tempX;
this.y = tempY;
this.color = tempColor;
this.xspeed = tempXspeed;
this.yspeed = tempYspeed;
this.rbody = tempRbody;
this.fscale = tempScale;
this.unsorted = true;
}
inside(px, py) {
let d = dist(px, py, this.x, this.y);
if (d < 50) {
return true;
} else {
return false;
}
}
changeColor(Color2) {
this.color = Color2;
}
changeSide() {
if (this.xspeed > 0) {
scale (this.scale = 5, this.scale);
}
}
move() {
let d2 = dist(this.x, this.y, aquarium.x, aquarium.y);
if (d2 > 200 || this.y < 200) {
this.xspeed = this.xspeed * -1;
this.yspeed = this.yspeed * -1;
}
this.x = this.x + this.xspeed;
this.y = this.y + this.yspeed;
}
show() {
//corps droite
if (this.xspeed > 0) {
translate(this.x, this.y);
scale(this.fscale);
fill(this.color);
stroke(0);
strokeWeight(3);
ellipse(0, 0, 100, 100);
//queue
triangle(- 50, 0, - 100, - 50, 0 - 100, 50);
//aileron
triangle(0, 10, 5, 30, - 30, 30);
//yeux
fill(255);
ellipse(15, - 10, 30, 30);
fill(0);
ellipse(15, - 10, 15, 15);
} else {
//corps gauche
translate(this.x, this.y);
scale(this.fscale);
fill(this.color);
stroke(0);
strokeWeight(3);
ellipse(0, 0, 100, 100);
//queue
triangle(50, 0, 100, - 50, 100, 50);
//aileron
triangle(0, 10, - 5, 30, 30, 30);
//yeux
fill(255);
ellipse(- 15, - 10, 30, 30);
fill(0);
ellipse(- 15, - 10, 15, 15);
}
}
}