Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
70 lines
1.6 KiB
Java
70 lines
1.6 KiB
Java
package electrosphere.entity.state;
|
|
|
|
import electrosphere.engine.Globals;
|
|
import electrosphere.entity.Entity;
|
|
import electrosphere.entity.EntityUtils;
|
|
|
|
import org.joml.Vector3d;
|
|
import org.joml.Vector3f;
|
|
|
|
/**
|
|
*
|
|
* @author amaterasu
|
|
*/
|
|
public class ParticleTree implements BehaviorTree {
|
|
Entity parent;
|
|
boolean hasLife = true;
|
|
int maxLife;
|
|
int lifeCurrent;
|
|
Vector3f destination;
|
|
float velocity;
|
|
float acceleration;
|
|
|
|
public ParticleTree(Entity parent, int maxLife, Vector3f destination, float velocity, float acceleration, boolean hasLife){
|
|
this.parent = parent;
|
|
this.maxLife = maxLife;
|
|
this.destination = destination;
|
|
this.velocity = velocity;
|
|
this.acceleration = acceleration;
|
|
this.hasLife = hasLife;
|
|
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(float deltaTime){
|
|
Vector3d parentPosition = EntityUtils.getPosition(parent);
|
|
parentPosition.add(new Vector3f(destination).mul(velocity));
|
|
velocity = velocity - acceleration;
|
|
if(velocity < 0){
|
|
velocity = 0;
|
|
acceleration = 0;
|
|
}
|
|
if(hasLife){
|
|
lifeCurrent--;
|
|
if(lifeCurrent <= 0){
|
|
EntityUtils.cleanUpEntity(parent);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|