Java Pong collision detection -


hello trying make pong game java , works great except collision part. firstly used bounds class , intersects method solve collision problem method works collision case shown on picture drew.

error case

so wrote new code myself instead of using bounds class, , created method side collision detection again having hard time solve collision detection top , bottom of paddle.

public boolean collideright(ball ball){     if(ball.getlayoutx()+ball.getradius()>=player.getlayoutx()&&(ball.getlayouty()+ball.getradius()>=player.getlayouty()&&ball.getlayouty()-ball.getradius()<=player.getlayouty()+height)){         return true;     }     else{         return false;     } } 

and method made top , bottom collision detection.

public boolean colliderightupside(ball ball){     if((ball.getlayoutx()+ball.getradius()>=player.getlayoutx()&&ball.getlayoutx()-ball.getradius()<=player.getlayoutx()+width)&&(ball.getlayouty()+ball.getradius()>=player.getlayouty()&&ball.getlayouty()-ball.getradius()<=player.getlayouty()+height)){         return true;     }     else{         return false;     } } 

can please me.

try include both if statements in 1 function looks this:

public boolean collidefunction(ball ball){     if(ball.getlayoutx()+ball.getradius()>=player.getlayoutx()&&(ball.getlayouty()+ball.getradius()>=player.getlayouty()&&ball.getlayouty()-ball.getradius()<=player.getlayouty()+height)){         return true;     }     else if((ball.getlayoutx()+ball.getradius()>=player.getlayoutx()&&ball.getlayoutx()-ball.getradius()<=player.getlayoutx()+width)&&(ball.getlayouty()+ball.getradius()>=player.getlayouty()&&ball.getlayouty()-ball.getradius()<=player.getlayouty()+height)){         return true;     }     else{         return false;     } } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -