some QoL stuff
parent
7fa2648a9a
commit
e869abf9fb
|
|
@ -27,4 +27,10 @@ public class Vector2i {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float distanceTo(int x, int y) {
|
||||||
|
int a = this.x - x;
|
||||||
|
int b = this.y - y;
|
||||||
|
return (float) Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ public class Tile extends GameObject {
|
||||||
public void start() {
|
public void start() {
|
||||||
camera = get(Camera.class);
|
camera = get(Camera.class);
|
||||||
|
|
||||||
if(Math.random() > 0.98) {
|
if(Math.random() > 0.90) {
|
||||||
Tree tree = new Tree(x, y);
|
Tree tree = new Tree(x, y);
|
||||||
stuff.add(tree);
|
stuff.add(tree);
|
||||||
add(tree);
|
add(tree);
|
||||||
|
|
|
||||||
|
|
@ -6,4 +6,5 @@ public interface IWorkable {
|
||||||
public boolean hasWork();
|
public boolean hasWork();
|
||||||
public Vector2i[] getWorablePositions();
|
public Vector2i[] getWorablePositions();
|
||||||
public void doWork();
|
public void doWork();
|
||||||
|
public Vector2i getLocation();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import static org.lwjgl.opengl.GL11.glVertex3f;
|
||||||
import static org.lwjgl.opengl.GL20.glVertexAttrib2f;
|
import static org.lwjgl.opengl.GL20.glVertexAttrib2f;
|
||||||
import static xyz.valnet.engine.util.Math.lerp;
|
import static xyz.valnet.engine.util.Math.lerp;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import xyz.valnet.engine.graphics.Drawing;
|
import xyz.valnet.engine.graphics.Drawing;
|
||||||
|
|
@ -31,7 +32,7 @@ public class Pawn extends GameObject implements ISelectable {
|
||||||
|
|
||||||
private Path path;
|
private Path path;
|
||||||
|
|
||||||
private final float invocationThreshold = 70f;
|
private final float invocationThreshold = 50 + (float)(Math.random() * 20);
|
||||||
|
|
||||||
private Camera camera;
|
private Camera camera;
|
||||||
private Terrain terrain;
|
private Terrain terrain;
|
||||||
|
|
@ -88,11 +89,6 @@ public class Pawn extends GameObject implements ISelectable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick(float dTime) {
|
public void tick(float dTime) {
|
||||||
// firstly, TRY PATHING.
|
|
||||||
if(path != null && !path.isComplete()) {
|
|
||||||
move();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// then, try to do work!
|
// then, try to do work!
|
||||||
if(currentJob != null && currentJob.hasWork()) {
|
if(currentJob != null && currentJob.hasWork()) {
|
||||||
|
|
@ -102,12 +98,22 @@ public class Pawn extends GameObject implements ISelectable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// firstly, TRY PATHING.
|
||||||
|
if(path != null && !path.isComplete()) {
|
||||||
|
move();
|
||||||
|
}
|
||||||
|
|
||||||
// then try to get work?!
|
// then try to get work?!
|
||||||
|
if(counter == 0) {
|
||||||
currentJob = null;
|
currentJob = null;
|
||||||
tryStartWork();
|
tryStartWork();
|
||||||
|
|
||||||
|
|
||||||
|
if(currentJob == null && (path == null || path.isComplete())) {
|
||||||
// then wander...
|
// then wander...
|
||||||
|
newPath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,6 +125,18 @@ public class Pawn extends GameObject implements ISelectable {
|
||||||
|
|
||||||
private void tryStartWork() {
|
private void tryStartWork() {
|
||||||
List<IWorkable> workables = getAll(IWorkable.class);
|
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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if(workables.size() > 0) {
|
if(workables.size() > 0) {
|
||||||
for(IWorkable job : workables) {
|
for(IWorkable job : workables) {
|
||||||
if(!job.hasWork()) continue;
|
if(!job.hasWork()) continue;
|
||||||
|
|
@ -134,14 +152,15 @@ public class Pawn extends GameObject implements ISelectable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// private void newPath() {
|
private void newPath() {
|
||||||
// // set new destination
|
// set new destination
|
||||||
// dx = 0.5f + (float)Math.floor(Math.random() * Terrain.WORLD_SIZE);
|
int randomX = (int)Math.floor(Math.random() * Terrain.WORLD_SIZE);
|
||||||
// dy = 0.5f + (float)Math.floor(Math.random() * Terrain.WORLD_SIZE);
|
int randomY = (int)Math.floor(Math.random() * Terrain.WORLD_SIZE);
|
||||||
|
path = pathfinder.getPath((int)x, (int)y, randomX, randomY);
|
||||||
|
|
||||||
// // and route there.
|
// // and route there.
|
||||||
// route();
|
// reroute();
|
||||||
// }
|
}
|
||||||
|
|
||||||
private void reroute() {
|
private void reroute() {
|
||||||
// intify all the coordinates
|
// intify all the coordinates
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,9 @@ public class Tree extends GameObject implements ITileThing, ISelectable, IWorkab
|
||||||
Assets.flat.pushColor(new Vector4f(1 - getProgress(), 1 - getProgress(), 1 - getProgress(), 1.0f));
|
Assets.flat.pushColor(new Vector4f(1 - getProgress(), 1 - getProgress(), 1 - getProgress(), 1.0f));
|
||||||
camera.draw(Assets.tree, x - 1, y - 2, 3, 3);
|
camera.draw(Assets.tree, x - 1, y - 2, 3, 3);
|
||||||
Assets.flat.popColor();
|
Assets.flat.popColor();
|
||||||
|
if(hasWork()) {
|
||||||
|
camera.draw(Assets.lilAxe, x, y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -38,7 +41,7 @@ public class Tree extends GameObject implements ITileThing, ISelectable, IWorkab
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vector4f getWorldBox() {
|
public Vector4f getWorldBox() {
|
||||||
return new Vector4f(x - 1, y - 2, x + 2, y + 1);
|
return new Vector4f(x, y, x + 1, y + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Action ACTION_CHOP = new Action("Chop");
|
public static final Action ACTION_CHOP = new Action("Chop");
|
||||||
|
|
@ -112,4 +115,9 @@ public class Tree extends GameObject implements ITileThing, ISelectable, IWorkab
|
||||||
public void onRemove() {
|
public void onRemove() {
|
||||||
add(new Log(x, y));
|
add(new Log(x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vector2i getLocation() {
|
||||||
|
return new Vector2i(x, y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ public class GameScene implements IScene {
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
objects.add(new Terrain());
|
objects.add(new Terrain());
|
||||||
for(int i = 0; i < 1; i ++) {
|
for(int i = 0; i < 5; i ++) {
|
||||||
objects.add(new Pawn());
|
objects.add(new Pawn());
|
||||||
}
|
}
|
||||||
objects.add(new Camera());
|
objects.add(new Camera());
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ public class Assets {
|
||||||
public static final Sprite tree;
|
public static final Sprite tree;
|
||||||
public static final Sprite rocks;
|
public static final Sprite rocks;
|
||||||
public static final Sprite log;
|
public static final Sprite log;
|
||||||
|
public static final Sprite lilAxe;
|
||||||
|
|
||||||
public static final SimpleShader flat;
|
public static final SimpleShader flat;
|
||||||
|
|
||||||
|
|
@ -47,6 +48,7 @@ public class Assets {
|
||||||
tree = new Sprite(atlas, 64, 64, 24, 24);
|
tree = new Sprite(atlas, 64, 64, 24, 24);
|
||||||
rocks = new Sprite(atlas, 64, 104, 8, 8);
|
rocks = new Sprite(atlas, 64, 104, 8, 8);
|
||||||
log = new Sprite(atlas, 48, 96, 16, 16);
|
log = new Sprite(atlas, 48, 96, 16, 16);
|
||||||
|
lilAxe = new Sprite(atlas, 64, 88, 16, 16);
|
||||||
|
|
||||||
Map<Character, Sprite> charset = new HashMap<Character, Sprite>();
|
Map<Character, Sprite> charset = new HashMap<Character, Sprite>();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue