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