more job related things
parent
47099b3057
commit
d8352fbc9a
|
|
@ -0,0 +1,8 @@
|
|||
package xyz.valnet.hadean.gameobjects;
|
||||
|
||||
import xyz.valnet.hadean.Tile;
|
||||
|
||||
public interface IHaulable extends IJob {
|
||||
public Log take();
|
||||
public Tile getDestination();
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package xyz.valnet.hadean.gameobjects;
|
||||
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
|
||||
public interface IJob {
|
||||
public boolean hasWork();
|
||||
public Vector2i[] getWorablePositions();
|
||||
public Vector2i getLocation();
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
package xyz.valnet.hadean.gameobjects;
|
||||
|
||||
public interface ITransferrable {
|
||||
|
||||
}
|
||||
|
|
@ -1,10 +1,5 @@
|
|||
package xyz.valnet.hadean.gameobjects;
|
||||
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
|
||||
public interface IWorkable {
|
||||
public boolean hasWork();
|
||||
public Vector2i[] getWorablePositions();
|
||||
public interface IWorkable extends IJob {
|
||||
public void doWork();
|
||||
public Vector2i getLocation();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,12 +8,14 @@ import xyz.valnet.hadean.Layers;
|
|||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
|
||||
public class Log extends GameObject implements ITileThing, ISelectable, ITransferrable, IWorkable {
|
||||
public class Log extends GameObject implements ITileThing, ISelectable, IHaulable, IWorkable {
|
||||
|
||||
private Camera camera;
|
||||
|
||||
private int x, y;
|
||||
|
||||
private boolean haul = false;
|
||||
|
||||
public Log(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
|
@ -28,6 +30,10 @@ public class Log extends GameObject implements ITileThing, ISelectable, ITransfe
|
|||
public void render() {
|
||||
Drawing.setLayer(Layers.GROUND);
|
||||
camera.draw(Assets.log, x, y);
|
||||
if(haul) {
|
||||
Drawing.setLayer(Layers.MARKERS);
|
||||
camera.draw(Assets.haulArrow, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import xyz.valnet.hadean.util.Assets;
|
|||
|
||||
public class Pawn extends GameObject implements ISelectable {
|
||||
|
||||
private ITransferrable carrying = null;
|
||||
private IHaulable carrying = null;
|
||||
|
||||
private float x = 0.5f + (int)(Math.random() * Terrain.WORLD_SIZE), y = 0.5f + (int)(Math.random() * Terrain.WORLD_SIZE);
|
||||
|
||||
|
|
@ -146,18 +146,20 @@ public class Pawn extends GameObject implements ISelectable {
|
|||
private IWorkable currentJob;
|
||||
|
||||
private void tryStartWork() {
|
||||
List<IWorkable> workables = getAll(IWorkable.class);
|
||||
|
||||
workables.sort(new Comparator<IWorkable>() {
|
||||
@Override
|
||||
public int compare(IWorkable a, IWorkable b) {
|
||||
float distA = a.getLocation().distanceTo((int)x, (int)y);
|
||||
float distB = b.getLocation().distanceTo((int)x, (int)y);
|
||||
if(distA > distB) return -1;
|
||||
if(distB > distA) return 1;
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
List<IWorkable> workables = getAll(IWorkable.class)
|
||||
.stream()
|
||||
.filter(workable -> workable.hasWork())
|
||||
.sorted(new Comparator<IWorkable>() {
|
||||
@Override
|
||||
public int compare(IWorkable a, IWorkable b) {
|
||||
float distA = a.getLocation().distanceTo((int)x, (int)y);
|
||||
float distB = b.getLocation().distanceTo((int)x, (int)y);
|
||||
if(distA > distB) return -1;
|
||||
if(distB > distA) return 1;
|
||||
return 0;
|
||||
}
|
||||
})
|
||||
.toList();
|
||||
|
||||
if(workables.size() > 0) {
|
||||
for(IWorkable job : workables) {
|
||||
|
|
|
|||
|
|
@ -64,6 +64,8 @@ public class Selection extends GameObject implements IMouseListener {
|
|||
@Override
|
||||
public void render() {
|
||||
|
||||
Drawing.setLayer(Layers.AREA_SELECT_BOX);
|
||||
|
||||
float t = animation / animationMax;
|
||||
float p = lerp(animationAmplitude, 0, t);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue