package electrosphere.entity.state;

import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils;
import electrosphere.main.Globals;
import org.joml.Vector3d;
import org.joml.Vector3f;

/**
 *
 * @author amaterasu
 */
public class ParticleTree {
    Entity parent;
    int maxLife;
    int lifeCurrent;
    Vector3f destination;
    float velocity;
    float acceleration;
    
    public ParticleTree(Entity parent, int maxLife, Vector3f destination, float velocity, float acceleration){
        this.parent = parent;
        this.maxLife = maxLife;
        this.destination = destination;
        this.velocity = velocity;
        this.acceleration = acceleration;
        lifeCurrent = maxLife;
    }

    public int getMaxLife() {
        return maxLife;
    }

    public int getLifeCurrent() {
        return lifeCurrent;
    }

    public Vector3f getDestination() {
        return destination;
    }

    public float getVelocity() {
        return velocity;
    }

    public float getAcceleration() {
        return acceleration;
    }
    
    public void simulate(){
        Vector3d parentPosition = EntityUtils.getPosition(parent);
        parentPosition.add(new Vector3f(destination).mul(velocity));
        velocity = velocity - acceleration;
        if(velocity < 0){
            velocity = 0;
            acceleration = 0;
        }
        lifeCurrent--;
        if(lifeCurrent <= 0){
            Globals.entityManager.deregisterEntity(parent);
        }
    }
    
}
