diff --git a/res/textures.png b/res/textures.png index c7a9111..e5324a9 100644 Binary files a/res/textures.png and b/res/textures.png differ diff --git a/src/main/java/xyz/valnet/engine/math/Vector4f.java b/src/main/java/xyz/valnet/engine/math/Vector4f.java index b4b2e4a..fb1bd3a 100644 --- a/src/main/java/xyz/valnet/engine/math/Vector4f.java +++ b/src/main/java/xyz/valnet/engine/math/Vector4f.java @@ -22,6 +22,10 @@ public class Vector4f { public static Vector4f black = new Vector4f(0f, 0f, 0f, 1f); 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() { return "(" + this.x + ", " + this.y + ", " + this.z + ", " + this.w + ")"; } diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/Tile.java b/src/main/java/xyz/valnet/hadean/gameobjects/Tile.java index 7bde8ee..f7e614a 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/Tile.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/Tile.java @@ -7,12 +7,15 @@ import xyz.valnet.engine.graphics.Sprite; import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector4f; 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.WorldObject; import xyz.valnet.hadean.interfaces.ITileThing; +import xyz.valnet.hadean.interfaces.IWorkable; import xyz.valnet.hadean.util.Assets; import xyz.valnet.hadean.util.Layers; -public class Tile extends GameObject { +public class Tile extends WorldObject implements IWorkable { private Camera camera; @@ -53,6 +56,10 @@ public class Tile extends GameObject { if(thing instanceof GameObject) { add((GameObject)thing); } + if(thing instanceof FarmPlot) { + desiredTill = true; + get(JobBoard.class).postJob(this); + } } @Override @@ -74,9 +81,16 @@ public class Tile extends GameObject { @Override public void render() { - Assets.flat.pushColor(color); - camera.draw(Layers.TILES, sprite, x, y); - Assets.flat.popColor(); + if(tillLevel < 1f) { + Assets.flat.pushColor(color); + camera.draw(Layers.TILES, sprite, x, y); + 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() { @@ -85,4 +99,46 @@ public class Tile extends GameObject { } 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; + } } diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/FarmPlot.java b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/FarmPlot.java index afe9394..b8cce3c 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/FarmPlot.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/FarmPlot.java @@ -1,43 +1,40 @@ package xyz.valnet.hadean.gameobjects.worldobjects; -import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector4f; -import xyz.valnet.hadean.gameobjects.JobBoard; import xyz.valnet.hadean.interfaces.BuildableMetadata; import xyz.valnet.hadean.interfaces.IBuildable; import xyz.valnet.hadean.interfaces.ISelectable; import xyz.valnet.hadean.interfaces.ITileThing; -import xyz.valnet.hadean.interfaces.IWorkable; import xyz.valnet.hadean.util.Action; import xyz.valnet.hadean.util.Assets; import xyz.valnet.hadean.util.Layers; @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 int stage = 0; - private boolean planted = false; - private boolean mature = false; + // private float progress = 0f; + // private int stage = 0; + // private boolean planted = false; + // private boolean mature = false; - private static int STAGE_LENGTH = 1000; - private static int MAX_STAGES = 4; + // private static int STAGE_LENGTH = 1000; + // private static int MAX_STAGES = 4; - private JobBoard board; + // private JobBoard board; private int w, h; @Override public void render() { - camera.draw(Layers.TILES, Assets.farmPlot, x, y); + // camera.draw(Layers.TILES, Assets.farmPlot, x, y); - if(planted) { - if(stage > 1) { - camera.draw(Layers.AIR, Assets.growingRice[stage], x, y - 1, 1, 2); - } else { - camera.draw(Layers.AIR, Assets.growingRice[stage], x, y); - } - } + // if(planted) { + // if(stage > 1) { + // camera.draw(Layers.AIR, Assets.growingRice[stage], x, y - 1, 1, 2); + // } else { + // camera.draw(Layers.AIR, Assets.growingRice[stage], x, y); + // } + // } } @Override @@ -52,24 +49,24 @@ public class FarmPlot extends WorldObject implements IWorkable, ISelectable, ITi public void update(float dTime) { super.update(dTime); - if(stage == MAX_STAGES - 1) { - return; - } if(planted) { - if(Math.random() > 0.95f) { - progress += 10; - if(progress >= STAGE_LENGTH) { - stage ++; - progress = 0; - if(stage == MAX_STAGES - 1) { - mature = true; - board.postJob(this); - } - } - } - } else if (progress >= STAGE_LENGTH) { - planted = true; - progress = 0; - } + // if(stage == MAX_STAGES - 1) { + // return; + // } if(planted) { + // if(Math.random() > 0.95f) { + // progress += 10; + // if(progress >= STAGE_LENGTH) { + // stage ++; + // progress = 0; + // if(stage == MAX_STAGES - 1) { + // mature = true; + // board.postJob(this); + // } + // } + // } + // } else if (progress >= STAGE_LENGTH) { + // planted = true; + // progress = 0; + // } } @@ -77,34 +74,34 @@ public class FarmPlot extends WorldObject implements IWorkable, ISelectable, ITi @Override public void start() { super.start(); - board = get(JobBoard.class); - board.postJob(this); + // board = get(JobBoard.class); + // board.postJob(this); } - @Override - public boolean hasWork() { - return !planted || mature; - } + // @Override + // public boolean hasWork() { + // // return !planted || mature; + // } - @Override - public Vector2i[] getWorkablePositions() { - return new Vector2i[] { - 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) - }; - } + // @Override + // public Vector2i[] getWorkablePositions() { + // return new Vector2i[] { + // 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) + // }; + // } - @Override - public Vector2i getLocation() { - return new Vector2i((int) x, (int) y); - } + // @Override + // public Vector2i getLocation() { + // return new Vector2i((int) x, (int) y); + // } - @Override - public String getJobName() { - return planted ? "Harvest Rice" : "Plant Rice"; - } + // @Override + // public String getJobName() { + // return planted ? "Harvest Rice" : "Plant Rice"; + // } @Override public Vector4f getWorldBox() { @@ -130,23 +127,21 @@ public class FarmPlot extends WorldObject implements IWorkable, ISelectable, ITi @Override public String details() { - return "Planted | " + planted + "\n" + - "Stage | " + stage + "\n" + - "Progress | " + String.format("%.2f", (progress / STAGE_LENGTH) * 100) + "%"; + return ""; } - @Override - public void doWork() { - progress ++; - if(mature && progress >= STAGE_LENGTH) { - mature = false; - planted = false; - stage = 0; - if(Math.random() < 0.3) { - getTile().placeThing(new Rice((int)x, (int)y)); - } - } - } + // @Override + // public void doWork() { + // // progress ++; + // // if(mature && progress >= STAGE_LENGTH) { + // // mature = false; + // // planted = false; + // // stage = 0; + // // if(Math.random() < 0.3) { + // // getTile().placeThing(new Rice((int)x, (int)y)); + // // } + // // } + // } @Override public boolean isWalkable() { diff --git a/src/main/java/xyz/valnet/hadean/interfaces/IJob.java b/src/main/java/xyz/valnet/hadean/interfaces/IJob.java index 5339038..5e98bbe 100644 --- a/src/main/java/xyz/valnet/hadean/interfaces/IJob.java +++ b/src/main/java/xyz/valnet/hadean/interfaces/IJob.java @@ -5,6 +5,8 @@ import xyz.valnet.engine.math.Vector2i; public interface IJob { public boolean hasWork(); public Vector2i[] getWorkablePositions(); + + @Deprecated // please use the workable positions. public Vector2i getLocation(); public String getJobName(); }