layers are floats now, better camera implementation!
parent
a0604b4555
commit
a4aafa9b04
|
|
@ -9,5 +9,5 @@ public interface IMouseCaptureArea {
|
|||
public void mouseUp(int button);
|
||||
|
||||
public Vector4f getBox();
|
||||
public int getLayer();
|
||||
public float getLayer();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,8 +67,8 @@ public abstract class SceneGraph implements IScene {
|
|||
mouseListeners.sort(new Comparator<IMouseCaptureArea>() {
|
||||
@Override
|
||||
public int compare(IMouseCaptureArea a, IMouseCaptureArea b) {
|
||||
int al = a.getLayer();
|
||||
int bl = b.getLayer();
|
||||
float al = a.getLayer();
|
||||
float bl = b.getLayer();
|
||||
return al < bl ? 1 : bl < al ? -1 : 0;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ package xyz.valnet.hadean.gameobjects;
|
|||
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.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.interfaces.IWorldBoundsAdapter;
|
||||
|
||||
public class Camera extends GameObject {
|
||||
|
||||
|
|
@ -13,6 +15,16 @@ public class Camera extends GameObject {
|
|||
|
||||
private Vector2f focus = new Vector2f(0, 0);
|
||||
|
||||
private float minY, maxY;
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
IWorldBoundsAdapter worldBoundsAdapter = get(IWorldBoundsAdapter.class);
|
||||
Vector4f bounds = worldBoundsAdapter.getWorldBounds();
|
||||
minY = bounds.y;
|
||||
maxY = bounds.w;
|
||||
}
|
||||
|
||||
public void focus(float x, float y) {
|
||||
this.focus.x = x;
|
||||
this.focus.y = y;
|
||||
|
|
@ -26,14 +38,26 @@ public class Camera extends GameObject {
|
|||
return new Vector2f((x - screenWidth / 2 + focus.x * tileWidth) / tileWidth, (y - screenHeight / 2 + focus.y * tileWidth) / tileWidth);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void draw(Sprite sprite, float x, float y) {
|
||||
Vector2f screenPos = world2screen(x, y);
|
||||
Drawing.drawSprite(sprite, (int)(screenPos.x), (int)(screenPos.y), tileWidth, tileWidth);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void draw(Sprite sprite, float x, float y, float w, float h) {
|
||||
Vector2f screenPos = world2screen(x, y);
|
||||
Drawing.drawSprite(sprite, (int)(screenPos.x), (int)(screenPos.y), (int)(tileWidth * w), (int)(tileWidth * h));
|
||||
}
|
||||
|
||||
public void draw(float layer, Sprite sprite, float x, float y) {
|
||||
draw(layer, sprite, x, y, 1, 1);
|
||||
}
|
||||
|
||||
public void draw(float layer, Sprite sprite, float x, float y, float w, float h) {
|
||||
Vector2f 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ public class SelectionUI extends GameObject implements ISelectionChangeListener,
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getLayer() {
|
||||
public float getLayer() {
|
||||
return Layers.GENERAL_UI;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package xyz.valnet.hadean.gameobjects;
|
||||
|
||||
import xyz.valnet.engine.graphics.Drawing;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.WorldObject;
|
||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||
|
|
@ -24,8 +23,7 @@ public class Stockpile extends WorldObject implements ITileThing, ISelectable {
|
|||
|
||||
@Override
|
||||
public void render() {
|
||||
Drawing.setLayer(Layers.GROUND);
|
||||
camera.draw(Assets.stockpile, x, y);
|
||||
camera.draw(Layers.GROUND, Assets.stockpile, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
package xyz.valnet.hadean.gameobjects;
|
||||
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.interfaces.IWorldBoundsAdapter;
|
||||
import xyz.valnet.hadean.pathfinding.IPathable;
|
||||
|
||||
public class Terrain extends GameObject implements IPathable {
|
||||
public class Terrain extends GameObject implements IPathable, IWorldBoundsAdapter {
|
||||
|
||||
public static final int WORLD_SIZE = 24;
|
||||
public static final int TILE_SIZE = 8;
|
||||
|
|
@ -32,12 +33,6 @@ public class Terrain extends GameObject implements IPathable {
|
|||
camera.focus(WORLD_SIZE / 2, WORLD_SIZE / 2);
|
||||
}
|
||||
|
||||
private Tile getRandomTile() {
|
||||
int x = (int) Math.floor(Math.random() * WORLD_SIZE);
|
||||
int y = (int) Math.floor(Math.random() * WORLD_SIZE);
|
||||
return getTile(x, y);
|
||||
}
|
||||
|
||||
public Tile getTile(int x, int y) {
|
||||
return tiles[x][y];
|
||||
}
|
||||
|
|
@ -55,4 +50,9 @@ public class Terrain extends GameObject implements IPathable {
|
|||
return x < 0 || y < 0 || x >= WORLD_SIZE || y >= WORLD_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector4f getWorldBounds() {
|
||||
return new Vector4f(0, 0, WORLD_SIZE, WORLD_SIZE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,10 @@ package xyz.valnet.hadean.gameobjects;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import xyz.valnet.engine.graphics.Drawing;
|
||||
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.Log;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.Tree;
|
||||
import xyz.valnet.hadean.interfaces.ITileThing;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
|
|
@ -37,7 +35,7 @@ public class Tile extends GameObject {
|
|||
public void start() {
|
||||
camera = get(Camera.class);
|
||||
|
||||
if(Math.random() > 0.97) {
|
||||
if(Math.random() > 0.9) {
|
||||
Tree tree = new Tree(x, y);
|
||||
stuff.add(tree);
|
||||
add(tree);
|
||||
|
|
@ -77,9 +75,8 @@ public class Tile extends GameObject {
|
|||
|
||||
@Override
|
||||
public void render() {
|
||||
Drawing.setLayer(Layers.TILES);
|
||||
Assets.flat.pushColor(color);
|
||||
camera.draw(sprite, x, y);
|
||||
camera.draw(Layers.TILES, sprite, x, y);
|
||||
Assets.flat.popColor();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getLayer() {
|
||||
public float getLayer() {
|
||||
return Layers.BUILD_INTERACTABLE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ public class Selection extends GameObject implements IMouseCaptureArea {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getLayer() {
|
||||
public float getLayer() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,10 +44,9 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
|
|||
Assets.uiFrame.draw((int) left, padding, (int) width, 576 - padding * 2 - BottomBar.bottomBarHeight);
|
||||
|
||||
if(opened.value()) {
|
||||
Drawing.setLayer(Layers.BUILD_INTERACTABLE);
|
||||
// draw the currently selected build item
|
||||
Assets.flat.pushColor(new Vector4f(1f, 1f, 1f, 0.8f));
|
||||
camera.draw(Assets.stockpile, x, y);
|
||||
camera.draw(Layers.BUILD_INTERACTABLE, Assets.stockpile, x, y);
|
||||
Assets.flat.popColor();
|
||||
}
|
||||
}
|
||||
|
|
@ -145,7 +144,7 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getLayer() {
|
||||
public float getLayer() {
|
||||
return Layers.GENERAL_UI;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,7 @@ import java.util.List;
|
|||
|
||||
import xyz.valnet.engine.graphics.Drawing;
|
||||
import xyz.valnet.hadean.gameobjects.BottomBar;
|
||||
import xyz.valnet.hadean.gameobjects.Camera;
|
||||
import xyz.valnet.hadean.gameobjects.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.Terrain;
|
||||
import xyz.valnet.hadean.gameobjects.inputlayer.BuildLayer;
|
||||
import xyz.valnet.hadean.gameobjects.inputlayer.Selection;
|
||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||
import xyz.valnet.hadean.interfaces.ISelectionChangeListener;
|
||||
|
|
@ -29,8 +26,6 @@ public class JobBoardTab extends Tab implements ISelectionChangeListener {
|
|||
|
||||
private int padding = 10;
|
||||
|
||||
private int x, y;
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
Drawing.setLayer(Layers.GENERAL_UI);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects;
|
||||
|
||||
import xyz.valnet.engine.graphics.Drawing;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.hadean.gameobjects.JobBoard;
|
||||
|
|
@ -30,15 +29,13 @@ public class FarmPlot extends WorldObject implements IWorkable, ISelectable, ITi
|
|||
|
||||
@Override
|
||||
public void render() {
|
||||
Drawing.setLayer(Layers.GROUND);
|
||||
camera.draw(Assets.farmPlot, x, y);
|
||||
camera.draw(Layers.GROUND, Assets.farmPlot, x, y);
|
||||
|
||||
if(planted) {
|
||||
if(stage > 1) {
|
||||
Drawing.setLayer(Layers.AIR);
|
||||
camera.draw(Assets.growingRice[stage], x, y - 1, 1, 2);
|
||||
camera.draw(Layers.AIR, Assets.growingRice[stage], x, y - 1, 1, 2);
|
||||
} else {
|
||||
camera.draw(Assets.growingRice[stage], x, y);
|
||||
camera.draw(Layers.AIR, Assets.growingRice[stage], x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects;
|
||||
|
||||
import xyz.valnet.engine.graphics.Drawing;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.hadean.gameobjects.JobBoard;
|
||||
|
|
@ -47,11 +46,9 @@ public class Log extends WorldObject implements ITileThing, ISelectable, IHaulab
|
|||
|
||||
@Override
|
||||
public void render() {
|
||||
Drawing.setLayer(Layers.GROUND);
|
||||
camera.draw(Assets.log, x, y);
|
||||
camera.draw(Layers.GROUND, Assets.log, x, y);
|
||||
if(haul.value()) {
|
||||
Drawing.setLayer(Layers.MARKERS);
|
||||
camera.draw(Assets.haulArrow, x, y);
|
||||
camera.draw(Layers.MARKERS, Assets.haulArrow, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import static org.lwjgl.opengl.GL11.glVertex3f;
|
|||
import static org.lwjgl.opengl.GL20.glVertexAttrib2f;
|
||||
import static xyz.valnet.engine.util.Math.lerp;
|
||||
|
||||
import xyz.valnet.engine.graphics.Drawing;
|
||||
import xyz.valnet.engine.math.Vector2f;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
|
|
@ -27,6 +26,7 @@ import xyz.valnet.hadean.pathfinding.Node;
|
|||
import xyz.valnet.hadean.pathfinding.Path;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
import xyz.valnet.hadean.util.Layers;
|
||||
|
||||
public class Pawn extends WorldObject implements ISelectable, IWorker {
|
||||
|
||||
|
|
@ -77,13 +77,11 @@ public class Pawn extends WorldObject implements ISelectable, IWorker {
|
|||
|
||||
@Override
|
||||
public void render() {
|
||||
|
||||
Drawing.setLayer(3f);
|
||||
|
||||
if(path != null && !path.isComplete()) {
|
||||
Node next = path.peek();
|
||||
float t = counter / invocationThreshold;
|
||||
camera.draw(Assets.pawn, lerp(x - 0.5f, next.x, t), lerp(y - 0.5f, next.y, t));
|
||||
camera.draw(Layers.PAWNS, Assets.pawn, lerp(x - 0.5f, next.x, t), lerp(y - 0.5f, next.y, t));
|
||||
|
||||
if(path != null && debug) {
|
||||
for(Node node : path) {
|
||||
|
|
@ -102,7 +100,7 @@ public class Pawn extends WorldObject implements ISelectable, IWorker {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
camera.draw(Assets.pawn, x - 0.5f, y - 0.5f);
|
||||
camera.draw(Layers.PAWNS, Assets.pawn, x - 0.5f, y - 0.5f);
|
||||
}
|
||||
|
||||
// Drawing.setLayer(0.1f);
|
||||
|
|
|
|||
|
|
@ -1,19 +1,12 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects;
|
||||
|
||||
import xyz.valnet.engine.graphics.Drawing;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.hadean.gameobjects.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.Stockpile;
|
||||
import xyz.valnet.hadean.gameobjects.Tile;
|
||||
import xyz.valnet.hadean.interfaces.IHaulable;
|
||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||
import xyz.valnet.hadean.interfaces.ITileThing;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
import xyz.valnet.hadean.util.Layers;
|
||||
import xyz.valnet.hadean.util.SmartBoolean;
|
||||
import xyz.valnet.hadean.util.SmartBoolean.IListener;
|
||||
|
||||
public class Rice extends WorldObject implements ITileThing, ISelectable {
|
||||
|
||||
|
|
@ -47,8 +40,7 @@ public class Rice extends WorldObject implements ITileThing, ISelectable {
|
|||
|
||||
@Override
|
||||
public void render() {
|
||||
Drawing.setLayer(Layers.AIR);
|
||||
camera.draw(Assets.riceBag, x, y);
|
||||
camera.draw(Layers.AIR, Assets.riceBag, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects;
|
||||
|
||||
import xyz.valnet.engine.graphics.Drawing;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.hadean.gameobjects.JobBoard;
|
||||
|
|
@ -28,12 +27,10 @@ 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));
|
||||
Drawing.setLayer(Layers.AIR);
|
||||
camera.draw(Assets.tree, x - 1, y - 2, 3, 3);
|
||||
camera.draw(Layers.AIR, Assets.tree, x - 1, y - 2, 3, 3);
|
||||
Assets.flat.popColor();
|
||||
if(hasWork()) {
|
||||
Drawing.setLayer(Layers.MARKERS);
|
||||
camera.draw(Assets.lilAxe, x, y);
|
||||
camera.draw(Layers.MARKERS, Assets.lilAxe, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ public class Button extends GameObject implements IMouseCaptureArea {
|
|||
protected float activeVPad = 0.1f;
|
||||
protected float activeHPad = 0.0f;
|
||||
|
||||
protected int layer;
|
||||
protected float layer;
|
||||
|
||||
public Button(Tile9 frame, String text, int x, int y, int w, int h, int l) {
|
||||
public Button(Tile9 frame, String text, int x, int y, int w, int h, float l) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
width = w;
|
||||
|
|
@ -188,7 +188,7 @@ public class Button extends GameObject implements IMouseCaptureArea {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getLayer() {
|
||||
public float getLayer() {
|
||||
return layer;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public class GOButton extends GameObject implements IMouseCaptureArea {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getLayer() {
|
||||
public float getLayer() {
|
||||
return layer;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import xyz.valnet.hadean.util.Assets;
|
|||
|
||||
public class SimpleButton extends Button {
|
||||
|
||||
public SimpleButton(String text, int x, int y, int w, int h, int l) {
|
||||
public SimpleButton(String text, int x, int y, int w, int h, float l) {
|
||||
super(Assets.uiFrame, text, x, y, w, h, l);
|
||||
|
||||
this.activeHPad = 0f;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package xyz.valnet.hadean.interfaces;
|
||||
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
|
||||
public interface IWorldBoundsAdapter {
|
||||
|
||||
public Vector4f getWorldBounds();
|
||||
|
||||
}
|
||||
|
|
@ -6,16 +6,17 @@ public class Layers {
|
|||
return current;
|
||||
}
|
||||
|
||||
public static final int BACKGROUND = current ++;
|
||||
public static final int TILES = current ++;
|
||||
public static final int GROUND = current ++;
|
||||
public static final int AIR = current ++;
|
||||
public static final int MARKERS = current ++;
|
||||
public static final int SELECTION_IDENTIFIERS = current ++;
|
||||
public static final int AREA_SELECT_BOX = current ++;
|
||||
public static final int BUILD_INTERACTABLE = current ++;
|
||||
public static final int GENERAL_UI = current ++;
|
||||
public static final int GENERAL_UI_INTERACTABLE = current ++;
|
||||
public static final int BOTTOM_BAR = current ++;
|
||||
public static final float BACKGROUND = current ++;
|
||||
public static final float TILES = current ++;
|
||||
public static final float GROUND = current ++;
|
||||
public static final float AIR = current ++;
|
||||
public static final float PAWNS = Layers.AIR + 0.001f;
|
||||
public static final float MARKERS = current ++;
|
||||
public static final float SELECTION_IDENTIFIERS = current ++;
|
||||
public static final float AREA_SELECT_BOX = current ++;
|
||||
public static final float BUILD_INTERACTABLE = current ++;
|
||||
public static final float GENERAL_UI = current ++;
|
||||
public static final float GENERAL_UI_INTERACTABLE = current ++;
|
||||
public static final float BOTTOM_BAR = current ++;
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue