java - Paddle game - Ball contacting paddle -


Currently coding Java games where the sword has three walls and one paddle, trying to implement the collision method Checks the ball attacking the paddle Ball sometimes notice the pedal, and sometimes it does not, it does not. If someone tells me where I am wrong

My code:

  Public boolean is Sieigenie (ball one ball) {int ballYPos = aBall.getY (); // getY will return the end of the ball paddleXPos = Paddle.this.getX (); / / Will return to the upper left corner of the pedal if (ballypos-aBall.getRadius () == Paddlex POS + width) // Check for yPos-radius {return true; } And false return; }    

You are currently checking whether they are exact identical. So it will be right only when they are exactly the same, i.e. 10.1 == 10.1 .... However 10.1! Try to use <10p

  if (ballYPos-aBall.getRadius () & lt; = paddleXPos + width) // YPos- Check for radius {Back to true; }   

However it seems that this is a clunk way to calculate in any way. You're comparing the Y value of the ball in the pedal X value.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -