How to make multiple enemies affect health

//Declared Global Variables
final static float MOVE_SPEED = 7.5;
final static float SPRITE_SCALE = 50.0/64;
final static float SPRITE_SCALE1 = 50.0/1920;
final static float SPRITE_SCALE2 =50.0/45;
final static float SPRITE_SCALE3 = 225.0/600;
final static float Teach_Scale=100.0/2800;
final static float SPRITE_SIZE = 50;
final static float GRAVITY= 0.6;
final static float JUMP_SPEED = 17.5;

final static float RIGHT_MARGIN = 400;
final static float LEFT_MARGIN = 60;
final static float VERTICAL_MARGIN = 40;

final static int NEUTRAL_FACING = 0;
final static int RIGHT_FACING = 1;
final static int LEFT_FACING  = 2;

final static float WIDTH = SPRITE_SIZE * 38.4;
final static float HEIGHT = SPRITE_SIZE * 24;
final static float GROUND_LEVEL = HEIGHT-SPRITE_SIZE;

int sec = second();
Sprite teach;
Sprite s1,s2;
Player p;
Sprite text;
PImage tile1, desk, enemy, shelf, p1;
float view_x = 0;
float view_y =0;
ArrayList<Sprite> platforms;
ArrayList<Sprite> walks;
Enemy enemi;
Enemy enemi1;
Enemy enemi2;
Enemy enemi3;
Enemy enemi4;
//initialize variables
int green1, green2, green3, green4, green5,green6;
int bar_of_know;
boolean isGameOver;
boolean chat;

void setup(){
size(1920,1200);
imageMode(CENTER);
p1  = loadImage("walk1.png");
teach = new Sprite("teach.png", Teach_Scale, 3200,850);
p=new Player(p1, 1.0);
bar_of_know=0;
p.setBottom(400);
p.center_x= 100;
p.change_x=0;
p.change_y=0;
isGameOver=false;
platforms = new ArrayList<Sprite>();
walks = new ArrayList<Sprite>();
enemy = loadImage("enemywalk.png");
tile1=loadImage("Tile1.png");
desk=loadImage("Desk.png");
shelf = loadImage("shelf1.png");
createPlatforms("map1.csv");
green1 = 0;
green2 =0;
green3=0;
green4=0;
green5=0;
green6=0;
}



//modify and draw images
void draw(){
background(255);
scroll();

displayAll();
if(!isGameOver){
updateAll();
}
}



void scroll(){
  float right_boundary = view_x+width-RIGHT_MARGIN;
  if(p.getRight()> right_boundary){
   view_x+=p.getRight()-right_boundary; 
  }
  float left_boundary = view_x+LEFT_MARGIN;
  if(p.getLeft()<left_boundary){
    view_x -=left_boundary-p.getLeft();
  }
  float bottom_bound = view_y+height-VERTICAL_MARGIN;
  if(p.getBottom()>bottom_bound){
   view_y+=p.getBottom()-bottom_bound; 
  }
  float top_bound = view_y+VERTICAL_MARGIN;
  if(p.getTop()<top_bound){
   view_y -= top_bound-p.getTop();
  }
  translate(-view_x,-view_y);
}



void drawRect(){
 fill(174, green1,  255);
rect(view_x, view_y, 100, 50);
fill(174,green2, 255);
rect(view_x+101, view_y, 100, 50);
fill(174,green3, 255);
rect(view_x+202, view_y, 100, 50);
fill(174,green4, 255);
rect(view_x+303, view_y, 100, 50);
fill(174,green5, 255);
rect(view_x+404, view_y, 100, 50);
fill(174,green6, 255);
rect(view_x+505, view_y, 100, 50); 
}



public boolean isOnPlat(Sprite s, ArrayList<Sprite> walls){
 s.center_y+=5;
 ArrayList<Sprite>col_list =checkCollisionList(s, walls);
 s.center_y-=5;
 if(col_list.size()>0){
  return true; 
 }
 else {
  return false; 
 }
}


public boolean checkCollision(Sprite s1, Sprite s2){  
boolean noXOverlap = s1.getRight() <= s2.getLeft() || s1.getLeft()>=s2.getRight();
boolean noYOverlap = s1.getBottom() <= s2.getTop() || s1.getTop()>=s2.getBottom();
if (noXOverlap || noYOverlap){
 return false;  
}
else {
return true; 
}
}


ArrayList<Sprite> checkCollisionList(Sprite s1, ArrayList<Sprite> list){
 ArrayList<Sprite> collision_list = new ArrayList<Sprite>();
 for(Sprite p: list){
  if(checkCollision(s1, p)) 
  collision_list.add(p);
 }
 return  collision_list;
}


public void resolvePlatformCollisions(Sprite s, ArrayList <Sprite> walls){
  s.change_y +=GRAVITY;
  s.center_y += s.change_y;
  ArrayList<Sprite> col_list = checkCollisionList(s,walls);
  if(col_list.size()>0){
   Sprite collided = col_list.get(0);
   if(s.change_y>0){
     s.setBottom(collided.getTop());
   }
   else if(s.change_y<0){
    s.setTop(collided.getBottom()); 
   }
   s.change_y=0;
  }
  
  s.center_x+=s.change_x;
  col_list = checkCollisionList(s,walls);
  if(col_list.size()>0){
    Sprite collided = col_list.get(0);
    if(s.change_x>0){
      s.setRight(collided.getLeft());
    }
    else if(s.change_x<0){
     s.setLeft(collided.getRight()); 
    }
  }
  
}


void createPlatforms(String filename){
  String[] lines = loadStrings(filename);
  for (int row=0; row < lines.length; row++){
    String[] values = split(lines[row], ",");
    for(int col = 0; col<values.length; col++){
    if(values[col].equals("1")){
     Sprite t= new Sprite(tile1, SPRITE_SCALE);
     t.center_x = SPRITE_SIZE/2+col*SPRITE_SIZE;
     t.center_y=SPRITE_SIZE/2+row*SPRITE_SIZE;
     platforms.add(t);
    }
    else if (values[col].equals("2")){
      Sprite s = new Sprite(desk, SPRITE_SCALE1);
      s.center_x = SPRITE_SIZE/2 + col * SPRITE_SIZE;
      s.center_y = SPRITE_SIZE/2 + row * SPRITE_SIZE;
      platforms.add(s);
    }
        else if (values[col].equals("3")){
      Sprite s = new Sprite(shelf, SPRITE_SCALE3);
      s.center_x = SPRITE_SIZE/2 + col * SPRITE_SIZE;
      s.center_y = SPRITE_SIZE/2 + row * SPRITE_SIZE;
      platforms.add(s);
    }
        else if (values[col].equals("4")){
          float bLeft = col*SPRITE_SIZE;
          float bRight = bLeft + 8 * SPRITE_SIZE;
        enemi = new Enemy(enemy, 50.0/32, bLeft, bRight);
      enemi.center_x = SPRITE_SIZE/2 + col * SPRITE_SIZE;
      enemi.center_y = SPRITE_SIZE/2 + row * SPRITE_SIZE;
      walks.add(enemi);
    }
        else if (values[col].equals("5")){
          float bLeft = col*SPRITE_SIZE;
          float bRight = bLeft + 7 * SPRITE_SIZE;
        enemi = new Enemy(enemy, 50.0/32, bLeft, bRight);
      enemi.center_x = SPRITE_SIZE/2 + col * SPRITE_SIZE;
      enemi.center_y = SPRITE_SIZE/2 + row * SPRITE_SIZE;
      walks.add(enemi);
    }
            else if (values[col].equals("6")){
          float bLeft = col*SPRITE_SIZE;
          float bRight = bLeft + 6 * SPRITE_SIZE;
        enemi = new Enemy(enemy, 50.0/32, bLeft, bRight);
      enemi.center_x = SPRITE_SIZE/2 + col * SPRITE_SIZE;
      enemi.center_y = SPRITE_SIZE/2 + row * SPRITE_SIZE;
      walks.add(enemi);
    }
            else if (values[col].equals("7")){
          float bLeft = col*SPRITE_SIZE;
          float bRight = bLeft + 5 * SPRITE_SIZE;
        enemi = new Enemy(enemy, 50.0/32, bLeft, bRight);
      enemi.center_x = SPRITE_SIZE/2 + col * SPRITE_SIZE;
      enemi.center_y = SPRITE_SIZE/2 + row * SPRITE_SIZE;
      walks.add(enemi);
    }
            else if (values[col].equals("8")){
          float bLeft = col*SPRITE_SIZE;
          float bRight = bLeft + 4 * SPRITE_SIZE;
        enemi = new Enemy(enemy, 50.0/32, bLeft, bRight);
      enemi.center_x = SPRITE_SIZE/2 + col * SPRITE_SIZE;
      enemi.center_y = SPRITE_SIZE/2 + row * SPRITE_SIZE;
      walks.add(enemi);
    }
    }
  }
}


