/* 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;
/**
* An Entity is an object which can interact with other Entities in the game.
*/
public abstract class Entity {
/** y-position of top paddle (= x-position of right paddle) */
public static final float TOP_POS = 10.0f;
public static final float MAX_SPEED = 100.0f;
private Vector2f position;
private Vector2f velocity;
public Entity() {
position = new Vector2f(0.0f, 0.0f);
velocity = new Vector2f(0.0f, 0.0f);
}
public final Vector2f getPosition() {
return new Vector2f(position.x, position.y);
}
public final void setPosition(Vector2f position) {
this.position = new Vector2f(position.x, position.y);
}
public final Vector2f getVelocity() {
return new Vector2f(velocity.x, velocity.y);
}
public final void setVelocity(Vector2f velocity) {
Vector2f v = new Vector2f(velocity.x, velocity.y);
float speed = v.length();
if (speed > MAX_SPEED)
v.scale(MAX_SPEED / speed);
this.velocity = v;
}
public abstract boolean isMovable();
/** update position according to velocity */
public void move(float elapsedTime) {
position.x += elapsedTime * velocity.x;
position.y += elapsedTime * velocity.y;
}
}