|
|
|
@ -18,22 +18,49 @@ import mightypork.util.math.Easing; |
|
|
|
|
*/ |
|
|
|
|
public class Player implements IonBundled, MapObserver, Updateable { |
|
|
|
|
|
|
|
|
|
private final double walktime = 0.3; // possibly make changeable for speed potion
|
|
|
|
|
|
|
|
|
|
private final WorldPos position = new WorldPos(); |
|
|
|
|
private final VectAnimated walkOffset = new VectAnimated(Vect.ZERO, Easing.LINEAR); |
|
|
|
|
private final WorldPos target = new WorldPos(); |
|
|
|
|
private Runnable targetListener; |
|
|
|
|
private Runnable moveListenerCustom; |
|
|
|
|
private Runnable moveListener = new Runnable() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void run() |
|
|
|
|
{ |
|
|
|
|
if (moveListenerCustom != null) moveListenerCustom.run(); |
|
|
|
|
|
|
|
|
|
if (!target.equals(position)) { |
|
|
|
|
|
|
|
|
|
int x = (target.x - position.x); |
|
|
|
|
int y = (target.y - position.y); |
|
|
|
|
|
|
|
|
|
if (Math.abs(x) >= Math.abs(y)) y = 0; |
|
|
|
|
if (Math.abs(y) > Math.abs(x)) x = 0; |
|
|
|
|
|
|
|
|
|
if (x > 0) x = 1; |
|
|
|
|
if (x < 0) x = -1; |
|
|
|
|
|
|
|
|
|
if (y > 0) y = 1; |
|
|
|
|
if (y < 0) y = -1; |
|
|
|
|
|
|
|
|
|
position.walk(x, y, walktime); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Player() |
|
|
|
|
{ |
|
|
|
|
walkOffset.setDefaultDuration(0.25); |
|
|
|
|
position.setMoveListener(moveListener); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Player(int x, int y, int floor) |
|
|
|
|
{ |
|
|
|
|
this.position.setTo(x, y, floor); |
|
|
|
|
this.target.setTo(position); |
|
|
|
|
position.setTo(x, y, floor); |
|
|
|
|
target.setTo(position); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -60,19 +87,12 @@ public class Player implements IonBundled, MapObserver, Updateable { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public WorldPos getLogicalPosition() |
|
|
|
|
public WorldPos getPosition() |
|
|
|
|
{ |
|
|
|
|
return position; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Vect getVisualOffset() |
|
|
|
|
{ |
|
|
|
|
return walkOffset; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int getViewRange() |
|
|
|
|
{ |
|
|
|
@ -84,49 +104,24 @@ public class Player implements IonBundled, MapObserver, Updateable { |
|
|
|
|
{ |
|
|
|
|
position.setTo(pos); |
|
|
|
|
target.setTo(pos); |
|
|
|
|
walkOffset.reset(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void walk(int offsetX, int offsetY) |
|
|
|
|
{ |
|
|
|
|
this.target.setTo(position.x + offsetX, position.y + offsetY, this.position.floor); |
|
|
|
|
target.setTo(position.x + offsetX, position.y + offsetY, this.position.floor); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void update(double delta) |
|
|
|
|
{ |
|
|
|
|
if (!walkOffset.isFinished()) { |
|
|
|
|
walkOffset.update(delta); |
|
|
|
|
if (walkOffset.isFinished()) { |
|
|
|
|
position.add(walkOffset.xi(), walkOffset.yi(), position.floor); |
|
|
|
|
walkOffset.reset(); |
|
|
|
|
targetListener.run(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (walkOffset.isFinished() && !target.equals(position)) { |
|
|
|
|
|
|
|
|
|
int x = (target.x - position.x); |
|
|
|
|
int y = (target.y - position.y); |
|
|
|
|
|
|
|
|
|
if (Math.abs(x) >= Math.abs(y)) y = 0; |
|
|
|
|
if (Math.abs(y) > Math.abs(x)) x = 0; |
|
|
|
|
|
|
|
|
|
if (x > 0) x = 1; |
|
|
|
|
if (x < 0) x = -1; |
|
|
|
|
|
|
|
|
|
if (y > 0) y = 1; |
|
|
|
|
if (y < 0) y = -1; |
|
|
|
|
|
|
|
|
|
walkOffset.animate(x, y, 0); |
|
|
|
|
} |
|
|
|
|
position.update(delta); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setTargetListener(Runnable r) |
|
|
|
|
public void setMoveListener(Runnable r) |
|
|
|
|
{ |
|
|
|
|
this.targetListener = r; |
|
|
|
|
this.moveListenerCustom = r; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|