//call whenever a key is pressed
void keyPressed(){
  if(keyCode == RIGHT){
   p.change_x=MOVE_SPEED; 
  }
   else if(keyCode == LEFT){
   p.change_x=-MOVE_SPEED; 
  }
   else if(keyCode == UP && isOnPlat(p, platforms)){
   p.change_y= -JUMP_SPEED; 
  }
  else if(isGameOver && key == ' '){
   setup(); 
  }
  if(checkCollision(p,teach) && key =='f'){
   chat=true;
  }
  

   if(key == ESC){
    exit(); 
   }
}


//call whenever a key is released
void keyReleased(){
    if(keyCode == RIGHT){
   p.change_x=0; 
  }
   else if(keyCode == LEFT){
   p.change_x=0; 
  }
   else if(keyCode == UP){
   p.change_y=0; 
  }
   else if(keyCode == DOWN){
     p.change_y=0;
   }
   else if(key=='f'){
    chat=false; 
   }
}


   void displayAll(){
    for(Sprite s: platforms){
s.display();
}
for(Sprite enemi: walks){
 enemi.display();
}
p.display(); 
textSize(32);
text("Bar Of Knowledge: "+bar_of_know,view_x+50,view_y+100);
drawRect();
teach.display();
if(chat){
    textSize(32);
   text("Yapping about Economics, Social Sciences, Political Sciences, Business", 3200,900); 
}
if(isGameOver){
 if(bar_of_know==-100){
 //put lose screen here
 }
 else{
  //put win screen here 
 }}}
   
   
   
   void updateAll(){
     checkDeath();
     if(bar_of_know==1){
     green1=198;
     }
     else if(bar_of_know==2){
     green1=198;
     green2=198;
     }
     else if(bar_of_know==3){
           green1=198;
           green2=198;
           green3=198;
     }
     else if(bar_of_know==4){
           green1=198;
           green2=198;
           green3=198;
           green4=198;
     }
     else if(bar_of_know==5){
           green1=198;
           green2=198;
           green3=198;
           green4=198;
           green5=198;
     }
     else if(bar_of_know==6){
           green1=198;
           green2=198;
           green3=198;
           green4=198;
           green5=198;
           green6=198;
     }
     else{
           green1=0;
           green2=0;
           green3=0;
           green4=0;
           green5=0;
           green6=0;
     }
     for(Sprite enemi:walks){
      enemi.update();
      ((AnimatedSprite)enemi).updateAnimation();
     }
       p.updateAnimation();
       resolvePlatformCollisions(p,platforms);
   }
   
   void checkDeath(){
     boolean collideEnemy = checkCollision(p, enemi);
     boolean collideEnemy1 = checkCollision(p, enemi1);
     boolean collideEnemy2 = checkCollision(p, enemi2);
     boolean collideEnemy3 = checkCollision(p, enemi3);
     if(collideEnemy||collideEnemy1||collideEnemy2||collideEnemy3){
      bar_of_know--;
      if(bar_of_know==-100){
       isGameOver=true; 
      }
     }
     
   }
   
   void collectKnowledge(){
    if(bar_of_know==10){
     isGameOver=true; 
    }
   }

→
So when I add more than 1 enemy using the csv file, only the very first enemy actually deals damage to my “player”. I’m new to processing and am not sure what would be relevant or not in solving this which is why I posted me entire code. The main points of focus are most likely “checkCollision”, “createPlatforms” and “checkDeath”

1 Like

Hi @3xotic109,

Sorry, no time to test your code just read…

But I guess your issue is here.

This means no matter how many enemies collide it always count, resp decrease 1 even if multiple enemies collide. Maybe it should decrease by the amount of enemy collisions…

Cheers
— mnse

1 Like

So the issue is that I can’t detect multiple enemies in the first place. Ive changed that to be by the number of enemies but no enemies do damage other than the very first one… Basically, I need help checking multiple enemi collisions so that i can actually make then do damage to the player.

Heres my new code:

//Declared Global Variables
final static float MOVE_SPEED = 7.5;
final static float SPRITE_SCALE = 50.0/64;
final static float SPRITE_SCALE1 = 50.0/1920;
final static float SPRITE_SCALE2 =50.0/45;
final static float SPRITE_SCALE3 = 225.0/600;
final static float Teach_Scale=100.0/2800;
final static float SPRITE_SIZE = 50;
final static float GRAVITY= 0.6;
final static float JUMP_SPEED = 17.5;

final static float RIGHT_MARGIN = 400;
final static float LEFT_MARGIN = 60;
final static float VERTICAL_MARGIN = 40;

final static int NEUTRAL_FACING = 0;
final static int RIGHT_FACING = 1;
final static int LEFT_FACING = 2;

final static float WIDTH = SPRITE_SIZE * 38.4;
final static float HEIGHT = SPRITE_SIZE * 24;
final static float GROUND_LEVEL = HEIGHT-SPRITE_SIZE;

int sec = second();
Sprite teach;
Sprite s1,s2;
Player p;
Sprite text;
PImage tile1, desk, enemy, shelf, p1;
float view_x = 0;
float view_y =0;
ArrayList platforms;
ArrayList walks;
Enemy enemi;
Enemy enemi1;
Enemy enemi2;
Enemy enemi3;
Enemy enemi4;
//initialize variables
int green1, green2, green3, green4, green5,green6,green7,green8,green9,green10;
int bar_of_know;
boolean isGameOver;
boolean chat=false;
boolean chat1=false;
boolean chat2=false;
boolean chat3=false;
boolean chat4=false;
boolean chat5=false;
boolean firstDone=false;
boolean secondDone=false;
boolean thirdDone=false;
boolean fourthDone=false;
boolean fifthDone=false;
boolean sixthDone=false;
boolean reset=false;
boolean reset1=false;
boolean reset2=false;
boolean reset3=false;
boolean reset4=false;
boolean firstRun=true;
void setup(){
size(1920,1200);
imageMode(CENTER);
p1 = loadImage(“walk1.png”);
teach = new Sprite(“teach.png”, Teach_Scale, 3200,850);
p=new Player(p1, 1.0);
bar_of_know=0;
p.setBottom(400);
p.center_x= 100;
p.change_x=0;
p.change_y=0;
isGameOver=false;
platforms = new ArrayList();
walks = new ArrayList();
enemy = loadImage(“enemywalk.png”);
tile1=loadImage(“Tile1.png”);
desk=loadImage(“Desk.png”);
shelf = loadImage(“shelf1.png”);
createPlatforms(“map1.csv”);
green1 = 0;
green2 =0;
green3=0;
green4=0;
green5=0;
green6=0;
green7=0;
green8=0;
green9=0;
green10=0;
}

//modify and draw images
void draw(){
background(255);
scroll();

displayAll();
//if(!isGameOver){
updateAll();
//}
}

void scroll(){
float right_boundary = view_x+width-RIGHT_MARGIN;
if(p.getRight()> right_boundary){
view_x+=p.getRight()-right_boundary;
}
float left_boundary = view_x+LEFT_MARGIN;
if(p.getLeft()<left_boundary){
view_x -=left_boundary-p.getLeft();
}
float bottom_bound = view_y+height-VERTICAL_MARGIN;
if(p.getBottom()>bottom_bound){
view_y+=p.getBottom()-bottom_bound;
}
float top_bound = view_y+VERTICAL_MARGIN;
if(p.getTop()<top_bound){
view_y -= top_bound-p.getTop();
}
translate(-view_x,-view_y);
}

