Skip to main content
Formatting
Source Link
Laurent Couvidou
  • 9.2k
  • 2
  • 42
  • 58

youYou are setting groundground to false in the wrong place. You should set groundground to false at the beginning of the method. Here is the modified code:

public void checkIntersect(ArrayList obs) {
     
    ground = false;
     
    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())) {

                // return ground;
            }
            if (a.getBottom().intersects(this.getTop())) {
                setDy(0);

                this.y += .1f;
            }
        }
    }
}

you are setting ground to false in the wrong place. You should set ground to false at the beginning of the method. Here is the code:

public void checkIntersect(ArrayList obs) {
        ground = false;
        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())) {

                // return ground;
            }
            if (a.getBottom().intersects(this.getTop())) {
                setDy(0);

                this.y += .1f;
            }
        }
    }

You are setting ground to false in the wrong place. You should set ground to false at the beginning of the method. Here is the modified code:

public void checkIntersect(ArrayList obs) {
 
    ground = false;
     
    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())) {

            // return ground;
        }
        if (a.getBottom().intersects(this.getTop())) {
            setDy(0);

            this.y += .1f;
        }
        
    }
}
Source Link

you are setting ground to false in the wrong place. You should set ground to false at the beginning of the method. Here is the code:

public void checkIntersect(ArrayList obs) {
        ground = false;
        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())) {

                // return ground;
            }
            if (a.getBottom().intersects(this.getTop())) {
                setDy(0);

                this.y += .1f;
            }
        }
    }