progress bars, minor balance changes

world-object-unification-project
Ivory 2023-01-04 05:06:53 -05:00
parent 1af8f12a99
commit afba135b7e
8 changed files with 55 additions and 10 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -54,4 +54,8 @@ public class Vector4f implements Serializable {
);
}
public Vector4i asInt() {
return new Vector4i((int)x, (int)y, (int)z, (int)w);
}
}

View File

@ -1,11 +1,16 @@
package xyz.valnet.hadean.gameobjects;
import static xyz.valnet.engine.util.Math.lerp;
import xyz.valnet.engine.graphics.Drawing;
import xyz.valnet.engine.graphics.Sprite;
import xyz.valnet.engine.math.Vector2f;
import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.engine.math.Vector4i;
import xyz.valnet.engine.scenegraph.GameObject;
import xyz.valnet.hadean.interfaces.IWorldBoundsAdapter;
import xyz.valnet.hadean.util.Assets;
import xyz.valnet.hadean.util.Layers;
public class Camera extends GameObject {
@ -76,5 +81,16 @@ public class Camera extends GameObject {
Drawing.setLayer(layer + (((y + h) - minY) / (maxY - minY)));
Drawing.drawSprite(sprite, (int)(screenPos.x), (int)(screenPos.y), (int)(tileWidth * w), (int)(tileWidth * h));
}
public void drawProgressBar(float progress, Vector4f worldBox) {
int h = 6;
Vector4i box = world2Screen(worldBox).toXYWH().asInt();
Drawing.setLayer(Layers.GENERAL_UI);
Assets.flat.pushColor(new Vector4f(0, 0, 0, 1));
Assets.uiFrame.draw(box.x - h, box.y + box.w / 2 - h / 2, box.z + h * 2, h);
Assets.flat.swapColor(new Vector4f(1, 1, 0, 1));
Assets.fillColor.draw(box.x + 1 - h, box.y + 1 + box.w / 2 - h / 2, (int)Math.round(lerp(0, box.z - 3 + h * 2, progress)) + 1, h - 2);
Assets.flat.popColor();
}
}

View File

@ -12,7 +12,7 @@ public class Clock extends GameObject {
@Override
public void update(float dTime) {
time += 0.0004f;
time += 0.0002f * dTime;
while (time >= 24) time -= 24;
}

View File

@ -1,7 +1,5 @@
package xyz.valnet.hadean.gameobjects.worldobjects;
import static xyz.valnet.engine.util.Math.lerp;
import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.hadean.gameobjects.Job;
@ -44,12 +42,22 @@ public class Bed extends WorldObject implements IBuildable, IItemReceiver, IWork
@Override
public void render() {
super.render();
if(isBuilt()) {
camera.draw(Layers.GROUND, Assets.bed, (int)x, (int)y, 1, 2);
} else {
Assets.flat.pushColor(Vector4f.opacity(lerp(0.5f, 1.0f, work / maxWork)));
float p = work / maxWork;
float b = 4;
Assets.flat.pushColor(new Vector4f(b, b, b, 0.5f));
camera.draw(Layers.GROUND, Assets.bed, (int)x, (int)y, 1, 2);
Assets.flat.popColor();
if(logs > 0) {
camera.drawProgressBar(p, getWorldBox());
}
// Assets.uiFrame.draw(box.x -3, box.y - 6, (int)Math.round(lerp(0, box.z + 6, p)), 4);
}
}
@ -133,7 +141,7 @@ public class Bed extends WorldObject implements IBuildable, IItemReceiver, IWork
public Detail[] getDetails() {
return new Detail[] {
new BooleanDetail("Built", isBuilt()),
new PercentDetail("Work", work / maxWork),
new PercentDetail("Work", work / maxWork, 1),
new ObjectDetail<Integer>("Logs", logs),
};
}

View File

@ -30,10 +30,13 @@ public class Tree extends WorldObject implements ITileThing, ISelectable, IWorka
@Override
public void render() {
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(Layers.AIR, Assets.tree, x - 1, y - 2, 3, 3);
Assets.flat.popColor();
// Assets.flat.popColor();
if(chopJob != null) {
if(getProgress() > 0) {
camera.drawProgressBar(getProgress(), new Vector4f(x - 1, y - 2, x + 2, y + 1));
}
camera.draw(Layers.MARKERS, Assets.lilAxe, x, y);
}
}

View File

@ -56,9 +56,9 @@ public abstract class Item extends WorldObject implements ISelectable, ITileThin
@Override
public void renderAlpha() {
if(haulJob != null) {
Assets.flat.pushColor(Vector4f.opacity(0.4f));
camera.draw(Layers.GENERAL_UI, Assets.haulArrow, getWorldPosition());
Assets.flat.popColor();
// Assets.flat.pushColor(Vector4f.opacity(1f));
camera.draw(Layers.MARKERS, Assets.haulArrow, getWorldPosition());
// Assets.flat.popColor();
}
}

View File

@ -22,6 +22,8 @@ public class Assets {
public static final Tile9 uiFrame;
public static final Tile9 uiFrameLight;
public static final Tile9 uiFrameDark;
public static final Tile9 fillColor;
public static final Sprite[] defaultTerrain;
public static final Sprite[] growingRice;
@ -247,6 +249,18 @@ public class Assets {
new Sprite(atlas, 15, 97, 2, 7),
new Sprite(atlas, 17, 97, 7, 7)
);
fillColor = new Tile9(
new Sprite(atlas, 44, 64, 1, 1),
new Sprite(atlas, 44, 64, 1, 1),
new Sprite(atlas, 44, 64, 1, 1),
new Sprite(atlas, 44, 64, 1, 1),
new Sprite(atlas, 44, 64, 1, 1),
new Sprite(atlas, 44, 64, 1, 1),
new Sprite(atlas, 44, 64, 1, 1),
new Sprite(atlas, 44, 64, 1, 1),
new Sprite(atlas, 44, 64, 1, 1)
);
uiFrame = new Tile9(
new Sprite(atlas, 32, 80, 1, 1),