src/Player.java
/**
     * Checks collision with any of the platform objects
     */
Checks collision with any of the platform objects
Checks collision with any of the platform objects
public void checkCollision(){
        for(GameObject obj : handler.objects){
            if(obj.getId().equals(ObjectId.Platform)){
                if(getBoundsB().intersects(obj.getBounds())){
                    velY = 0;
                    falling = false;
                    jumping = false;
                    this.y = obj.getY() - this.h/2;
                }
                if(getBoundsT().intersects(obj.getBounds())){
                    velY = 0;
                    falling = true;
                    this.y = obj.getY() + 40 + this.h/2;
                }
                if(getBoundsL().intersects(obj.getBounds())){
                    velX = 0;
                    this.x = obj.getX() + 40 + this.w/2;
                }
                if(getBoundsR().intersects(obj.getBounds())){
                    velX = 0;
                    this.x = obj.getX() - this.w/2;
                }
            }else if(obj.getId().equals(ObjectId.Waypoint)){
                if(getBounds().intersects(obj.getBounds())){
                    Game.gameState = ((Game.level == 4)?"menu":"quiz");
                    if(Game.level != 4) game.quiz.loadQuestions();
                    this.reset();
                    break;
                }
            }else if(obj.getId().equals(ObjectId.Food)){
                if(getBounds().intersects(obj.getBounds())){
                    handler.remove(obj);
                    if(!(((Food)obj).isHealthy())){
                        w = (int)(Math.round((double)w*1.2));
                        h = (int)(Math.round((double)h*1.2));
                        imageL = Game.scale(imageL,w,h);
                        imageR = Game.scale(imageR,w,h);
                        Game.score -= 2500;
                    }
                    Game.score += 5000;
                    break;
                }
            }else if(obj.getId().equals(ObjectId.Water)){
                if(getBounds().intersects(obj.getBounds())){
                    handler.remove(obj);
                    bottleCount++;
                    Game.score += 5000;
                    break;
                }
            }
        }
    }
public void checkCollision ( ) { for ( GameObject obj : handler . objects ) { if ( obj . getId ( ) . equals ( ObjectId . Platform ) ) { if ( getBoundsB ( ) . intersects ( obj . getBounds ( ) ) ) { velY = 0 ; falling = false ; jumping = false ; this . y = obj . getY ( ) - this . h / 2 ; } if ( getBoundsT ( ) . intersects ( obj . getBounds ( ) ) ) { velY = 0 ; falling = true ; this . y = obj . getY ( ) + 40 + this . h / 2 ; } if ( getBoundsL ( ) . intersects ( obj . getBounds ( ) ) ) { velX = 0 ; this . x = obj . getX ( ) + 40 + this . w / 2 ; } if ( getBoundsR ( ) . intersects ( obj . getBounds ( ) ) ) { velX = 0 ; this . x = obj . getX ( ) - this . w / 2 ; } } else if ( obj . getId ( ) . equals ( ObjectId . Waypoint ) ) { if ( getBounds ( ) . intersects ( obj . getBounds ( ) ) ) { Game . gameState = ( ( Game . level == 4 ) ? "menu" : "quiz" ) ; if ( Game . level != 4 ) game . quiz . loadQuestions ( ) ; this . reset ( ) ; break ; } } else if ( obj . getId ( ) . equals ( ObjectId . Food ) ) { if ( getBounds ( ) . intersects ( obj . getBounds ( ) ) ) { handler . remove ( obj ) ; if ( ! ( ( ( Food ) obj ) . isHealthy ( ) ) ) { w = ( int ) ( Math . round ( ( double ) w * 1.2 ) ) ; h = ( int ) ( Math . round ( ( double ) h * 1.2 ) ) ; imageL = Game . scale ( imageL , w , h ) ; imageR = Game . scale ( imageR , w , h ) ; Game . score -= 2500 ; } Game . score += 5000 ; break ; } } else if ( obj . getId ( ) . equals ( ObjectId . Water ) ) { if ( getBounds ( ) . intersects ( obj . getBounds ( ) ) ) { handler . remove ( obj ) ; bottleCount ++ ; Game . score += 5000 ; break ; } } } }
Checks collision with any of the platform objects
Checks collision with any of the platform objects