I need help with checking for intersections in a game I'm creating: When a character collides with a single obstacle on the screen all works as intended, but when multiple obstacles are added to the screen the character can only jump off of the last obstacle that is being checked for collision. The character still collides properly with the other obstacles (doesn't fall through, cant walk through) but can't jump off of them. Obs is an arraylist of obstacles. Ground is the boolean that determines if the character is allowed to jump.
public void checkIntersect(ArrayList<Obstacle> obs){
for(Obstacle a: obs){
if(a.getLeft().intersects(this.getRight())){
if(getDx()>0){
sidecollision=true;
setDx(0);
this.x-=1.5f;
}
} if (a.getRight().intersects(this.getLeft())){
sidecollision = true;
setDx(0);
this.x+=1.5f;
} if((a.getTop()).intersects(this.getBottom())){
ground=true;
setDy(0);
this.y-=.10f;
} else if(!(a.getTop()).intersects(this.getBottom())){
ground = false;
//return ground;
} if(a.getBottom().intersects(this.getTop())){
ground=false;
setDy(0);
this.y+=.1f;
}
}
}
and how collision is being checked on the game component:
bg.update(quote);
win.fill(clear);
bg.drawBG(win);
for(Obstacle o: obs){
o.draw(win);
o.update(bg);
}
if(quote.isVisible()){
quote.movedrawProtag(win, keys);
quote.checkIntersect(obs);
}