Exemplo n.º 1
0
    /**
     * Normalizes a ball's position after it has hit a paddle.
     *
     * @param r The paddle the ball has hit.
     */
    protected void normalize(Paddle p) {
      // Quit if the ball is outside the width of the paddle
      if (x < p.getLeft() || x > p.getRight()) {
        return;
      }

      // Case if ball is above the paddle
      if (y < p.getTop()) {
        y = Math.min(y, p.getTop() - Ball.RADIUS);
      } else if (y > p.getBottom()) {
        y = Math.max(y, p.getBottom() + Ball.RADIUS);
      }
    }
Exemplo n.º 2
0
  protected void handleBottomFastBounce(Paddle paddle, float px, float py) {
    if (mBall.goingDown() == false) return;

    float bx = mBall.x;
    float by = mBall.y + Ball.RADIUS;
    float pbx = px;
    float pby = py + Ball.RADIUS;
    float dyp = by - paddle.getTop();
    float xc = bx + (bx - pbx) * dyp / (pby - by);

    if (by > paddle.getTop()
        && pby < paddle.getTop()
        && xc > paddle.getLeft()
        && xc < paddle.getRight()) {

      mBall.x = xc;
      mBall.y = paddle.getTop() - Ball.RADIUS;
      mBall.bouncePaddle(paddle);
      playSound(mPaddleSFX);
      increaseDifficulty();
    }
  }