Renderer/src/main/java/electrosphere/entity/state/movement/ServerFallTree.java
austin ebec7a373e
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
Separation of client and server logic
2023-05-20 19:18:09 -04:00

102 lines
2.8 KiB
Java

package electrosphere.entity.state.movement;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.BehaviorTree;
import electrosphere.renderer.actor.Actor;
public class ServerFallTree implements BehaviorTree {
static enum FallState {
ACTIVE,
INACTIVE,
}
FallState state = FallState.INACTIVE;
String animationFall = "Armature|Fall";
String animationLand = "Armature|Land";
Entity parent;
ServerJumpTree jumpTree;
public ServerFallTree(Entity parent){
this.parent = parent;
}
@Override
public void simulate(float deltaTime) {
Actor entityActor = EntityUtils.getActor(parent);
switch(state){
case ACTIVE:
if(entityActor != null){
String animationToPlay = determineCorrectAnimation();
if(
!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationToPlay) &&
(jumpTree == null || !jumpTree.isJumping())
){
entityActor.playAnimation(animationToPlay,1);
entityActor.incrementAnimationTime(0.0001);
}
}
break;
case INACTIVE:
break;
}
}
public void start(){
state = FallState.ACTIVE;
}
public boolean isFalling(){
return state == FallState.ACTIVE;
}
public void land(){
if(state != FallState.INACTIVE){
state = FallState.INACTIVE;
Actor entityActor = EntityUtils.getActor(parent);
if(entityActor != null){
String animationToPlay = determineCorrectAnimation();
if(
!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationToPlay)
){
entityActor.playAnimation(animationToPlay,1);
entityActor.incrementAnimationTime(0.0001);
}
}
}
}
public static ServerFallTree getFallTree(Entity parent){
return (ServerFallTree)parent.getData(EntityDataStrings.FALL_TREE);
}
String determineCorrectAnimation(){
switch(state){
case ACTIVE:
return animationFall;
case INACTIVE:
return animationLand;
default:
return animationLand;
}
}
public void setServerJumpTree(ServerJumpTree jumpTree){
this.jumpTree = jumpTree;
}
public void setAnimationFall(String animationName){
animationFall = animationName;
}
public void setAnimationLand(String animationName){
animationLand = animationName;
}
}