basic drag buildings. needs better ui. works on macos

pull/1/head
Bronwen 2022-06-02 04:30:48 -04:00
parent a4aafa9b04
commit fe95f750c2
5 changed files with 44 additions and 25 deletions

View File

@ -7,7 +7,7 @@ varying vec2 vTexCoord;
void main() { void main() {
vec4 texColor = texture2D(u_texture, vTexCoord); vec4 texColor = texture2D(u_texture, vTexCoord);
if(texColor == vec4(1, 0, 1, 1) || texColor == vec4(1, 0, 0, 1) || texColor.w == 0) { if(texColor == vec4(1, 0, 1, 1) || texColor == vec4(1, 0, 0, 1) || texColor.w == 0.0) {
discard; discard;
} else { } else {
gl_FragColor = texColor * vColor; gl_FragColor = texColor * vColor;

View File

@ -136,6 +136,7 @@ public class App {
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
glDepthMask(true); glDepthMask(true);
glfwSwapInterval(1);
game.start(); game.start();
} }

View File

@ -31,31 +31,31 @@ public class HadeanGame extends Game {
renderDebugInfo(); renderDebugInfo();
} }
// private Runtime runtime = Runtime.getRuntime(); private Runtime runtime = Runtime.getRuntime();
// private static Vector4f fontColor = new Vector4f(0, 1, 1, 1); private static Vector4f fontColor = new Vector4f(0, 1, 1, 1);
private void renderDebugInfo() { private void renderDebugInfo() {
// long allocated = runtime.totalMemory(); long allocated = runtime.totalMemory();
// long max = runtime.maxMemory(); long max = runtime.maxMemory();
// Assets.flat.pushColor(Vector4f.black); Assets.flat.pushColor(Vector4f.black);
// Assets.font.drawString("FPS: " + Math.round(averageFPS) + "/" + measuredFPS + " | AVG/MEASURED", 1, 1); Assets.font.drawString("FPS: " + Math.round(averageFPS) + "/" + measuredFPS + " | AVG/MEASURED", 1, 1);
// Assets.font.drawString("Mouse: <" + App.mouseX + ", " + App.mouseY + ">", 1, 17); Assets.font.drawString("Mouse: <" + App.mouseX + ", " + App.mouseY + ">", 1, 17);
// Assets.font.drawString("MEMORY: " + (int)((allocated / (double)max) * 100) + "% (" + (allocated / (1024 * 1024)) + "/" + (max / (1024 * 1024)) + "MB)", 1, 33); Assets.font.drawString("MEMORY: " + (int)((allocated / (double)max) * 100) + "% (" + (allocated / (1024 * 1024)) + "/" + (max / (1024 * 1024)) + "MB)", 1, 33);
// Assets.font.drawString("IPATHABLE", 1, 49); Assets.font.drawString("IPATHABLE", 1, 49);
// Assets.font.drawString("", 1, 65); Assets.font.drawString("", 1, 65);
// Assets.font.drawString("", 1, 81); Assets.font.drawString("", 1, 81);
// Assets.flat.swapColor(fontColor); Assets.flat.swapColor(fontColor);
// Assets.font.drawString("FPS: " + Math.round(averageFPS) + "/" + measuredFPS + " | AVG/MEASURED", 0, 0); Assets.font.drawString("FPS: " + Math.round(averageFPS) + "/" + measuredFPS + " | AVG/MEASURED", 0, 0);
// Assets.font.drawString("Mouse: <" + App.mouseX + ", " + App.mouseY + ">", 0, 16); Assets.font.drawString("Mouse: <" + App.mouseX + ", " + App.mouseY + ">", 0, 16);
// Assets.font.drawString("MEMORY: " + (int)((allocated / (double)max) * 100) + "% (" + (allocated / (1024 * 1024)) + "/" + (max / (1024 * 1024)) + "MB)", 0, 32); Assets.font.drawString("MEMORY: " + (int)((allocated / (double)max) * 100) + "% (" + (allocated / (1024 * 1024)) + "/" + (max / (1024 * 1024)) + "MB)", 0, 32);
// Assets.font.drawString("IPATHABLE", 0, 48); Assets.font.drawString("IPATHABLE", 0, 48);
// Assets.font.drawString("", 0, 64); Assets.font.drawString("", 0, 64);
// Assets.font.drawString("", 0, 80); Assets.font.drawString("", 0, 80);
// Assets.flat.popColor(); Assets.flat.popColor();
} }
// receive the updated matrix every frame for the actual window. // receive the updated matrix every frame for the actual window.

View File

@ -7,6 +7,7 @@ import xyz.valnet.engine.scenegraph.GameObject;
import xyz.valnet.engine.scenegraph.IMouseCaptureArea; import xyz.valnet.engine.scenegraph.IMouseCaptureArea;
import xyz.valnet.hadean.gameobjects.Camera; import xyz.valnet.hadean.gameobjects.Camera;
import xyz.valnet.hadean.interfaces.IBuildLayerListener; import xyz.valnet.hadean.interfaces.IBuildLayerListener;
import xyz.valnet.hadean.util.Assets;
import xyz.valnet.hadean.util.Layers; import xyz.valnet.hadean.util.Layers;
public class BuildLayer extends GameObject implements IMouseCaptureArea { public class BuildLayer extends GameObject implements IMouseCaptureArea {
@ -30,6 +31,14 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea {
broadcastWorldCoords(); broadcastWorldCoords();
} }
@Override
public void render() {
if(mouseDown && active) {
Assets.selectionFrame.draw(screenX, screenY, App.mouseX - screenX, App.mouseY - screenY);
camera.screen2world(App.mouseX, App.mouseY);
}
}
public void activate(IBuildLayerListener listener) { public void activate(IBuildLayerListener listener) {
active = true; active = true;
this.listener = listener; this.listener = listener;
@ -57,6 +66,7 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea {
} }
private float x, y; private float x, y;
private int screenX, screenY;
private boolean mouseDown = false; private boolean mouseDown = false;
@Override @Override
@ -67,6 +77,8 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea {
} else if(button == 0 && active && hovered) { } else if(button == 0 && active && hovered) {
Vector2f worldcoords = camera.screen2world(App.mouseX, App.mouseY); Vector2f worldcoords = camera.screen2world(App.mouseX, App.mouseY);
mouseDown = true; mouseDown = true;
screenX = App.mouseX;
screenY = App.mouseY;
x = worldcoords.x; x = worldcoords.x;
y = worldcoords.y; y = worldcoords.y;
} }

View File

@ -67,11 +67,17 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
} }
@Override @Override
public void select(float nx, float ny, float nw, float nh) { public void select(float x1, float y1, float x2, float y2) {
x = (int)Math.floor(nx); int ix1 = (int)Math.floor(x1);
y = (int)Math.floor(ny); int iy1 = (int)Math.floor(y1);
ITileThing thing = new FarmPlot(x, y); int ix2 = (int)Math.floor(x2);
terrain.getTile(x, y).placeThing(thing); int iy2 = (int)Math.floor(y2);
for(int x = ix1; x <= ix2; x ++) {
for(int y = iy1; y <= iy2; y ++) {
ITileThing thing = new FarmPlot(x, y);
terrain.getTile(x, y).placeThing(thing);
}
}
opened.set(false); opened.set(false);
} }