diff --git a/shaders/StylishShaders/HorizontalProgressBar.glsl b/shaders/StylishShaders/HorizontalProgressBar.glsl new file mode 100644 index 0000000..3c90c38 --- /dev/null +++ b/shaders/StylishShaders/HorizontalProgressBar.glsl @@ -0,0 +1,31 @@ +#version 410 + +in vec4 color; +in vec2 fragCoord; + +out vec4 FragColor; + +uniform float time; +uniform float fill; +uniform bool leftToRight; + +void main() +{ + if (leftToRight){ + if (fill > fragCoord.x){ + FragColor = color; + } + else { + FragColor = vec4(color.xyz, 0f); + } + } else { + if (fill < fragCoord.x){ + FragColor = color; + } + else { + FragColor = vec4(color.xyz, 0f); + } + } + + +} \ No newline at end of file diff --git a/shaders/StylishShaders/ProgressBarFrag.glsl b/shaders/StylishShaders/ProgressBarFrag.glsl deleted file mode 100644 index 9f376da..0000000 --- a/shaders/StylishShaders/ProgressBarFrag.glsl +++ /dev/null @@ -1,21 +0,0 @@ -#version 410 - -in vec4 color; -in vec2 fragCoord; - -out vec4 FragColor; - -uniform float time; -uniform float fill; - -void main() -{ - if (fill > fragCoord.x){ - FragColor = color; - } - else { - FragColor = vec4(color.xyz, 0f); - } - - -} \ No newline at end of file diff --git a/src/engine/TestEngine.java b/src/engine/TestEngine.java index 8d5ecea..023ff48 100644 --- a/src/engine/TestEngine.java +++ b/src/engine/TestEngine.java @@ -4,11 +4,9 @@ import engine.gui.UIElement; import engine.gui.UIElementText; import engine.input.*; import engine.math.Vector3f; -import engine.object.Hitbox; import engine.object.ObjectGl; -import engine.object.ProgressBar; +import engine.object.HorizontalProgressBar; import engine.object.Sprite; -import engine.sound.*; import java.util.ArrayList; import java.util.List; @@ -83,7 +81,7 @@ public class TestEngine { UIElementText uiTextCoordP1 = new UIElementText("Boulevard Combattant", 7.0f, 0.0f,0.05f, 25.0f, engine); engine.add_uiElement(uiTextCoordP1); - ProgressBar healthP1 = new ProgressBar(50f, 10, 1, 100, 100, 100); + HorizontalProgressBar healthP1 = new HorizontalProgressBar(50f, 10, 1, 100, 100, 100, false); UIElement healthP1UI = new UIElement(healthP1, 0f, 1f, engine); engine.add_uiElement(healthP1UI); float hpCurrent = 100; @@ -162,11 +160,11 @@ public class TestEngine { frame = 0; } - while (!nextFrame) { - nextFrame = System.currentTimeMillis() - lastFrame >= 16.66f; - } +// while (!nextFrame) { +// nextFrame = System.currentTimeMillis() - lastFrame >= 16.66f; +// } - hpCurrent -= 1; + hpCurrent -= 0.01; healthP1.setCurrent(hpCurrent); nextFrame = false; diff --git a/src/engine/object/ProgressBar.java b/src/engine/object/HorizontalProgressBar.java similarity index 60% rename from src/engine/object/ProgressBar.java rename to src/engine/object/HorizontalProgressBar.java index 55adc82..5648628 100644 --- a/src/engine/object/ProgressBar.java +++ b/src/engine/object/HorizontalProgressBar.java @@ -4,16 +4,18 @@ import engine.math.Vector3f; import static org.lwjgl.glfw.GLFW.glfwGetTime; -public class ProgressBar extends ObjectGl{ +public class HorizontalProgressBar extends ObjectGl{ private float max; private float current; + private int leftToRight; - public ProgressBar(float z, float w, float h, float size, float current, float max) { + public HorizontalProgressBar(float z, float w, float h, float size, float current, float max, boolean leftToRight) { super(z, w, h, size, null, new Vector3f(0f, 1f, 0f)); - this.current = current; this.max = max; - this.setShader("shaders/StylishShaders/BasicNoTexVert.glsl", "shaders/StylishShaders/ProgressBarFrag.glsl"); + this.current = current; + this.leftToRight = leftToRight ? 1 : 0; + this.setShader("shaders/StylishShaders/BasicNoTexVert.glsl", "shaders/StylishShaders/HorizontalProgressBar.glsl"); } public void setCurrent(float newCurrent){ @@ -32,7 +34,14 @@ public class ProgressBar extends ObjectGl{ this.shader.enable(); if (this.useTime) this.shader.setUniform1f("time", (float) glfwGetTime()); - this.shader.setUniform1f("fill", (this.current / this.max) * this.getWidth()); + + if (this.leftToRight == 1){ + this.shader.setUniform1f("fill", (this.current / this.max) * this.getWidth()); + } else { + this.shader.setUniform1f("fill", Math.abs(((this.current / this.max) * this.getWidth()) - this.getWidth())); + } + + this.shader.setUniform1i("leftToRight", this.leftToRight); this.shader.setUniformMat4f("projection", projection); this.shader.setUniformMat4f("view", view);