package xaero.rotatenjump.game.object;

import xaero.rotatenjump.game.Game;
import xaero.rotatenjump.game.graphics.Graphics;

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

public class Entity {

    protected float posX;
    protected float posY;
    protected float posZ;
    protected float lastPosX;
    protected float lastPosY;
    protected float lastPosZ;
    private float renderBoxWidth;//size of the box around posX posY which is used to check whether to render this entity
    private float renderBoxHeight;
    private float renderBoxFatness;
    private float renderBoxWidthExtra = -1;//takes perspective in count
    private float renderBoxHeightExtra = -1;//takes perspective in count
    public int goThrough = 0;
    public int shake = 0;

    protected float posXRender;
    protected float posYRender;
    protected float posZRender;
    protected float lastPosXRender;
    protected float lastPosYRender;
    protected float lastPosZRender;
    //protected float partialTickMultiplier = 1f;
   // protected float nextPartialTickMultiplier = 1f;
    protected float[] updateVector2 = new float[2];//reusable object for all sorts of things, only for usage in update thread

    public Entity(float posX, float posY, float renderBoxWidth, float renderBoxHeight, float renderBoxFatness){
        this.posX = this.posXRender = posX;
        this.posY = this.posYRender = posY;
        this.lastPosX = lastPosXRender = posX;
        this.lastPosY = lastPosYRender = posY;
        this.renderBoxWidth = renderBoxWidth;
        this.renderBoxHeight = renderBoxHeight;
        this.renderBoxFatness = renderBoxFatness;
    }

    public void preUpdate(){
        lastPosX = posX;
        lastPosY = posY;
        lastPosZ = posZ;
    }

   /* public float getNextPartialTickMultiplier(){
        return nextPartialTickMultiplier;
    }*/

    public float getPosX(float partialCollision) {
        return lastPosX + (posX - lastPosX) * partialCollision;
    }

    public float getPosY(float partialCollision) {
        return lastPosY + (posY - lastPosY) * partialCollision;
    }

    public float getLastPosX() {
        return lastPosX;
    }

    public float getLastPosY() {
        return lastPosY;
    }

    public float getLastPosXRender() {
        return lastPosXRender;
    }

    public float getLastPosYRender() {
        return lastPosYRender;
    }

    public float getBoxWidth(){
        if(renderBoxWidthExtra == -1)
            renderBoxWidthExtra = renderBoxFatness * Graphics.halfFOVTan;
        return renderBoxWidth + renderBoxWidthExtra;
    }

    public float getBoxHeight(){
        if(renderBoxHeightExtra == -1)
            renderBoxHeightExtra = renderBoxFatness * Graphics.halfFOVTan / Graphics.ratio;
        return renderBoxHeight + renderBoxHeightExtra;
    }

    public void update(Game game){
        if(goThrough > 0)
            goThrough--;
    }

    public void refresh(){
        lastPosXRender = posXRender;
        posXRender = posX;
        lastPosYRender = posYRender;
        posYRender = posY;
        lastPosZRender = posZRender;
        posZRender = posZ;
    }

    public void render(Game game, float partialTicks){
    }

    public boolean isCollidingWith(Player player, float distance, float[][] points, float collisionPartial){
        return false;
    }

    public void collide(Player player, float[][] points){

    }

}