void drawRect(){
fill(174, green1, 255);
rect(view_x, view_y, 100, 50);
fill(174,green2, 255);
rect(view_x+101, view_y, 100, 50);
fill(174,green3, 255);
rect(view_x+202, view_y, 100, 50);
fill(174,green4, 255);
rect(view_x+303, view_y, 100, 50);
fill(174,green5, 255);
rect(view_x+404, view_y, 100, 50);
fill(174,green6, 255);
rect(view_x+505, view_y, 100, 50);
fill(174,green7, 255);
rect(view_x+606, view_y, 100, 50);
fill(174,green8, 255);
rect(view_x+707, view_y, 100, 50);
fill(174,green9, 255);
rect(view_x+808, view_y, 100, 50);
fill(174,green10, 255);
rect(view_x+909, view_y, 100, 50);
}

public boolean isOnPlat(Sprite s, ArrayList walls){
s.center_y+=5;
ArrayListcol_list =checkCollisionList(s, walls);
s.center_y-=5;
if(col_list.size()>0){
return true;
}
else {
return false;
}
}

public boolean checkCollision(Sprite s1, Sprite s2){
boolean noXOverlap = s1.getRight() <= s2.getLeft() || s1.getLeft()>=s2.getRight();
boolean noYOverlap = s1.getBottom() <= s2.getTop() || s1.getTop()>=s2.getBottom();
if (noXOverlap || noYOverlap){
return false;
}
else {
return true;
}
}

ArrayList checkCollisionList(Sprite s1, ArrayList list){
ArrayList collision_list = new ArrayList();
for(Sprite p: list){
if(checkCollision(s1, p))
collision_list.add(p);
}
return collision_list;
}

public void resolvePlatformCollisions(Sprite s, ArrayList walls){
s.change_y +=GRAVITY;
s.center_y += s.change_y;
ArrayList col_list = checkCollisionList(s,walls);
if(col_list.size()>0){
Sprite collided = col_list.get(0);
if(s.change_y>0){
s.setBottom(collided.getTop());
}
else if(s.change_y<0){
s.setTop(collided.getBottom());
}
s.change_y=0;
}

s.center_x+=s.change_x;
col_list = checkCollisionList(s,walls);
if(col_list.size()>0){
Sprite collided = col_list.get(0);
if(s.change_x>0){
s.setRight(collided.getLeft());
}
else if(s.change_x<0){
s.setLeft(collided.getRight());
}
}

}

void createPlatforms(String filename){
String lines = loadStrings(filename);
for (int row=0; row < lines.length; row++){
String values = split(lines[row], “,”);
for(int col = 0; col<values.length; col++){
if(values[col].equals(“1”)){
Sprite t= new Sprite(tile1, SPRITE_SCALE);
t.center_x = SPRITE_SIZE/2+colSPRITE_SIZE;
t.center_y=SPRITE_SIZE/2+row
SPRITE_SIZE;
platforms.add(t);
}
else if (values[col].equals(“2”)){
Sprite s = new Sprite(desk, SPRITE_SCALE1);
s.center_x = SPRITE_SIZE/2 + col * SPRITE_SIZE;
s.center_y = SPRITE_SIZE/2 + row * SPRITE_SIZE;
platforms.add(s);
}
else if (values[col].equals(“3”)){
Sprite s = new Sprite(shelf, SPRITE_SCALE3);
s.center_x = SPRITE_SIZE/2 + col * SPRITE_SIZE;
s.center_y = SPRITE_SIZE/2 + row * SPRITE_SIZE;
platforms.add(s);
}
else if (values[col].equals(“4”)){
float bLeft = colSPRITE_SIZE;
float bRight = bLeft + 8 * SPRITE_SIZE;
enemi = new Enemy(enemy, 50.0/32, bLeft, bRight);
enemi.center_x = SPRITE_SIZE/2 + col * SPRITE_SIZE;
enemi.center_y = SPRITE_SIZE/2 + row * SPRITE_SIZE;
walks.add(enemi);
}
else if (values[col].equals(“5”)){
float bLeft = col
SPRITE_SIZE;
float bRight = bLeft + 7 * SPRITE_SIZE;
enemi = new Enemy(enemy, 50.0/32, bLeft, bRight);
enemi.center_x = SPRITE_SIZE/2 + col * SPRITE_SIZE;
enemi.center_y = SPRITE_SIZE/2 + row * SPRITE_SIZE;
walks.add(enemi);
}
else if (values[col].equals(“6”)){
float bLeft = colSPRITE_SIZE;
float bRight = bLeft + 6 * SPRITE_SIZE;
enemi = new Enemy(enemy, 50.0/32, bLeft, bRight);
enemi.center_x = SPRITE_SIZE/2 + col * SPRITE_SIZE;
enemi.center_y = SPRITE_SIZE/2 + row * SPRITE_SIZE;
walks.add(enemi);
}
else if (values[col].equals(“7”)){
float bLeft = col
SPRITE_SIZE;
float bRight = bLeft + 5 * SPRITE_SIZE;
enemi = new Enemy(enemy, 50.0/32, bLeft, bRight);
enemi.center_x = SPRITE_SIZE/2 + col * SPRITE_SIZE;
enemi.center_y = SPRITE_SIZE/2 + row * SPRITE_SIZE;
walks.add(enemi);
}
else if (values[col].equals(“8”)){
float bLeft = col*SPRITE_SIZE;
float bRight = bLeft + 4 * SPRITE_SIZE;
enemi = new Enemy(enemy, 50.0/32, bLeft, bRight);
enemi.center_x = SPRITE_SIZE/2 + col * SPRITE_SIZE;
enemi.center_y = SPRITE_SIZE/2 + row * SPRITE_SIZE;
walks.add(enemi);
}
}
}
}

