Hi! I have 2 cats that float around until they stop when they come into contact with each other, which I called catFight();. I want them to start floating around again normally every time ‘m’ is pressed. I’m new so processing so any basic solutions would be awesome!
Bombay b1;
Scottishfold sf1;
void setup() {
size(800, 600);
b1 = new Bombay();
sf1 = new Scottishfold();
}
void draw () {
background(30, 85, 147);
b1.display();
b1.moveBom();
b1.checkBomEdges();
sf1.display();
sf1.moveScot();
sf1.checkScotEdges();
catFight();
}
void catFight() {
if (((b1.bound2>sf1.bound1 && b1.bound2<sf1.bound2) || (b1.bound1>sf1.bound1 && b1.bound1<sf1.bound2)) && ((b1.bound4>sf1.bound4 && b1.bound4<sf1.bound3) || (b1.bound3>sf1.bound4 && b1.bound4<sf1.bound3))) {
//println("Fight");
b1.xSpeed=0;
b1.ySpeed=0;
sf1.xSpeed=0;
sf1.ySpeed=0;
}
}
class Bombay {
color bodyC1;
color bodyC2;
color bodyC3;
float x;
float y;
float xSpeed;
float ySpeed;
float bound1;
float bound2;
float bound3;
float bound4;
Bombay() {
this.bodyC1 = color (0);
this.bodyC2 = color (138);
this.bodyC3 = color (173);
this.x = 400;
this.y = 300;
this.xSpeed = -4;
this.ySpeed = 3;
this.bound1 = x-325;
this.bound2 = x-200;
this.bound3 = y-30;
this.bound4 = y-150;
}
void display() {
//leg 1
stroke(184);
fill(this.bodyC1);
beginShape();
vertex(this.x-250,this.y-70);
vertex(this.x-260,this.y-30);
vertex(this.x-280,this.y-70);
endShape(CLOSE);
//leg 2
beginShape();
vertex(this.x-250,this.y-90);
vertex(this.x-230,this.y-75);
vertex(this.x-245,this.y-30);
vertex(this.x-260,this.y-70);
endShape(CLOSE);
//tail
beginShape();
vertex(this.x-250,this.y-90);
vertex(this.x-210,this.y-60);
vertex(this.x-200,this.y-50);
vertex(this.x-225,this.y-60);
endShape(CLOSE);
//body 1
beginShape();
vertex(this.x-310,this.y-90);
vertex(this.x-250,this.y-90);
vertex(this.x-250,this.y-50);
vertex(this.x-290,this.y-50);
endShape(CLOSE);
// draw legs
// front leg 1
beginShape();
vertex(this.x-300, this.y-50);
vertex(this.x-310, this.y-30);
vertex(this.x-325, this.y-75);
vertex(this.x-300, this.y-100);
endShape(CLOSE);
//front leg 2
beginShape();
vertex(this.x-275, this.y-75);
vertex(this.x-285, this.y-30);
vertex(this.x-320, this.y-80);
endShape(CLOSE);
//body 4
beginShape();
vertex(this.x-300,this.y-125);
vertex(this.x-275, this.y-75);
vertex(this.x-300, this.y-50);
vertex(this.x-325, this.y-75);
endShape(CLOSE);
// draw head
// head 1
stroke(184);
fill(this.bodyC1);
beginShape();
vertex(this.x-287.5,this.y-135);
vertex(this.x-300,this.y-125);
vertex(this.x-312.5,this.y-135);
endShape(CLOSE);
// head 2
beginShape();
vertex(this.x-287.5, this.y-112.5);
vertex(this.x-312.5, this.y-112.5);
vertex(this.x-300, this.y-125);
endShape(CLOSE);
//head 3
beginShape();
vertex(this.x-287.5,this.y-135);
vertex(this.x-275, this.y-120);
vertex(this.x-287.5, this.y-112.5);
vertex(this.x-300, this.y-125);
endShape(CLOSE);
//left eye
fill(245,239,74);
ellipse(this.x-287,this.y-124,7,3);
fill(0);
circle(this.x-287,this.y-122,5);
// head 4
beginShape();
vertex(this.x-300, this.y-125);
vertex(this.x-312.5, this.y-112.5);
vertex(this.x-327, this.y-120);
vertex(this.x-312.5,this.y-135);
endShape(CLOSE);
//right eye
fill(245,239,74);
ellipse(this.x-312,this.y-124,7,3);
fill(0);
circle(this.x-312,this.y-122,5);
//head 5
beginShape();
vertex(this.x-312.5,this.y-135);
vertex(this.x-327, this.y-120);
vertex(this.x-327, this.y-150);
endShape(CLOSE);
//head 6
beginShape();
vertex(this.x-287.5,this.y-135);
vertex(this.x-275, this.y-150);
vertex(this.x-275, this.y-120);
endShape(CLOSE);
// head 7
beginShape();
vertex(this.x-287.5, this.y-112.5);
vertex(this.x-300, this.y-100);
vertex(this.x-312.5, this.y-112.5);
endShape(CLOSE);
}
void moveBom(){
x=x+xSpeed;
y+=ySpeed;
bound1+=xSpeed;
bound2+=xSpeed;
bound3+=ySpeed;
bound4+=ySpeed;
}
void checkBomEdges() {
if ((x-325<0) || (x-200>width)) {
xSpeed = xSpeed * -1;
}
if ((y-30>height) || (y-150<0)) {
ySpeed = ySpeed * -1;
}
}
}
class Scottishfold {
color bC1;
color bC2;
float x;
float y;
float xSpeed;
float ySpeed;
float bound1;
float bound2;
float bound3;
float bound4;
Scottishfold() {
this.bC1 = color (152,141,132);
this.bC2 = color (85,77,71);
this.x = 700;
this.y = 500;
this.xSpeed = -4;
this.ySpeed = 3;
this.bound1 = x-333;
this.bound2 = x-200;
this.bound3 = y-30;
this.bound4 = y-150;
}
void display() {
//leg 1
stroke(184);
fill(this.bC1);
beginShape();
vertex(this.x-250,this.y-70);
vertex(this.x-260,this.y-30);
vertex(this.x-280,this.y-70);
endShape(CLOSE);
//leg 2
beginShape();
vertex(this.x-250,this.y-90);
vertex(this.x-230,this.y-75);
vertex(this.x-245,this.y-30);
vertex(this.x-260,this.y-70);
endShape(CLOSE);
//tail
beginShape();
vertex(this.x-250,this.y-90);
vertex(this.x-210,this.y-60);
vertex(this.x-200,this.y-50);
vertex(this.x-225,this.y-60);
endShape(CLOSE);
//body 1
beginShape();
vertex(this.x-310,this.y-90);
vertex(this.x-250,this.y-90);
vertex(this.x-250,this.y-50);
vertex(this.x-290,this.y-50);
endShape(CLOSE);
// draw legs
// front leg 1
beginShape();
vertex(this.x-300,this.y-50);
vertex(this.x-310,this.y-30);
vertex(this.x-325,this.y-75);
vertex(this.x-300,this.y-100);
endShape(CLOSE);
//front leg 2
beginShape();
vertex(this.x-275,this.y-75);
vertex(this.x-285,this.y-30);
vertex(this.x-320,this.y-80);
endShape(CLOSE);
//body 4
beginShape();
vertex(this.x-300,this.y-125);
vertex(this.x-275,this.y-75);
vertex(this.x-300,this.y-50);
vertex(this.x-325,this.y-75);
endShape(CLOSE);
//draw head
//head 1
ellipse(this.x-300,this.y-115,42,34);
//left eye
fill(255,189,90);
circle(this.x-310,this.y-115,10);
fill(0);
circle(this.x-310,this.y-113,6);
//right eye
fill(255,189,90);
circle(this.x-290,this.y-115,10);
fill(0);
circle(this.x-290,this.y-113,6);
//left ear 1
fill(this.bC1);
beginShape();
vertex(this.x-312.5,this.y-128);
vertex(this.x-322,this.y-118);
vertex(this.x-327,this.y-135);
endShape(CLOSE);
//left ear 2
noStroke();
beginShape();
vertex(this.x-327,this.y-135);
vertex(this.x-333,this.y-128);
vertex(this.x-316,this.y-128);
endShape(CLOSE);
//right ear 1
stroke(184);
beginShape();
vertex(this.x-287.5,this.y-128);
vertex(this.x-278,this.y-118);
vertex(this.x-275,this.y-135);
endShape(CLOSE);
//right ear 2
noStroke();
beginShape();
vertex(this.x-275,this.y-135);
vertex(this.x-267,this.y-128);
vertex(this.x-280,this.y-125);
endShape(CLOSE);
}
void moveScot() {
x=x+xSpeed;
y+=ySpeed;
bound1+=xSpeed;
bound2+=xSpeed;
bound3+=ySpeed;
bound4+=ySpeed;
}
void checkScotEdges() {
if ((x-333<0) || (x-200>width)) {
xSpeed = xSpeed * -1;
}
if ((y-30>height) || (y-150<0)) {
ySpeed = ySpeed * -1;
}
}
}