agents move normally regardless of framerate
parent
43c035ba5b
commit
e8b94f9900
|
|
@ -27,7 +27,7 @@ import static xyz.valnet.engine.util.Math.lerp;
|
||||||
|
|
||||||
public abstract class Agent extends WorldObject implements ISelectable {
|
public abstract class Agent extends WorldObject implements ISelectable {
|
||||||
public abstract String getName();
|
public abstract String getName();
|
||||||
private int frameCounter = 0;
|
private float frameCounter = 0;
|
||||||
private int speed = 100 + (int)(Math.random() * 50);
|
private int speed = 100 + (int)(Math.random() * 50);
|
||||||
|
|
||||||
private IPathfinder pathfinder;
|
private IPathfinder pathfinder;
|
||||||
|
|
@ -58,14 +58,14 @@ public abstract class Agent extends WorldObject implements ISelectable {
|
||||||
@Override
|
@Override
|
||||||
public void update(float dTime) {
|
public void update(float dTime) {
|
||||||
think();
|
think();
|
||||||
act();
|
act(dTime);
|
||||||
postAct();
|
postAct();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void postAct();
|
protected abstract void postAct();
|
||||||
|
|
||||||
private void move() {
|
private void move(float dTime) {
|
||||||
frameCounter++;
|
frameCounter += dTime;
|
||||||
if(frameCounter >= speed) {
|
if(frameCounter >= speed) {
|
||||||
Vector2i nextPos = path.pop().getPosition();
|
Vector2i nextPos = path.pop().getPosition();
|
||||||
this.x = nextPos.x;
|
this.x = nextPos.x;
|
||||||
|
|
@ -75,7 +75,7 @@ public abstract class Agent extends WorldObject implements ISelectable {
|
||||||
nextPath = null;
|
nextPath = null;
|
||||||
}
|
}
|
||||||
if(path.isComplete()) path = null;
|
if(path.isComplete()) path = null;
|
||||||
frameCounter = 0;
|
frameCounter -= speed;
|
||||||
if(stopPathingFlag) {
|
if(stopPathingFlag) {
|
||||||
path = null;
|
path = null;
|
||||||
nextPath = null;
|
nextPath = null;
|
||||||
|
|
@ -112,9 +112,9 @@ public abstract class Agent extends WorldObject implements ISelectable {
|
||||||
correctPath();
|
correctPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean act() {
|
protected boolean act(float dTime) {
|
||||||
if(path != null) {
|
if(path != null) {
|
||||||
move();
|
move(dTime);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,7 +127,7 @@ public abstract class Agent extends WorldObject implements ISelectable {
|
||||||
Path newPath = pathfinder.getPath((int)this.x, (int)this.y, x, y);
|
Path newPath = pathfinder.getPath((int)this.x, (int)this.y, x, y);
|
||||||
if(path == null) {
|
if(path == null) {
|
||||||
path = newPath;
|
path = newPath;
|
||||||
frameCounter = 0;
|
frameCounter -= 0;
|
||||||
} else {
|
} else {
|
||||||
nextPath = newPath;
|
nextPath = newPath;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue