|
@@ -38,21 +38,28 @@ public class GDInstance {
|
|
public Model getFrameOnPercent(double percent) {
|
|
public Model getFrameOnPercent(double percent) {
|
|
double usablePercent = percent - (start / 100);
|
|
double usablePercent = percent - (start / 100);
|
|
if (usablePercent > 0) {
|
|
if (usablePercent > 0) {
|
|
- float max = LevelInfo.getLevel().getMaxPos();
|
|
|
|
- double speed = LevelInfo.getLevel().getSpeedAt((float) percent);
|
|
|
|
- //Animation length in second
|
|
|
|
- //TODO: MAKE THIS WORK + add a function to convert percentage to time with correct estimation pf speed (
|
|
|
|
- double fullTime = (double) animationObject.getFrames().size() / 24;
|
|
|
|
- int frame = 0;
|
|
|
|
- if (!(frame > animationObject.getModelFrames().size() - 1)) {
|
|
|
|
- System.out.println(frame);
|
|
|
|
- return animationObject.getModelFrames().get(frame);
|
|
|
|
|
|
+ float max = LevelInfo.getLevel().getMaxPos(); // Max distance
|
|
|
|
+ double pos = max * usablePercent; // Position based on percent traveled
|
|
|
|
+ double speed = LevelInfo.getLevel().getSpeedAt((float) percent); // Speed at the current position
|
|
|
|
+
|
|
|
|
+ // Calculate the distance per frame
|
|
|
|
+ double distancePerFrame = (speed / fps) * 10; // Speed divided by FPS gives distance per frame
|
|
|
|
+
|
|
|
|
+ // Calculate the current frame
|
|
|
|
+ int frame = (int) (pos / distancePerFrame); // Position divided by distance per frame
|
|
|
|
+
|
|
|
|
+ System.out.println(pos + " - " + frame);
|
|
|
|
+
|
|
|
|
+ // Ensure the frame is within bounds
|
|
|
|
+ if (frame < animationObject.getModelFrames().size()) {
|
|
|
|
+ return animationObject.getModelFrames().get(frame); // Return the correct frame
|
|
}
|
|
}
|
|
- return animationObject.getModelFrames().getLast();
|
|
|
|
|
|
+ return animationObject.getModelFrames().getLast(); // If out of bounds, return last frame
|
|
}
|
|
}
|
|
- return animationObject.getModelFrames().getFirst();
|
|
|
|
|
|
+ return animationObject.getModelFrames().getFirst(); // If no progress, return first frame
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
private ModelInstance instance;
|
|
private ModelInstance instance;
|
|
private boolean animation;
|
|
private boolean animation;
|
|
private double start;
|
|
private double start;
|