tillable soil
parent
e4007a76ab
commit
95cf571450
BIN
res/textures.png
BIN
res/textures.png
Binary file not shown.
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
|
|
@ -22,6 +22,10 @@ public class Vector4f {
|
||||||
public static Vector4f black = new Vector4f(0f, 0f, 0f, 1f);
|
public static Vector4f black = new Vector4f(0f, 0f, 0f, 1f);
|
||||||
public static Vector4f zero = new Vector4f(0f, 0f, 0f, 0f);
|
public static Vector4f zero = new Vector4f(0f, 0f, 0f, 0f);
|
||||||
|
|
||||||
|
public static Vector4f opacity(float w) {
|
||||||
|
return new Vector4f(1, 1, 1, w);
|
||||||
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "(" + this.x + ", " + this.y + ", " + this.z + ", " + this.w + ")";
|
return "(" + this.x + ", " + this.y + ", " + this.z + ", " + this.w + ")";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,15 @@ import xyz.valnet.engine.graphics.Sprite;
|
||||||
import xyz.valnet.engine.math.Vector2i;
|
import xyz.valnet.engine.math.Vector2i;
|
||||||
import xyz.valnet.engine.math.Vector4f;
|
import xyz.valnet.engine.math.Vector4f;
|
||||||
import xyz.valnet.engine.scenegraph.GameObject;
|
import xyz.valnet.engine.scenegraph.GameObject;
|
||||||
|
import xyz.valnet.hadean.gameobjects.worldobjects.FarmPlot;
|
||||||
import xyz.valnet.hadean.gameobjects.worldobjects.Tree;
|
import xyz.valnet.hadean.gameobjects.worldobjects.Tree;
|
||||||
|
import xyz.valnet.hadean.gameobjects.worldobjects.WorldObject;
|
||||||
import xyz.valnet.hadean.interfaces.ITileThing;
|
import xyz.valnet.hadean.interfaces.ITileThing;
|
||||||
|
import xyz.valnet.hadean.interfaces.IWorkable;
|
||||||
import xyz.valnet.hadean.util.Assets;
|
import xyz.valnet.hadean.util.Assets;
|
||||||
import xyz.valnet.hadean.util.Layers;
|
import xyz.valnet.hadean.util.Layers;
|
||||||
|
|
||||||
public class Tile extends GameObject {
|
public class Tile extends WorldObject implements IWorkable {
|
||||||
|
|
||||||
private Camera camera;
|
private Camera camera;
|
||||||
|
|
||||||
|
|
@ -53,6 +56,10 @@ public class Tile extends GameObject {
|
||||||
if(thing instanceof GameObject) {
|
if(thing instanceof GameObject) {
|
||||||
add((GameObject)thing);
|
add((GameObject)thing);
|
||||||
}
|
}
|
||||||
|
if(thing instanceof FarmPlot) {
|
||||||
|
desiredTill = true;
|
||||||
|
get(JobBoard.class).postJob(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -74,10 +81,17 @@ public class Tile extends GameObject {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
|
if(tillLevel < 1f) {
|
||||||
Assets.flat.pushColor(color);
|
Assets.flat.pushColor(color);
|
||||||
camera.draw(Layers.TILES, sprite, x, y);
|
camera.draw(Layers.TILES, sprite, x, y);
|
||||||
Assets.flat.popColor();
|
Assets.flat.popColor();
|
||||||
}
|
}
|
||||||
|
if(tillLevel > 0f) {
|
||||||
|
Assets.flat.pushColor(Vector4f.opacity(tillLevel));
|
||||||
|
camera.draw(Layers.TILES, Assets.farmPlot, x, y);
|
||||||
|
Assets.flat.popColor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isWalkable() {
|
public boolean isWalkable() {
|
||||||
for(ITileThing thing : stuff) {
|
for(ITileThing thing : stuff) {
|
||||||
|
|
@ -85,4 +99,46 @@ public class Tile extends GameObject {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean desiredTill = false;
|
||||||
|
private float tillLevel = 0;
|
||||||
|
|
||||||
|
public void setTill(boolean till) {
|
||||||
|
desiredTill = till;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasWork() {
|
||||||
|
return desiredTill && tillLevel < 1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vector2i[] getWorkablePositions() {
|
||||||
|
return new Vector2i[] {
|
||||||
|
new Vector2i(x - 1, y - 1),
|
||||||
|
new Vector2i(x, y - 1),
|
||||||
|
new Vector2i(x + 1, y - 1),
|
||||||
|
new Vector2i(x - 1, y + 0),
|
||||||
|
new Vector2i(x, y + 0),
|
||||||
|
new Vector2i(x + 1, y + 0),
|
||||||
|
new Vector2i(x - 1, y + 1),
|
||||||
|
new Vector2i(x, y + 1),
|
||||||
|
new Vector2i(x + 1, y + 1),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vector2i getLocation() {
|
||||||
|
return new Vector2i(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getJobName() {
|
||||||
|
return "Till Soil";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doWork() {
|
||||||
|
tillLevel += 0.005f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,43 +1,40 @@
|
||||||
package xyz.valnet.hadean.gameobjects.worldobjects;
|
package xyz.valnet.hadean.gameobjects.worldobjects;
|
||||||
|
|
||||||
import xyz.valnet.engine.math.Vector2i;
|
|
||||||
import xyz.valnet.engine.math.Vector4f;
|
import xyz.valnet.engine.math.Vector4f;
|
||||||
import xyz.valnet.hadean.gameobjects.JobBoard;
|
|
||||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||||
import xyz.valnet.hadean.interfaces.IBuildable;
|
import xyz.valnet.hadean.interfaces.IBuildable;
|
||||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||||
import xyz.valnet.hadean.interfaces.ITileThing;
|
import xyz.valnet.hadean.interfaces.ITileThing;
|
||||||
import xyz.valnet.hadean.interfaces.IWorkable;
|
|
||||||
import xyz.valnet.hadean.util.Action;
|
import xyz.valnet.hadean.util.Action;
|
||||||
import xyz.valnet.hadean.util.Assets;
|
import xyz.valnet.hadean.util.Assets;
|
||||||
import xyz.valnet.hadean.util.Layers;
|
import xyz.valnet.hadean.util.Layers;
|
||||||
|
|
||||||
@BuildableMetadata(category = "Zones", name = "Farm Plot")
|
@BuildableMetadata(category = "Zones", name = "Farm Plot")
|
||||||
public class FarmPlot extends WorldObject implements IWorkable, ISelectable, ITileThing, IBuildable {
|
public class FarmPlot extends WorldObject implements ISelectable, ITileThing, IBuildable {
|
||||||
|
|
||||||
private float progress = 0f;
|
// private float progress = 0f;
|
||||||
private int stage = 0;
|
// private int stage = 0;
|
||||||
private boolean planted = false;
|
// private boolean planted = false;
|
||||||
private boolean mature = false;
|
// private boolean mature = false;
|
||||||
|
|
||||||
private static int STAGE_LENGTH = 1000;
|
// private static int STAGE_LENGTH = 1000;
|
||||||
private static int MAX_STAGES = 4;
|
// private static int MAX_STAGES = 4;
|
||||||
|
|
||||||
private JobBoard board;
|
// private JobBoard board;
|
||||||
|
|
||||||
private int w, h;
|
private int w, h;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
camera.draw(Layers.TILES, Assets.farmPlot, x, y);
|
// camera.draw(Layers.TILES, Assets.farmPlot, x, y);
|
||||||
|
|
||||||
if(planted) {
|
// if(planted) {
|
||||||
if(stage > 1) {
|
// if(stage > 1) {
|
||||||
camera.draw(Layers.AIR, Assets.growingRice[stage], x, y - 1, 1, 2);
|
// camera.draw(Layers.AIR, Assets.growingRice[stage], x, y - 1, 1, 2);
|
||||||
} else {
|
// } else {
|
||||||
camera.draw(Layers.AIR, Assets.growingRice[stage], x, y);
|
// camera.draw(Layers.AIR, Assets.growingRice[stage], x, y);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -52,24 +49,24 @@ public class FarmPlot extends WorldObject implements IWorkable, ISelectable, ITi
|
||||||
public void update(float dTime) {
|
public void update(float dTime) {
|
||||||
super.update(dTime);
|
super.update(dTime);
|
||||||
|
|
||||||
if(stage == MAX_STAGES - 1) {
|
// if(stage == MAX_STAGES - 1) {
|
||||||
return;
|
// return;
|
||||||
} if(planted) {
|
// } if(planted) {
|
||||||
if(Math.random() > 0.95f) {
|
// if(Math.random() > 0.95f) {
|
||||||
progress += 10;
|
// progress += 10;
|
||||||
if(progress >= STAGE_LENGTH) {
|
// if(progress >= STAGE_LENGTH) {
|
||||||
stage ++;
|
// stage ++;
|
||||||
progress = 0;
|
// progress = 0;
|
||||||
if(stage == MAX_STAGES - 1) {
|
// if(stage == MAX_STAGES - 1) {
|
||||||
mature = true;
|
// mature = true;
|
||||||
board.postJob(this);
|
// board.postJob(this);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
} else if (progress >= STAGE_LENGTH) {
|
// } else if (progress >= STAGE_LENGTH) {
|
||||||
planted = true;
|
// planted = true;
|
||||||
progress = 0;
|
// progress = 0;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -77,34 +74,34 @@ public class FarmPlot extends WorldObject implements IWorkable, ISelectable, ITi
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
super.start();
|
super.start();
|
||||||
board = get(JobBoard.class);
|
// board = get(JobBoard.class);
|
||||||
board.postJob(this);
|
// board.postJob(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public boolean hasWork() {
|
// public boolean hasWork() {
|
||||||
return !planted || mature;
|
// // return !planted || mature;
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public Vector2i[] getWorkablePositions() {
|
// public Vector2i[] getWorkablePositions() {
|
||||||
return new Vector2i[] {
|
// return new Vector2i[] {
|
||||||
new Vector2i((int) x, (int) y + 1),
|
// new Vector2i((int) x, (int) y + 1),
|
||||||
new Vector2i((int) x, (int) y - 1),
|
// new Vector2i((int) x, (int) y - 1),
|
||||||
new Vector2i((int) x + 1, (int) y),
|
// new Vector2i((int) x + 1, (int) y),
|
||||||
new Vector2i((int) x - 1, (int) y)
|
// new Vector2i((int) x - 1, (int) y)
|
||||||
};
|
// };
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public Vector2i getLocation() {
|
// public Vector2i getLocation() {
|
||||||
return new Vector2i((int) x, (int) y);
|
// return new Vector2i((int) x, (int) y);
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public String getJobName() {
|
// public String getJobName() {
|
||||||
return planted ? "Harvest Rice" : "Plant Rice";
|
// return planted ? "Harvest Rice" : "Plant Rice";
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vector4f getWorldBox() {
|
public Vector4f getWorldBox() {
|
||||||
|
|
@ -130,23 +127,21 @@ public class FarmPlot extends WorldObject implements IWorkable, ISelectable, ITi
|
||||||
@Override
|
@Override
|
||||||
public String details() {
|
public String details() {
|
||||||
|
|
||||||
return "Planted | " + planted + "\n" +
|
return "";
|
||||||
"Stage | " + stage + "\n" +
|
|
||||||
"Progress | " + String.format("%.2f", (progress / STAGE_LENGTH) * 100) + "%";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public void doWork() {
|
// public void doWork() {
|
||||||
progress ++;
|
// // progress ++;
|
||||||
if(mature && progress >= STAGE_LENGTH) {
|
// // if(mature && progress >= STAGE_LENGTH) {
|
||||||
mature = false;
|
// // mature = false;
|
||||||
planted = false;
|
// // planted = false;
|
||||||
stage = 0;
|
// // stage = 0;
|
||||||
if(Math.random() < 0.3) {
|
// // if(Math.random() < 0.3) {
|
||||||
getTile().placeThing(new Rice((int)x, (int)y));
|
// // getTile().placeThing(new Rice((int)x, (int)y));
|
||||||
}
|
// // }
|
||||||
}
|
// // }
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWalkable() {
|
public boolean isWalkable() {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import xyz.valnet.engine.math.Vector2i;
|
||||||
public interface IJob {
|
public interface IJob {
|
||||||
public boolean hasWork();
|
public boolean hasWork();
|
||||||
public Vector2i[] getWorkablePositions();
|
public Vector2i[] getWorkablePositions();
|
||||||
|
|
||||||
|
@Deprecated // please use the workable positions.
|
||||||
public Vector2i getLocation();
|
public Vector2i getLocation();
|
||||||
public String getJobName();
|
public String getJobName();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue