Package ponkOut.logic

Source Code of ponkOut.logic.PaddleCylinderCollision

/* Copyright 2010, 2013 Christian Matt
*
* This file is part of PonkOut.
*
* PonkOut is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PonkOut is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PonkOut.  If not, see <http://www.gnu.org/licenses/>.
*/

package ponkOut.logic;

import org.lwjgl.util.vector.Vector2f;

public class PaddleCylinderCollision extends Collision {
  private Paddle paddle;

  public PaddleCylinderCollision(float time, Ball ball, Paddle paddle) {
    super(time, ball);
    this.paddle = paddle;
  }

  @Override
  public void apply() {
    // just reflect velocity of ball
    Vector2f v1 = ball.getVelocity();
    switch (paddle.getPlace()) {
    case LEFT:
    case RIGHT:
      ball.setVelocity(new Vector2f(-v1.x, v1.y));
      break;

    case TOP:
    case BOTTOM:
      ball.setVelocity(new Vector2f(v1.x, -v1.y));
      break;
    }

    // update ball's last paddle
    if (paddle.isMovable()) {
      ball.setLastPaddle(paddle);
    }
  }
}
TOP

Related Classes of ponkOut.logic.PaddleCylinderCollision

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.