Package ponkOut.logic

Source Code of ponkOut.logic.Ball

/* 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 ponkOut.PonkOut;
import ponkOut.graphics.BallGO;
import ponkOut.graphics.GraphicsObjectsManager;
import ponkOut.graphics.Material;
import ponkOut.graphics.SolidBallGO;

public abstract class Ball extends Entity {
  protected BallGO graphicsObject;
  protected float radius;

  protected static final float MIN_RADIUS = 0.1f;
  protected static final float MAX_RADIUS = 0.5f;

  public Ball(Material material, GraphicsObjectsManager goManager) {
    radius = PonkOut.COMMON_RADIUS;
    EntityManager.getInstance().addBall(this);
    graphicsObject = new SolidBallGO(this, material, goManager);
  }

  public Ball(Material material, float radius, GraphicsObjectsManager goManager) {
    if (radius < MIN_RADIUS) {
      radius = MIN_RADIUS;
    }
    if (radius > MAX_RADIUS) {
      radius = MAX_RADIUS;
    }

    this.radius = radius;
    EntityManager.getInstance().addBall(this);
    graphicsObject = new SolidBallGO(this, material, goManager);
  }

  public float getRadius() {
    return radius;
  }

  public float getMass() {
    // 3/(4pi) * volume of the sphere
    return radius * radius * radius;
  }

  public abstract boolean isAttached();

  /** detach ball if attached, do nothing if it is not */
  public abstract void detach();

  /** get the last player paddle that had contact with this ball */
  public abstract Paddle getLastPaddle();

  /** set the last player paddle that had contact with this ball */
  public abstract void setLastPaddle(Paddle paddle);
}
TOP

Related Classes of ponkOut.logic.Ball

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.