diff --git a/core/src/main/java/jgd/platformer/gameplay/logic/signal/consumer/ModelTranslateOnSignalSystem.java b/core/src/main/java/jgd/platformer/gameplay/logic/signal/consumer/ModelTranslateOnSignalSystem.java index 2d8337c..0b75bbf 100644 --- a/core/src/main/java/jgd/platformer/gameplay/logic/signal/consumer/ModelTranslateOnSignalSystem.java +++ b/core/src/main/java/jgd/platformer/gameplay/logic/signal/consumer/ModelTranslateOnSignalSystem.java @@ -22,24 +22,22 @@ public class ModelTranslateOnSignalSystem { public void moveEntity(SignalActivated event, EntityRef entityRef, ModelTranslateOnSignalComponent translateOnSignal, BaseLocationComponent baseLocation, LocationComponent location) { long time = timeManager.getTime(); ModelTranslateOverTimeComponent translateOverTime = entityRef.getComponent(ModelTranslateOverTimeComponent.class); - if (translateOverTime == null) { + if (translateOverTime == null) translateOverTime = entityRef.createComponent(ModelTranslateOverTimeComponent.class); - translateOverTime.setDistanceX(translateOnSignal.getDistanceX()); - translateOverTime.setDistanceY(translateOnSignal.getDistanceY()); - translateOverTime.setDistanceZ(translateOnSignal.getDistanceZ()); - translateOverTime.setStartTime(time); - translateOverTime.setMoveTime(translateOnSignal.getMoveTime()); - translateOverTime.setInterpolation(translateOnSignal.getInterpolation()); - translateOverTime.setReverse(false); - } else { - translateOverTime.setDistanceX(translateOnSignal.getDistanceX()); - translateOverTime.setDistanceY(translateOnSignal.getDistanceY()); - translateOverTime.setDistanceZ(translateOnSignal.getDistanceZ()); - translateOverTime.setStartTime(time); - translateOverTime.setMoveTime(translateOnSignal.getMoveTime()); - translateOverTime.setInterpolation(translateOnSignal.getInterpolation()); - translateOverTime.setReverse(false); - } + + translateOverTime.setSourceX(location.getX()); + translateOverTime.setSourceY(location.getY()); + translateOverTime.setSourceZ(location.getZ()); + + translateOverTime.setDestinationX(baseLocation.getX() + translateOnSignal.getDistanceX()); + translateOverTime.setDestinationY(baseLocation.getY() + translateOnSignal.getDistanceY()); + translateOverTime.setDestinationZ(baseLocation.getZ() + translateOnSignal.getDistanceZ()); + + translateOverTime.setStartTime(time); + translateOverTime.setMoveTime(translateOnSignal.getMoveTime()); + + translateOverTime.setInterpolation(translateOnSignal.getInterpolation()); + entityRef.saveChanges(); } @@ -47,24 +45,23 @@ public void moveEntity(SignalActivated event, EntityRef entityRef, ModelTranslat public void moveEntityBack(SignalDeactivated event, EntityRef entityRef, ModelTranslateOnSignalComponent translateOnSignal, BaseLocationComponent baseLocation, LocationComponent location) { long time = timeManager.getTime(); ModelTranslateOverTimeComponent translateOverTime = entityRef.getComponent(ModelTranslateOverTimeComponent.class); - if (translateOverTime == null) { + if (translateOverTime == null) translateOverTime = entityRef.createComponent(ModelTranslateOverTimeComponent.class); - translateOverTime.setDistanceX(translateOnSignal.getDistanceX()); - translateOverTime.setDistanceY(translateOnSignal.getDistanceY()); - translateOverTime.setDistanceZ(translateOnSignal.getDistanceZ()); - translateOverTime.setStartTime(time); - translateOverTime.setMoveTime(translateOnSignal.getMoveTime()); - translateOverTime.setInterpolation(translateOnSignal.getInterpolation()); - translateOverTime.setReverse(true); - } else { - translateOverTime.setDistanceX(translateOnSignal.getDistanceX()); - translateOverTime.setDistanceY(translateOnSignal.getDistanceY()); - translateOverTime.setDistanceZ(translateOnSignal.getDistanceZ()); - translateOverTime.setStartTime(time); - translateOverTime.setMoveTime(translateOnSignal.getMoveTime()); - translateOverTime.setInterpolation(translateOnSignal.getInterpolation()); - translateOverTime.setReverse(true); - } + + translateOverTime.setSourceX(location.getX()); + translateOverTime.setSourceY(location.getY()); + translateOverTime.setSourceZ(location.getZ()); + + translateOverTime.setDestinationX(baseLocation.getX()); + translateOverTime.setDestinationY(baseLocation.getY()); + translateOverTime.setDestinationZ(baseLocation.getZ()); + + translateOverTime.setStartTime(time); + translateOverTime.setMoveTime(translateOnSignal.getMoveTime()); + + translateOverTime.setInterpolation(translateOnSignal.getInterpolation()); + + entityRef.saveChanges(); entityRef.saveChanges(); } } diff --git a/core/src/main/java/jgd/platformer/gameplay/logic/transform/ModelTranslateOverTimeComponent.java b/core/src/main/java/jgd/platformer/gameplay/logic/transform/ModelTranslateOverTimeComponent.java index b76beeb..a755e55 100644 --- a/core/src/main/java/jgd/platformer/gameplay/logic/transform/ModelTranslateOverTimeComponent.java +++ b/core/src/main/java/jgd/platformer/gameplay/logic/transform/ModelTranslateOverTimeComponent.java @@ -3,31 +3,36 @@ import com.gempukku.secsy.entity.Component; public interface ModelTranslateOverTimeComponent extends Component { - float getDistanceX(); + float getSourceX(); - void setDistanceX(float distanceX); + void setSourceX(float sourceX); - float getDistanceY(); + float getSourceY(); - void setDistanceY(float distanceY); + void setSourceY(float sourceY); - float getDistanceZ(); + float getSourceZ(); - void setDistanceZ(float distanceZ); + void setSourceZ(float sourceZ); - long getStartTime(); + float getDestinationX(); + + void setDestinationX(float destinationX); + + float getDestinationY(); + + void setDestinationY(float destinationY); + + float getDestinationZ(); + + void setDestinationZ(float destinationZ); + long getStartTime(); void setStartTime(long startTime); long getMoveTime(); - void setMoveTime(long moveTime); String getInterpolation(); - void setInterpolation(String interpolation); - - boolean isReverse(); - - void setReverse(boolean reverse); } diff --git a/core/src/main/java/jgd/platformer/gameplay/logic/transform/ModelTranslateSystem.java b/core/src/main/java/jgd/platformer/gameplay/logic/transform/ModelTranslateSystem.java index 746db90..956e0a8 100644 --- a/core/src/main/java/jgd/platformer/gameplay/logic/transform/ModelTranslateSystem.java +++ b/core/src/main/java/jgd/platformer/gameplay/logic/transform/ModelTranslateSystem.java @@ -90,11 +90,9 @@ public void translateModels(GameLoopUpdate event, EntityRef entityRef) { translateOverTimeEntity.removeComponents(ModelTranslateOverTimeComponent.class); a = 1; } - if (translate.isReverse()) - a = 1 - a; - location.setX(baseLocation.getX() + a * translate.getDistanceX()); - location.setY(baseLocation.getY() + a * translate.getDistanceY()); - location.setZ(baseLocation.getZ() + a * translate.getDistanceZ()); + location.setX(translate.getSourceX() + a * (translate.getDestinationX() - translate.getSourceX())); + location.setY(translate.getSourceY() + a * (translate.getDestinationY() - translate.getSourceY())); + location.setZ(translate.getSourceZ() + a * (translate.getDestinationZ() - translate.getSourceZ())); translateOverTimeEntity.saveChanges(); }