more boxes
parent
ac0a9217db
commit
39710d33a7
|
|
@ -21,7 +21,7 @@ public abstract class Game {
|
|||
if(this.scene != null) {
|
||||
this.scene.disable();
|
||||
}
|
||||
scene.enable();
|
||||
scene.enable(this);
|
||||
this.scene = scene;
|
||||
}
|
||||
|
||||
|
|
@ -51,6 +51,14 @@ public abstract class Game {
|
|||
}
|
||||
}
|
||||
|
||||
public final float getAverageFPS() {
|
||||
return averageFPS;
|
||||
}
|
||||
|
||||
public final int getMeasuredFPS() {
|
||||
return measuredFPS;
|
||||
}
|
||||
|
||||
public abstract void updateViewMatrix(Matrix4f matrix);
|
||||
|
||||
public final void scrollUp() {
|
||||
|
|
|
|||
|
|
@ -85,6 +85,14 @@ public class Box implements Serializable {
|
|||
return new Box(x, y, x2 - x, y2 - y);
|
||||
}
|
||||
|
||||
public static Box fromPoints(Vector2f a, Vector2i b) {
|
||||
return new Box(a.x, a.y, b.x - a.x, b.y - a.y);
|
||||
}
|
||||
|
||||
public static Box fromPoints(Vector2i a, Vector2f b) {
|
||||
return new Box(a.x, a.y, b.x - a.x, b.y - a.y);
|
||||
}
|
||||
|
||||
public Box copy() {
|
||||
return new Box(x, y, w, h);
|
||||
}
|
||||
|
|
@ -92,4 +100,47 @@ public class Box implements Serializable {
|
|||
public boolean contains(float x, float y) {
|
||||
return x >= this.x && x < this.x2 && y >= this.y && y < this.y2;
|
||||
}
|
||||
|
||||
public boolean contains(Vector2f pos) {
|
||||
return contains(pos.x, pos.y);
|
||||
}
|
||||
|
||||
public boolean intersects(Box other) {
|
||||
boolean aLeftOfB = x2 <= other.x;
|
||||
boolean aRightOfB = x >= other.x2;
|
||||
boolean aAboveB = y >= other.y2;
|
||||
boolean aBelowB = y2 <= other.y;
|
||||
|
||||
return !( aLeftOfB || aRightOfB || aAboveB || aBelowB );
|
||||
}
|
||||
|
||||
public Vector2i[] getBorders() {
|
||||
|
||||
// TODO this could be bad, idk man. maybe define an intbox...
|
||||
int x = (int) Math.round(this.x);
|
||||
int y = (int) Math.round(this.y);
|
||||
int w = (int) Math.round(this.w);
|
||||
int h = (int) Math.round(this.h);
|
||||
|
||||
int size = 2 * w + 2 * h;
|
||||
Vector2i[] vecs = new Vector2i[size];
|
||||
|
||||
// top / bottom row
|
||||
for(int i = 0; i < h; i ++) {
|
||||
vecs[i] = new Vector2i(x + i, y - 1);
|
||||
vecs[size - i - 1] = new Vector2i(x + i, y + h);
|
||||
}
|
||||
|
||||
// middle pillars
|
||||
for(int i = 0; i < h; i ++) {
|
||||
vecs[w + i * 2] = new Vector2i(x - 1, y + i);
|
||||
vecs[w + i * 2 + 1] = new Vector2i(x + h, y + i);
|
||||
}
|
||||
|
||||
return vecs;
|
||||
}
|
||||
|
||||
public Box outset(float f) {
|
||||
return new Box(x - f, y - f, w + 2 * f, h + 2 * f);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class Vector2f implements Serializable {
|
|||
}
|
||||
|
||||
public Vector2i asInt() {
|
||||
return new Vector2i((int)x, (int)y);
|
||||
return new Vector2i((int)Math.floor(x), (int)Math.floor(y));
|
||||
}
|
||||
|
||||
public boolean equals(Vector2f v) {
|
||||
|
|
|
|||
|
|
@ -59,4 +59,8 @@ public class Vector2i implements Serializable {
|
|||
return new Box(x, y, 1, 1);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "<" + x + ", " + y + ">";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package xyz.valnet.engine.scenegraph;
|
|||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import xyz.valnet.hadean.util.Pair;
|
||||
|
||||
public class GameObject implements IRenderable, ITickable, Serializable {
|
||||
private transient SceneGraph scene;
|
||||
|
||||
|
|
@ -85,4 +87,8 @@ public class GameObject implements IRenderable, ITickable, Serializable {
|
|||
protected boolean isPaused() {
|
||||
return scene.isPaused();
|
||||
}
|
||||
|
||||
protected Pair<Float, Integer> getFPS() {
|
||||
return scene.getFPS();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package xyz.valnet.engine.scenegraph;
|
||||
|
||||
import xyz.valnet.engine.Game;
|
||||
|
||||
public interface IScene {
|
||||
public void render();
|
||||
public void update(float dTime);
|
||||
|
|
@ -14,6 +16,6 @@ public interface IScene {
|
|||
public void keyRelease(int key);
|
||||
public void keyRepeat(int key);
|
||||
|
||||
public void enable();
|
||||
public void enable(Game game);
|
||||
public void disable();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,11 @@ import java.util.Set;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
import xyz.valnet.engine.App;
|
||||
import xyz.valnet.engine.Game;
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.hadean.HadeanGame;
|
||||
import xyz.valnet.hadean.gameobjects.ui.tabs.DebugTab;
|
||||
import xyz.valnet.hadean.util.Pair;
|
||||
|
||||
public abstract class SceneGraph implements IScene {
|
||||
protected final List<GameObject> objects = new ArrayList<GameObject>();
|
||||
|
|
@ -131,13 +133,15 @@ public abstract class SceneGraph implements IScene {
|
|||
}
|
||||
|
||||
private boolean paused = false;
|
||||
private Game game;
|
||||
|
||||
public boolean isPaused() {
|
||||
return paused;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
public void enable(Game game) {
|
||||
this.game = game;
|
||||
this.construct();
|
||||
|
||||
for(GameObject obj : objects) {
|
||||
|
|
@ -324,4 +328,8 @@ public abstract class SceneGraph implements IScene {
|
|||
iml.scrollUp();
|
||||
}
|
||||
}
|
||||
|
||||
public Pair<Float, Integer> getFPS() {
|
||||
return new Pair<Float, Integer>(game.getAverageFPS(), game.getMeasuredFPS());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,14 +31,6 @@ public class HadeanGame extends Game {
|
|||
if(!debugView) return;
|
||||
}
|
||||
|
||||
public float getAverageFPS() {
|
||||
return averageFPS;
|
||||
}
|
||||
|
||||
public int getMeasuredFPS() {
|
||||
return measuredFPS;
|
||||
}
|
||||
|
||||
// receive the updated matrix every frame for the actual window.
|
||||
@Override
|
||||
public void updateViewMatrix(Matrix4f matrix) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package xyz.valnet.hadean.designation;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.interfaces.BuildType;
|
||||
import xyz.valnet.hadean.interfaces.IBuildable;
|
||||
|
|
@ -12,27 +12,16 @@ public abstract class Designation<T extends ISelectable> extends GameObject impl
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void buildAt(int x, int y, int w, int h) {
|
||||
public void buildAt(Box box) {
|
||||
Class<T> type = getType();
|
||||
List<T> things = getAll(type);
|
||||
for(ISelectable thing : things) {
|
||||
Vector4f box = thing.getWorldBox();
|
||||
if(rectanglesIntersect(x, y, x + w, y + h, box.x, box.y, box.z, box.w))
|
||||
designate((T) thing);
|
||||
Box thingBox = thing.getWorldBox();
|
||||
if(box.intersects(thingBox))
|
||||
designate((T) thing);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean rectanglesIntersect(
|
||||
float minAx, float minAy, float maxAx, float maxAy,
|
||||
float minBx, float minBy, float maxBx, float maxBy ) {
|
||||
boolean aLeftOfB = maxAx <= minBx;
|
||||
boolean aRightOfB = minAx >= maxBx;
|
||||
boolean aAboveB = minAy >= maxBy;
|
||||
boolean aBelowB = maxAy <= minBy;
|
||||
|
||||
return !( aLeftOfB || aRightOfB || aAboveB || aBelowB );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBuildTabCategory() {
|
||||
return "Jobs";
|
||||
|
|
|
|||
|
|
@ -41,11 +41,11 @@ public class Camera extends GameObject implements ITransient, IMouseCaptureArea
|
|||
maxY = bounds.w;
|
||||
}
|
||||
|
||||
public void setFocusBounds(Box box) {
|
||||
public final void setFocusBounds(Box box) {
|
||||
this.focusBounds = box;
|
||||
}
|
||||
|
||||
public Vector2f getWorldMouse() {
|
||||
public final Vector2f getWorldMouse() {
|
||||
return screen2world(App.mouseX, App.mouseY);
|
||||
}
|
||||
|
||||
|
|
@ -84,24 +84,28 @@ public class Camera extends GameObject implements ITransient, IMouseCaptureArea
|
|||
this.focus.y = y;
|
||||
}
|
||||
|
||||
public Vector2i world2screen(float x, float y) {
|
||||
public final Box world2screen(Box box) {
|
||||
return Box.fromPoints(world2screen(box.a), world2screen(box.b));
|
||||
}
|
||||
|
||||
public final Vector2i world2screen(float x, float y) {
|
||||
return new Vector2i((int)(x * tileWidth + screenWidth / 2 - focus.x * tileWidth), (int)(y * tileWidth + screenHeight / 2 - focus.y * tileWidth));
|
||||
}
|
||||
|
||||
public Vector2i world2screen(Vector2f pos) {
|
||||
public final Vector2i world2screen(Vector2f pos) {
|
||||
return world2screen(pos.x, pos.y);
|
||||
}
|
||||
|
||||
public Vector2f screen2world(float x, float y) {
|
||||
public final Vector2f screen2world(float x, float y) {
|
||||
return new Vector2f((x - screenWidth / 2 + focus.x * tileWidth) / tileWidth, (y - screenHeight / 2 + focus.y * tileWidth) / tileWidth);
|
||||
}
|
||||
|
||||
public Vector2f screen2world(Vector2f pos) {
|
||||
public final Vector2f screen2world(Vector2f pos) {
|
||||
return screen2world(pos.x, pos.y);
|
||||
}
|
||||
|
||||
// !! this takes an AABB and returns and AABB
|
||||
public Vector4f world2screen(Vector4f input) {
|
||||
public final Vector4f world2screen(Vector4f input) {
|
||||
return new Vector4f(
|
||||
input.x * tileWidth + screenWidth / 2 - focus.x * tileWidth,
|
||||
input.y * tileWidth + screenHeight / 2 - focus.y * tileWidth,
|
||||
|
|
@ -111,53 +115,53 @@ public class Camera extends GameObject implements ITransient, IMouseCaptureArea
|
|||
}
|
||||
|
||||
@Deprecated
|
||||
public void draw(Sprite sprite, float x, float y) {
|
||||
public final void draw(Sprite sprite, float x, float y) {
|
||||
Vector2i screenPos = world2screen(x, y);
|
||||
Drawing.drawSprite(sprite, (screenPos.x), (screenPos.y), tileWidth, tileWidth);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void draw(Sprite sprite, float x, float y, float w, float h) {
|
||||
public final void draw(Sprite sprite, float x, float y, float w, float h) {
|
||||
Vector2i screenPos = world2screen(x, y);
|
||||
Drawing.drawSprite(sprite, (screenPos.x), (screenPos.y), (int)(tileWidth * w), (int)(tileWidth * h));
|
||||
}
|
||||
|
||||
public void draw(float layer, Sprite sprite, float x, float y) {
|
||||
public final void draw(float layer, Sprite sprite, float x, float y) {
|
||||
draw(layer, sprite, x, y, 1, 1);
|
||||
}
|
||||
|
||||
public void draw(float layer, Sprite sprite, Vector2f pos) {
|
||||
public final void draw(float layer, Sprite sprite, Vector2f pos) {
|
||||
draw(layer, sprite, pos.x, pos.y, 1, 1);
|
||||
}
|
||||
|
||||
public void draw(float layer, Sprite sprite, Vector4i pos) {
|
||||
public final void draw(float layer, Sprite sprite, Vector4i pos) {
|
||||
draw(layer, sprite, pos.x, pos.y, pos.z, pos.w);
|
||||
}
|
||||
|
||||
public void draw(float layer, Sprite sprite, float x, float y, float w, float h) {
|
||||
public final void draw(float layer, Sprite sprite, float x, float y, float w, float h) {
|
||||
Vector2i screenPos = world2screen(x, y);
|
||||
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 draw(float layer, Tile9 sprite, Box box) {
|
||||
public final void draw(float layer, Tile9 sprite, Box box) {
|
||||
draw(layer, sprite, box.x, box.y, box.w, box.h);
|
||||
}
|
||||
|
||||
public void draw(float layer, Tile9 sprite, float x, float y, float w, float h) {
|
||||
public final void draw(float layer, Tile9 sprite, float x, float y, float w, float h) {
|
||||
Vector2i screenPos = world2screen(x, y);
|
||||
Drawing.setLayer(layer + (((y + h) - minY) / (maxY - minY)));
|
||||
sprite.draw((int)(screenPos.x), (int)(screenPos.y), (int)(tileWidth * w), (int)(tileWidth * h));
|
||||
}
|
||||
|
||||
public void drawProgressBar(float progress, Vector4f worldBox) {
|
||||
public final void drawProgressBar(float progress, Box worldBox) {
|
||||
int h = 6;
|
||||
Vector4i box = world2screen(worldBox).toXYWH().asInt();
|
||||
Box box = world2screen(worldBox);
|
||||
Drawing.setLayer(Layers.GENERAL_UI);
|
||||
Assets.flat.pushColor(Color.black);
|
||||
Assets.uiFrame.draw(box.x - h, box.y + box.w / 2 - h / 2, box.z + h * 2, h);
|
||||
Assets.uiFrame.draw((int)(box.x - h), (int)(box.y + box.h / 2 - h / 2), (int)(box.w + h * 2), h);
|
||||
Assets.flat.swapColor(Color.yellow);
|
||||
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.fillColor.draw((int)(box.x + 1 - h), (int)(box.y + 1 + box.h / 2 - h / 2), (int)Math.round(lerp(0, box.w - 3 + h * 2, progress)) + 1, h - 2);
|
||||
Assets.flat.popColor();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,16 +58,16 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
|||
}
|
||||
|
||||
private void broadcastWorldCoords() {
|
||||
Vector2i worldcoords = camera.screen2world(App.mouseX, App.mouseY).asInt();
|
||||
Vector2i worldcoords = camera.getWorldMouse().asInt();
|
||||
if(mouseDown) {
|
||||
Vector2i[] ords = orderCoords(new Vector2i(x, y), worldcoords);
|
||||
listener.update(ords[0].x, ords[0].y, ords[2].x + 1, ords[2].y + 1);
|
||||
Vector2i[] ords = orderCoords(startingPoint, worldcoords);
|
||||
listener.update(new Box(ords[0].x, ords[0].y, ords[2].x + 1, ords[2].y + 1));
|
||||
return;
|
||||
}
|
||||
if(type == BuildType.SINGLE && dimensions != null) {
|
||||
listener.update(worldcoords.x, worldcoords.y, dimensions.x, dimensions.y);
|
||||
listener.update(new Box(worldcoords, dimensions));
|
||||
} else {
|
||||
listener.update(worldcoords.x, worldcoords.y, 1, 1);
|
||||
listener.update(new Box(worldcoords, 1, 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +86,7 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
|||
hovered = false;
|
||||
}
|
||||
|
||||
private int x, y;
|
||||
private Vector2i startingPoint = null;
|
||||
private boolean mouseDown = false;
|
||||
|
||||
private Vector2i dimensions = new Vector2i(1, 1);
|
||||
|
|
@ -102,12 +102,10 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
|||
listener.cancel();
|
||||
} else if(button == 0 && active && hovered) {
|
||||
// TODO this conversion in negative numbers definitely works wrong.
|
||||
Vector2i worldcoords = camera.screen2world(App.mouseX, App.mouseY).asInt();
|
||||
startingPoint = camera.getWorldMouse().asInt();
|
||||
mouseDown = true;
|
||||
x = worldcoords.x;
|
||||
y = worldcoords.y;
|
||||
if(type == BuildType.SINGLE) {
|
||||
listener.build(x, y, x + dimensions.x - 1, y + dimensions.y - 1);
|
||||
listener.build(new Box(startingPoint, dimensions));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -117,29 +115,11 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
|||
if(button == 0 && active && mouseDown) {
|
||||
mouseDown = false;
|
||||
if(type == BuildType.AREA) {
|
||||
Vector2i worldcoords = camera.screen2world(App.mouseX, App.mouseY).asInt();
|
||||
int x1 = x;
|
||||
int y1 = y;
|
||||
int x2 = worldcoords.x;
|
||||
int y2 = worldcoords.y;
|
||||
int minX = Math.min(x1, x2);
|
||||
int minY = Math.min(y1, y2);
|
||||
int maxX = Math.max(x1, x2);
|
||||
int maxY = Math.max(y1, y2);
|
||||
listener.build(minX, minY, maxX, maxY);
|
||||
listener.build(Box.fromPoints(camera.getWorldMouse(), startingPoint));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated(since = "What is this abomination", forRemoval = true)
|
||||
private Vector2i[] orderCoords(Vector2i a, Vector2i b) {
|
||||
return new Vector2i[] {
|
||||
new Vector2i(Math.min(a.x, b.x), Math.min(a.y, b.y)),
|
||||
new Vector2i(Math.max(a.x, b.x), Math.max(a.y, b.y)),
|
||||
new Vector2i(Math.max(a.x, b.x) - Math.min(a.x, b.x), Math.max(a.y, b.y) - Math.min(a.y, b.y))
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Box> getGuiBoxes() {
|
||||
return List.of(active ? new Box(0, 0, 1024, 576) : Box.none);
|
||||
|
|
|
|||
|
|
@ -80,11 +80,8 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
|
|||
float p = lerp(animationAmplitude, 0, t);
|
||||
|
||||
for(ISelectable thing : selected) {
|
||||
Vector4f box = thing.getWorldBox();
|
||||
Vector2i min = camera.world2screen(box.x - p, box.y - p);
|
||||
Vector2i max = camera.world2screen(box.z + p, box.w + p);
|
||||
Drawing.setLayer(Layers.SELECTION_IDENTIFIERS);
|
||||
Assets.selectedFrame.draw((int)min.x, (int)min.y, (int)(max.x - min.x), (int)(max.y - min.y));
|
||||
Box box = thing.getWorldBox().outset(p);
|
||||
camera.draw(Layers.SELECTION_IDENTIFIERS, Assets.selectedFrame, box);
|
||||
thing.selectedRender();
|
||||
}
|
||||
|
||||
|
|
@ -96,37 +93,17 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
|
|||
}
|
||||
}
|
||||
|
||||
// this will take any x1, y1, x2, y2 vector and make x1 < x2 and y1 < y2;
|
||||
private Vector4f sortVector(Vector4f vector) {
|
||||
return new Vector4f(
|
||||
Math.min(vector.x, vector.z),
|
||||
Math.min(vector.y, vector.w),
|
||||
Math.max(vector.x, vector.z),
|
||||
Math.max(vector.y, vector.w)
|
||||
);
|
||||
}
|
||||
|
||||
private List<ISelectable> selected = new ArrayList<ISelectable>();
|
||||
|
||||
private void makeSelection(Vector4f a) {
|
||||
private void makeSelection(Box selectionBox) {
|
||||
List<ISelectable> newSelection = new ArrayList<ISelectable>();
|
||||
|
||||
Vector4f normalizedSelectionBoxScreen = sortVector(a);
|
||||
Vector2f selectionBoxWorldMin = new Vector2f(normalizedSelectionBoxScreen.x, normalizedSelectionBoxScreen.y);
|
||||
Vector2f selectionBoxWorldMax = new Vector2f(normalizedSelectionBoxScreen.z, normalizedSelectionBoxScreen.w);
|
||||
|
||||
List<ISelectable> selectables = getAll(ISelectable.class);
|
||||
|
||||
int prio = Integer.MIN_VALUE;
|
||||
|
||||
for(ISelectable thing : selectables) {
|
||||
Vector4f thingBox = thing.getWorldBox();
|
||||
if(rectanglesIntersect(
|
||||
selectionBoxWorldMin.x, selectionBoxWorldMin.y,
|
||||
selectionBoxWorldMax.x, selectionBoxWorldMax.y,
|
||||
thingBox.x, thingBox.y,
|
||||
thingBox.z, thingBox.w
|
||||
)) {
|
||||
Box thingBox = thing.getWorldBox();
|
||||
if(selectionBox.intersects(thingBox)) {
|
||||
int thingPrio = thing.getSelectPriority().toValue();
|
||||
if(thingPrio > prio) {
|
||||
newSelection.clear();
|
||||
|
|
@ -216,18 +193,7 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
|
|||
@Override
|
||||
public void mouseUp(int button) {
|
||||
if(initialCoords != null && button == 0) {
|
||||
|
||||
Vector2f worldMouse = camera.screen2world(App.mouseX, App.mouseY);
|
||||
|
||||
Vector4f worldBox = new Vector4f(
|
||||
initialCoords.x,
|
||||
initialCoords.y,
|
||||
worldMouse.x,
|
||||
worldMouse.y
|
||||
);
|
||||
|
||||
makeSelection(worldBox);
|
||||
|
||||
makeSelection(Box.fromPoints(initialCoords, camera.getWorldMouse()));
|
||||
initialCoords = null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ public class Tile extends WorldObject implements IWorkable {
|
|||
add(new Tree(pos.x, pos.y));
|
||||
} else if(Math.random() > 0.98) {
|
||||
rocks = false;
|
||||
add(new Log(pos.x, pos.y));
|
||||
add(new Boulder(pos.x, pos.y));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||
|
||||
import xyz.valnet.engine.App;
|
||||
import xyz.valnet.engine.graphics.Drawing;
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.engine.math.Vector2f;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
|
|
@ -42,13 +43,8 @@ public class HoverQuery extends GameObject implements ITransient {
|
|||
Vector2f position = camera.screen2world(App.mouseX, App.mouseY);
|
||||
thingStrings.clear();
|
||||
for(WorldObject obj : getAll(WorldObject.class)) {
|
||||
Vector4f box = obj.getWorldBox();
|
||||
if(
|
||||
position.x >= box.x &&
|
||||
position.x < box.z &&
|
||||
position.y >= box.y &&
|
||||
position.y < box.w
|
||||
) {
|
||||
Box box = obj.getWorldBox();
|
||||
if(box.contains(position)) {
|
||||
thingStrings.add(obj.getName());
|
||||
if (!HadeanGame.debugView) continue;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import java.util.Map;
|
|||
|
||||
import xyz.valnet.engine.graphics.Color;
|
||||
import xyz.valnet.engine.graphics.Drawing;
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.designation.CutTreesDesignation;
|
||||
|
|
@ -36,8 +37,7 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
|
|||
private BuildLayer buildLayer;
|
||||
private Camera camera;
|
||||
|
||||
private int x, y;
|
||||
private int w, h;
|
||||
private Box renderBox = Box.none;
|
||||
|
||||
private String selectedCategory = null;
|
||||
|
||||
|
|
@ -105,13 +105,13 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
|
|||
if(!opened || selectedBuildable == null) return;
|
||||
// draw the currently selected build item
|
||||
Assets.flat.pushColor(Color.white);
|
||||
Vector2i topLeft = camera.world2screen(x, y);
|
||||
Vector2i topLeft = camera.world2screen(renderBox.a);
|
||||
Assets.font.drawString(selectedBuildable.name, topLeft.x, topLeft.y - 20);
|
||||
Assets.flat.swapColor(Color.white.withAlpha(0.6f));
|
||||
camera.draw(Layers.BUILD_INTERACTABLE, Assets.selectionFrame, x, y, w, h);
|
||||
camera.draw(Layers.BUILD_INTERACTABLE, Assets.selectionFrame, renderBox);
|
||||
Assets.flat.swapColor(Color.white.withAlpha(0.35f));
|
||||
for(int i = 0; i < w; i ++) for(int j = 0; j < h; j ++) {{
|
||||
camera.draw(Layers.BUILD_INTERACTABLE, Assets.checkerBoard, x + i, y + j);
|
||||
for(int i = 0; i < renderBox.w; i ++) for(int j = 0; j < renderBox.h; j ++) {{
|
||||
camera.draw(Layers.BUILD_INTERACTABLE, Assets.checkerBoard, renderBox.x + i, renderBox.y + j);
|
||||
}}
|
||||
Assets.flat.popColor();
|
||||
}
|
||||
|
|
@ -153,28 +153,6 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
|
|||
buildLayer.setDimensions(selectedBuildable.dimensions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(int nx, int ny, int nw, int nh) {
|
||||
x = nx;
|
||||
y = ny;
|
||||
w = nw;
|
||||
h = nh;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(int x1, int y1, int x2, int y2) {
|
||||
if(selectedBuildable == null) return;
|
||||
try {
|
||||
IBuildable building = selectedBuildable.constructor.newInstance();
|
||||
if(building instanceof GameObject) {
|
||||
add((GameObject) building);
|
||||
}
|
||||
building.buildAt(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
|
||||
} catch (Exception e) {
|
||||
DebugTab.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
if(selectedBuildable == null) {
|
||||
|
|
@ -252,4 +230,23 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
|
|||
protected void onOpen() {
|
||||
reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Box box) {
|
||||
renderBox = box;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Box box) {
|
||||
if(selectedBuildable == null) return;
|
||||
try {
|
||||
IBuildable building = selectedBuildable.constructor.newInstance();
|
||||
if(building instanceof GameObject) {
|
||||
add((GameObject) building);
|
||||
}
|
||||
building.buildAt(box);
|
||||
} catch (Exception e) {
|
||||
DebugTab.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,10 @@ public class DebugTab extends Tab implements IKeyboardListener {
|
|||
space(8);
|
||||
text(System.getProperty("java.version"));
|
||||
space(8);
|
||||
var fps = getFPS();
|
||||
text("FPS: " + fps.first());
|
||||
text("MEASURED FPS: " + fps.second());
|
||||
space(8);
|
||||
|
||||
long allocated = runtime.totalMemory();
|
||||
long max = runtime.maxMemory();
|
||||
|
|
@ -65,6 +69,7 @@ public class DebugTab extends Tab implements IKeyboardListener {
|
|||
while(logs.size() > 10) {
|
||||
logs.remove(0);
|
||||
}
|
||||
System.out.println(str);
|
||||
}
|
||||
|
||||
public static void log(Object obj) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects;
|
||||
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
||||
import xyz.valnet.hadean.interfaces.IBuildable;
|
||||
|
|
@ -11,8 +12,8 @@ import xyz.valnet.hadean.util.detail.Detail;
|
|||
public abstract class Buildable extends WorldObject implements IBuildable, ITileThing, ISelectable {
|
||||
|
||||
@Override
|
||||
public void buildAt(int x, int y, int w, int h) {
|
||||
setPosition(x, y, w, h);
|
||||
public void buildAt(Box box) {
|
||||
setPosition(box);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects;
|
||||
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.Job;
|
||||
|
|
@ -32,7 +33,7 @@ public class Tree extends WorldObject implements ITileThing, ISelectable, IWorka
|
|||
// Assets.flat.popColor();
|
||||
if(chopJob != null) {
|
||||
if(getProgress() > 0) {
|
||||
camera.drawProgressBar(getProgress(), new Vector4f(pos.x - 1, pos.y - 2, pos.x + 2, pos.y + 1));
|
||||
camera.drawProgressBar(getProgress(), new Box(pos.x - 1, pos.y - 2, 3, 3));
|
||||
}
|
||||
camera.draw(Layers.MARKERS, Assets.lilAxe, pos.x, pos.y);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package xyz.valnet.hadean.gameobjects.worldobjects;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.math.Vector4i;
|
||||
|
|
@ -14,6 +15,7 @@ import xyz.valnet.hadean.interfaces.ITileThing;
|
|||
|
||||
public abstract class WorldObject extends GameObject {
|
||||
|
||||
// TODO make it just a box lawl
|
||||
private int x;
|
||||
private int y;
|
||||
private int w;
|
||||
|
|
@ -93,6 +95,10 @@ public abstract class WorldObject extends GameObject {
|
|||
setPosition(x, y, 1, 1);
|
||||
}
|
||||
|
||||
protected void setPosition(Box box) {
|
||||
setPosition((int) box.x, (int) box.y, (int) box.w, (int) box.h);
|
||||
}
|
||||
|
||||
protected void setPosition(int x, int y, int w, int h) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
|
@ -124,8 +130,8 @@ public abstract class WorldObject extends GameObject {
|
|||
|
||||
public abstract String getName();
|
||||
|
||||
public Vector4f getWorldBox() {
|
||||
return new Vector4f(x, y, x + w, y + h);
|
||||
public Box getWorldBox() {
|
||||
return new Box(x, y, w, h);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import xyz.valnet.engine.graphics.Color;
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.engine.math.Vector2f;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.util.Names;
|
||||
import xyz.valnet.hadean.HadeanGame;
|
||||
import xyz.valnet.hadean.gameobjects.Clock;
|
||||
|
|
@ -154,9 +154,9 @@ public class Pawn extends Agent {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Vector4f getWorldBox() {
|
||||
public Box getWorldBox() {
|
||||
Vector2f pos = getCalculatedPosition();
|
||||
return new Vector4f(pos.x, pos.y, pos.x+1, pos.y+1);
|
||||
return new Box(pos, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public abstract class Construction extends Buildable implements IItemReceiver {
|
|||
|
||||
@Override
|
||||
public Vector2i[] getWorkablePositions() {
|
||||
return getWorldBox().toXYWH().asInt().getBorders();
|
||||
return getWorldBox().getBorders();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -119,7 +119,7 @@ public abstract class Construction extends Buildable implements IItemReceiver {
|
|||
|
||||
@Override
|
||||
public Vector2i[] getItemDropoffLocations() {
|
||||
return getWorldBox().toXYWH().asInt().getBorders();
|
||||
return getWorldBox().getBorders();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class Wall extends Construction implements IPingable {
|
|||
|
||||
@Override
|
||||
public void ping() {
|
||||
Vector2i pos = getWorldBox().asInt().xy();
|
||||
Vector2i pos = getWorldBox().a.asInt();
|
||||
wallSides = EnumSet.noneOf(Direction.class);
|
||||
|
||||
Tile north = terrain.getTile(pos.x, pos.y - 1);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package xyz.valnet.hadean.interfaces;
|
||||
|
||||
import xyz.valnet.engine.math.Box;
|
||||
|
||||
public interface IBuildLayerListener {
|
||||
@Deprecated
|
||||
public void update(int x, int y, int w, int h);
|
||||
@Deprecated
|
||||
public void build(int x, int y, int w, int h);
|
||||
|
||||
public void update(Box box);
|
||||
public void build(Box box);
|
||||
|
||||
public void cancel();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
package xyz.valnet.hadean.interfaces;
|
||||
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
|
||||
public interface IBuildable {
|
||||
|
||||
public void buildAt(int x, int y, int w, int h);
|
||||
public void buildAt(Box box);
|
||||
|
||||
public String getBuildTabCategory();
|
||||
public BuildType getBuildType();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package xyz.valnet.hadean.interfaces;
|
||||
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.util.detail.Detail;
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ public interface ISelectable {
|
|||
}
|
||||
}
|
||||
|
||||
public Vector4f getWorldBox();
|
||||
public Box getWorldBox();
|
||||
public Action[] getActions();
|
||||
public void runAction(Action action);
|
||||
public Detail[] getDetails();
|
||||
|
|
|
|||
Loading…
Reference in New Issue