package de.frajul.endlessroll.entities;

import de.frajul.endlessroll.data.Vector;
import de.frajul.endlessroll.entities.collision.geometry.Quad;
import de.frajul.endlessroll.entities.textures.Texture;

/**
 * Created by Julian on 20.11.2015.
 */
public class Entity extends Quad {

    private int textureAtlasIndex;
    private Texture texture;
    private Vector movement;
    private float rotation;
    private float alpha = 1.0f;
    private boolean destroyed;
    private DestroyEffect destroyEffect;
    private Vector maxTexSize;
    private boolean visible = true;

    public Entity(Texture texture, Vector position, float width, float height) {
        super(position, width, height);
        this.texture = texture;
        this.movement = new Vector();
        this.maxTexSize = new Vector();
    }

    public void move(Vector movement) {
        position.translate(movement);
    }

    public void rotate(float factor) {
        rotation += factor;
    }

    public void setToTerrain(float terrainEdge) {
        position.y = terrainEdge + height / 2;
    }

    public void setTopEdge(float y) {
        position.y = y - height / 2;
    }

    public Texture getTexture() {
        return texture;
    }

    public void setTexture(Texture texture) {
        this.texture = texture;
    }

    public Vector getMovement() {
        return movement;
    }

    public void setMovement(Vector movement) {
        this.movement = movement;
    }

    public float getRotation() {
        return rotation;
    }

    public void setRotation(float rotation) {
        this.rotation = rotation;
    }

    public void setAlpha(float alpha) {
        this.alpha = alpha;
    }

    public float getAlpha() {
        return alpha;
    }

    public void destroy(DestroyEffect destroyEffect) {
        this.destroyed = true;
        this.destroyEffect = destroyEffect;
    }

    public boolean isDestroyed() {
        return destroyed;
    }

    public DestroyEffect getDestroyEffect() {
        return destroyEffect;
    }

    public void setTextureAtlasIndex(int textureAtlasIndex) {
        this.textureAtlasIndex = textureAtlasIndex;
    }

    public int getTextureAtlasIndex() {
        return textureAtlasIndex;
    }

    public void setMaxTexSize(Vector maxTexSize) {
        this.maxTexSize = maxTexSize;
    }

    public Vector getMaxTexSize() {
        return maxTexSize;
    }

    public float calcTexScaleX() {
        return getMaxTexSize().x == 0 ? 1 : getWidth() / getMaxTexSize().x;
    }

    public float calcTexScaleY() {
        return getMaxTexSize().y == 0 ? 1 : getHeight() / getMaxTexSize().y;
    }

    public void setVisible(boolean visible) {
        this.visible = visible;
    }

    public boolean isVisible() {
        return visible;
    }
}