//call whenever a key is pressed
void keyPressed(){
if(keyCode == RIGHT){
p.change_x=MOVE_SPEED;
}
else if(keyCode == LEFT){
p.change_x=-MOVE_SPEED;
}
else if(keyCode == UP && isOnPlat(p, platforms)){
p.change_y= -JUMP_SPEED;
}
else if(isGameOver && key == ’ '){
setup();
}
if(checkCollision(p,teach) && key ==‘f’ && firstRun==true){
chat=true;
}
if(checkCollision(p,teach) && key==‘f’&&reset==true){
chat1=true;
}
else if(checkCollision(p,teach) && key==‘f’ &&reset1==true){
chat2=true;
}
else if(checkCollision(p,teach) && key==‘f’ &&reset2==true){
chat3=true;
}
else if(checkCollision(p,teach) && key==‘f’ &&reset3==true){
chat4=true;
}
else if(checkCollision(p,teach) && key==‘f’ &&reset4==true){
chat5=true;
}
if(key==‘r’){
p.center_x=100;
p.setBottom(800);
reset=true;
firstRun=false;
}
if(key==‘r’ && bar_of_know==4){
p.center_x=100;
p.setBottom(800);
reset1=true;
reset=false;
reset2=false;
reset3=false;
reset4=false;
}
if(key==‘r’ && bar_of_know==6){
p.center_x=100;
p.setBottom(800);
reset2=true;
reset1=false;
reset=false;
reset3=false;
reset4=false;
}
if(key==‘r’ && bar_of_know==8){
p.center_x=100;
p.setBottom(800);
reset3=true;
reset=false;
reset2=false;
reset1=false;
reset4=false;
}
if(key==‘r’ && bar_of_know==10){
p.center_x=100;
p.setBottom(800);
reset4=true;
reset=false;
reset2=false;
reset3=false;
reset1=false;
}

if(key == ESC){
exit();
}
}

//call whenever a key is released
void keyReleased(){
if(keyCode == RIGHT){
p.change_x=0;
}
else if(keyCode == LEFT){
p.change_x=0;
}
else if(keyCode == UP){
p.change_y=0;
}
else if(keyCode == DOWN){
p.change_y=0;
}
else if(key==‘f’){
chat=false;
chat1=false;
chat2=false;
chat3=false;
chat4=false;
chat5=false;
}
else if(key==‘r’){

}
}

