I am working on a school project and I am having trouble creating multiple enemies form one class. when I create an two enemies from the same class and when one gets hit they all disappear can someone help please.
here is my code
float X,Y,Xc,Yc,Xm,Ym,Xl,Xr,Yt,Yb;
float H1,H2,H3,H1x,H1y,Ev;
float Hbar=3;
float Pdamx=100*width/1000, pdamy=100*height/1000;
color H1G, H1B;
int EM =1;
int EMi =1;
void setup(){
H1G= color(255,0,0,255);
H1B = color(0,0,0,0);
Ev=255;
size(1000,1000);
X=2;Y=2;Yc=500*height/1000;Xc=500*width/1000;Xl=300*width/1000;Xr=700*width/1000;Yt=700*height/1000;Yb=300*height/1000;
}
void draw(){
enamy E1= new enamy(300,700);
enamy E3= new enamy(300,300);
enamy2 E2= new enamy2(700,700);
background(150);
rectMode(CENTER);
if(X==2){Xm=Xc;}
if(X==1){Xm=Xl;}
if(X==3){Xm=Xr;}
if(Y==2){Ym=Yc;}
if(Y==1){Ym=Yb;}
if(Y==3){Ym=Yt;}
//health
print(Hbar);
if(Hbar==3){
fill(H1G);
rect(25,25,50,50);
}
if(Hbar==2){
fill(0,255,0);
rect(25,25,50,50);
}
if(Hbar==1){
fill(255,150,255);
rect(25,25,50,50);
}
if(Hbar==0){
fill(0);
rect(25,25,50,50);
}
//board
fill(255);
rect(500*width/1000,500*height/1000,200*width/1000,200*height/1000);
rect(700*width/1000,500*height/1000,200*width/1000,200*height/1000);
rect(500*width/1000,700*height/1000,200*width/1000,200*height/1000);
rect(700*width/1000,700*height/1000,200*width/1000,200*height/1000);
rect(500*width/1000,300*height/1000,200*width/1000,200*height/1000);
rect(300*width/1000,500*height/1000,200*width/1000,200*height/1000);
rect(300*width/1000,300*height/1000,200*width/1000,200*height/1000);
rect(700*width/1000,300*height/1000,200*width/1000,200*height/1000);
rect(300*width/1000,700*height/1000,200*width/1000,200*height/1000);
//player
fill(0);
rect(Xm,Ym,100*width/1000,100*height/1000);
//enamy
E1.move();
E2.movee();
E3.move();
}
//movement
void keyReleased(){
if (key == 'a') {
X=X-1;
}
if (key == 'd'){
X=X+1;
}
if (key == 'w'){
Y=Y-1;
}
if (key == 's') {
Y=Y+1;
}
}
class enamy {
float Xe,Ye;
enamy(float x,float y){Xe=x;Ye=y;}
void move(){
switch(EM){
case 1:
if(Xm==Xe && Ym==Ye){ EM=2;Hbar=Hbar-1;}
fill(150,100,0,Ev);
rect(Xe,Ye,150*width/1000,150*height/1000);
case 2:
Xe=0;
Ye =0;
}
}
}
class enamy2 {
float Xe2,Ye2;
enamy2(float x,float y){Xe2=x;Ye2=y;}
void movee(){
switch(EMi){
case 1:
if(Xm==Xe2 && Ym==Ye2){ EMi=2;Hbar=Hbar-1;}
fill(150,100,0,Ev);
rect(Xe2,Ye2,150*width/1000,150*height/1000);
case 2:
Xe2=0;
Ye2 =0;
}
}
}