Package ponkOut.logic

Source Code of ponkOut.logic.BlockFaceCollision

/* Copyright 2010 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 BlockFaceCollision extends Collision {
  private Block block;
  private Block.FacePlace face;

  public BlockFaceCollision(float time, Ball ball, Block block, Block.FacePlace face) {
    super(time, ball);

    this.block = block;
    this.face = face;
  }

  @Override
  public void apply() {
    // just reflect velocity of ball
    Vector2f v1 = ball.getVelocity();
    switch (face) {
    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;
    }

    block.notifyHit(ball);
  }
}
TOP

Related Classes of ponkOut.logic.BlockFaceCollision

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.