void displayAll(){
for(Sprite s: platforms){
s.display();
}
for(Sprite enemi: walks){
enemi.display();
}
p.display();
textSize(32);
text("Bar Of Knowledge: "+bar_of_know,view_x+50,view_y+100);
drawRect();
teach.display();
//textSize(32);
//text(“reset:”+reset,view_x+50,view_y+200);
//text(“reset1:”+reset1,view_x+50,view_y+300);
//text(“reset2:”+reset2,view_x+50,view_y+400);
//text(“reset3:”+reset3,view_x+50,view_y+500);
//text(“reset4:”+reset4,view_x+50,view_y+600);
if(chat){
textSize(32);
text(“Master the basics of supply and demand,”, 2500,650);
text(“and connect economic concepts to current”,2500,700);
text(“events for a practical understanding of”,2500,750);
text(“how economics influences the world around you.”,2500,800);
firstDone=true;
}

if(chat1){
text(“Master social science basics like culture”, 2500,650);
text(“and human behavior, and connect them”,2500,700);
text(“to current events for a practical”,2500,750);
text(“understanding of the world’s complexities.”,2500,800);
secondDone=true;
}
if(chat2){//CHANGE
text(“Master social science basics like culture”, 2500,650);
text(“and human behavior, and connect them”,2500,700);
text(“to current events for a practical”,2500,750);
text(“understanding of the world’s complexities.”,2500,800);
thirdDone=true;
}
if(chat3){//CHANGE
text(“Master social science basics like culture”, 2500,650);
text(“and human behavior, and connect them”,2500,700);
text(“to current events for a practical”,2500,750);
text(“understanding of the world’s complexities.”,2500,800);
fourthDone=true;
}
if(chat4){//CHANGE
text(“Master social science basics like culture”, 2500,650);
text(“and human behavior, and connect them”,2500,700);
text(“to current events for a practical”,2500,750);
text(“understanding of the world’s complexities.”,2500,800);
fifthDone=true;
}
if(chat5){//CHANGE
text(“Master social science basics like culture”, 2500,650);
text(“and human behavior, and connect them”,2500,700);
text(“to current events for a practical”,2500,750);
text(“understanding of the world’s complexities.”,2500,800);
sixthDone=true;
}
if(firstDone==true){
bar_of_know=2;
firstDone=false;
}
else if(secondDone==true){
bar_of_know=4;
secondDone=false;
}
else if(thirdDone==true){
bar_of_know=6;
thirdDone=false;
}
else if(fourthDone==true){
bar_of_know=8;
fourthDone=false;
}
else if(fifthDone==true){
bar_of_know=10;
fifthDone=false;
}

collectKnowledge();
if(isGameOver){
if(bar_of_know==-100){
text(“YOU LOSE”,view_x+500,view_y+500);
}
else{
text(“YOU WIN”,view_x+500,view_y+500);
}}}

void updateAll(){
checkDeath();
if(bar_of_know==1){
green1=198;
}
else if(bar_of_know==2){
green1=198;
green2=198;
}
else if(bar_of_know==4){
green1=198;
green2=198;
green3=198;
green4=198;
}
else if(bar_of_know==6){
green1=198;
green2=198;
green3=198;
green4=198;
green5=198;
green6=198;
}
else if(bar_of_know==8){
green1=198;
green2=198;
green3=198;
green4=198;
green5=198;
green6=198;
green7=198;
green8=198;
}
else if(bar_of_know==10){
green1=198;
green2=198;
green3=198;
green4=198;
green5=198;
green6=198;
green7=198;
green8=198;
green9=198;
green10=198;
}
else{
green1=0;
green2=0;
green3=0;
green4=0;
green5=0;
green6=0;
green7=0;
green8=0;
green9=0;
green10=0;
}
for(Sprite enemi:walks){
enemi.update();
((AnimatedSprite)enemi).updateAnimation();
}
p.updateAnimation();
resolvePlatformCollisions(p,platforms);
}

void checkDeath(){
boolean collideEnemy = checkCollision(p, enemi);

 if(collideEnemy){
  bar_of_know--;
  if(bar_of_know==-100){
   isGameOver=true; 
  }
 }

}

void collectKnowledge(){
if(bar_of_know==10){
isGameOver=true;
}
}

You forgot to change the line?

Try

if(collideEnemy){
bar_of_know–;
}

if(collideEnemy1){
bar_of_know–;
}

etc.!

each separately