Renderer/src/main/java/electrosphere/entity/state/movement/SprintTree.java
2024-03-21 20:37:47 -04:00

85 lines
2.1 KiB
Java

package electrosphere.entity.state.movement;
import electrosphere.engine.Main;
import electrosphere.entity.Entity;
import electrosphere.entity.btree.BehaviorTree;
import electrosphere.entity.state.movement.groundmove.GroundMovementTree;
import electrosphere.entity.state.movement.groundmove.GroundMovementTree.MovementTreeState;
/**
*
* @author amaterasu
*/
public class SprintTree implements BehaviorTree {
public static enum SprintTreeState {
SPRINTING,
NOT_SPRINTING,
}
SprintTreeState state;
GroundMovementTree groundMovementTree;
Entity parent;
int staminaCurrent = 0;
int staminaMax = 1;
float maxVelocity;
public SprintTree(Entity e, float maxVelocity, int staminaMax){
state = SprintTreeState.NOT_SPRINTING;
parent = e;
this.maxVelocity = maxVelocity;
this.staminaMax = staminaMax;
}
public SprintTreeState getState(){
return state;
}
public void start(){
if(staminaCurrent > 0){
// System.out.println("Starting sprinting");
state = SprintTreeState.SPRINTING;
}
}
public void stop(){
state = SprintTreeState.NOT_SPRINTING;
}
@Override
public void simulate(float deltaTime){
switch(state){
case SPRINTING:
if(groundMovementTree != null && groundMovementTree.getState() != MovementTreeState.IDLE){
staminaCurrent--;
if(staminaCurrent < 1){
state = SprintTreeState.NOT_SPRINTING;
}
}
break;
case NOT_SPRINTING:
staminaCurrent++;
if(staminaCurrent > staminaMax){
staminaCurrent = staminaMax;
}
break;
}
}
public void setGroundMovementTree(GroundMovementTree groundMovementTree){
this.groundMovementTree = groundMovementTree;
}
//get max velocity
public float getMaxVelocity() {
return maxVelocity;
}
}