Refactor speed-related methods to support 1/s unit rather than 1/frame
This commit is contained in:
@@ -28,8 +28,8 @@ public class BulletAnimationRunner implements AnimationRunner {
|
||||
private Integer repeat = 1;
|
||||
private float scale = 1.0f;
|
||||
private int delay = 0;
|
||||
private float animationSpeed = 0.05f;
|
||||
private float speed = 0.05f;
|
||||
private float animationSpeed = 3f;
|
||||
private float speed = 3f;
|
||||
private float rotation = 0f;
|
||||
private Direction direction;
|
||||
private Path<Animation> path;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class RandomAnimationsRunner implements AnimationRunner {
|
||||
private float delay = 0f;
|
||||
private RealDistribution delayDistribution;
|
||||
|
||||
private float animationSpeed = 0.05f;
|
||||
private float animationSpeed = 3f;
|
||||
private RealDistribution animationSpeedDistribution;
|
||||
|
||||
private float rotation = 0f;
|
||||
|
||||
@@ -13,8 +13,8 @@ public class SimpleAnimationRunner implements AnimationRunner {
|
||||
private Integer repeat = 1;
|
||||
private float scale = 1.0f;
|
||||
private int delay = 0;
|
||||
private float animationSpeed = 0.05f;
|
||||
private float speed = 0.05f;
|
||||
private float animationSpeed = 3f;
|
||||
private float speed = 3f;
|
||||
private float rotation = 0f;
|
||||
private Path<Animation> path;
|
||||
private Integer repeatPath;
|
||||
|
||||
@@ -54,8 +54,8 @@ public class DefaultGameEngine implements GameEngine {
|
||||
chrono.init();
|
||||
|
||||
initializables.stream()
|
||||
.peek(i -> log.info("Initializing {}", i.getClass().getSimpleName()))
|
||||
.forEach(Initializable::init);
|
||||
.peek(i -> log.info("Initializing {}", i.getClass().getSimpleName()))
|
||||
.forEach(Initializable::init);
|
||||
|
||||
logic.init(screen, context);
|
||||
}
|
||||
@@ -122,16 +122,7 @@ public class DefaultGameEngine implements GameEngine {
|
||||
running = false;
|
||||
}
|
||||
|
||||
// TODO
|
||||
// It is supposed to be moved to the Context so that
|
||||
// user will be able to choose default window size,
|
||||
// as well as further possibility to resize the window
|
||||
// or forcing fullscreen mode.
|
||||
// Until it's not implemented yet, the window width and height
|
||||
// are hardcoded right here.
|
||||
//
|
||||
// The same applies for target UPS (updates per second) parameter.
|
||||
private static final int WINDOW_WIDTH = 640;
|
||||
private static final int WINDOW_HEIGHT = 480;
|
||||
private static final int TARGET_UPS = 60;
|
||||
public static final int TARGET_UPS = 60;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.bartlomiejpluta.base.engine.world.animation.model;
|
||||
|
||||
import com.bartlomiejpluta.base.api.animation.Animated;
|
||||
import com.bartlomiejpluta.base.engine.core.engine.DefaultGameEngine;
|
||||
import com.bartlomiejpluta.base.engine.core.gl.object.material.Material;
|
||||
import com.bartlomiejpluta.base.engine.core.gl.object.mesh.Mesh;
|
||||
import com.bartlomiejpluta.base.engine.world.location.LocationableSprite;
|
||||
@@ -27,7 +28,7 @@ public abstract class AnimatedSprite extends LocationableSprite implements Anima
|
||||
|
||||
@Override
|
||||
public void setAnimationSpeed(float speed) {
|
||||
intervalInMilliseconds = (int) (1 / MathUtil.clamp(speed, Float.MIN_VALUE, 1.0));
|
||||
intervalInMilliseconds = (int) (1 / MathUtil.clamp(speed / DefaultGameEngine.TARGET_UPS, Float.MIN_VALUE, 1.0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.bartlomiejpluta.base.engine.world.movement;
|
||||
|
||||
import com.bartlomiejpluta.base.api.move.Movable;
|
||||
import com.bartlomiejpluta.base.api.move.Movement;
|
||||
import com.bartlomiejpluta.base.engine.core.engine.DefaultGameEngine;
|
||||
import com.bartlomiejpluta.base.engine.core.gl.object.material.Material;
|
||||
import com.bartlomiejpluta.base.engine.core.gl.object.mesh.Mesh;
|
||||
import com.bartlomiejpluta.base.engine.world.animation.model.AnimatedSprite;
|
||||
@@ -38,7 +39,7 @@ public abstract class MovableSprite extends AnimatedSprite implements Movable, U
|
||||
|
||||
@Override
|
||||
public void setSpeed(float speed) {
|
||||
framesToCrossOneTile = (int) (1 / MathUtil.clamp(speed, Float.MIN_VALUE, 1.0));
|
||||
framesToCrossOneTile = (int) (1 / MathUtil.clamp(speed / DefaultGameEngine.TARGET_UPS, Float.MIN_VALUE, 1.0));
|
||||
}
|
||||
|
||||
protected abstract void setDefaultAnimationFrame();
|
||||
@@ -81,7 +82,7 @@ public abstract class MovableSprite extends AnimatedSprite implements Movable, U
|
||||
|
||||
if (movement != null) {
|
||||
if (moveTime > 0) {
|
||||
--moveTime;
|
||||
moveTime -= dt;
|
||||
movePosition(movementVector);
|
||||
} else {
|
||||
adjustCoordinates();
|
||||
|
||||
Reference in New Issue
Block a user