package xaero.rotatenjump.game.object;

/**
 * Created by xaero on 08/07/2017.
 */

public class EntityWithVelocity extends Entity {

    public static final float MAX_VELOCITY = 15;
    protected float velocityX;
    protected float velocityY;
    protected float velocityZ;

    public EntityWithVelocity(float posX, float posY, float renderBoxWidth, float renderBoxHeight, float renderBoxFatness){
        super(posX, posY, renderBoxWidth, renderBoxHeight, renderBoxFatness);
    }

    protected float getVelocity(){
        return (float) Math.sqrt(velocityX * velocityX + velocityY * velocityY + velocityZ * velocityZ);
    }

    protected float fixVelocity(){
        float velocity = getVelocity();
        if (velocity > MAX_VELOCITY) {
            velocityX *= MAX_VELOCITY / velocity;
            velocityY *= MAX_VELOCITY / velocity;
            velocityZ *= MAX_VELOCITY / velocity;
            velocity = MAX_VELOCITY;
        }
        return velocity;
    }

    protected void applyVelocity(){
        posX += velocityX;
        posY += velocityY;
        posZ += velocityZ;
    }

}
