/* Copyright 2010, 2012 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;
import ponkOut.PonkOut;
import ponkOut.graphics.GraphicsObjectsManager;
import ponkOut.graphics.Material;
import ponkOut.graphics.PaddleGO;
public abstract class Paddle extends Entity {
public enum Place {
LEFT, RIGHT, TOP, BOTTOM
};
/**
* TOP_LEFT means top if the paddle is in place left or right and top
* otherwise BOTTOM_RIGHT means bottom if the paddle is in place left or
* right and right otherwise
*/
public enum HemispherePlace {
TOP_LEFT, BOTTOM_RIGHT
};
protected PaddleGO graphicsObject;
/** Length of the cylinder. There are hemispheres added at both sides */
protected float length;
/** radius of the cylinder and hemispheres */
protected float radius;
/** The assigned place, can be LEFT, RIGHT, TOP or BOTTOM */
protected Place place;
public Paddle(Place place, float length, Material material, GraphicsObjectsManager goManager) {
this.place = place;
this.length = length;
this.radius = PonkOut.COMMON_RADIUS;
switch (place) {
case LEFT:
setPosition(new Vector2f(-TOP_POS, 0.0f));
break;
case RIGHT:
setPosition(new Vector2f(TOP_POS, 0.0f));
break;
case TOP:
setPosition(new Vector2f(0.0f, TOP_POS));
break;
case BOTTOM:
setPosition(new Vector2f(0.0f, -TOP_POS));
break;
}
graphicsObject = new PaddleGO(this, material, goManager);
EntityManager.getInstance().addPaddle(this);
}
public Place getPlace() {
return place;
}
public float getLength() {
return length;
}
public float getRadius() {
return radius;
}
public float getMass() {
// 3/(4pi) * (volume of the sphere + cylinder)
return radius * radius * radius + 0.75f * radius * radius * length;
}
public Vector2f getHemispherePosition(HemispherePlace hemispherePlace) {
Vector2f p = getPosition();
switch (place) {
case LEFT:
case RIGHT:
if (hemispherePlace == HemispherePlace.TOP_LEFT)
return new Vector2f(p.x, p.y + length / 2.0f);
else
return new Vector2f(p.x, p.y - length / 2.0f);
case TOP:
case BOTTOM:
if (hemispherePlace == HemispherePlace.TOP_LEFT)
return new Vector2f(p.x - length / 2.0f, p.y);
else
return new Vector2f(p.x + length / 2.0f, p.y);
}
throw new IllegalStateException("Paddle in unspecified place");
}
public abstract boolean isBallAttached();
public abstract GameBall getAttachedBall();
public void applyInput(float elapsedTime) {
}
}