ProgressBar.java added, can be used to represent healthbar ;o)
This commit is contained in:
parent
f85a15b393
commit
8b9d698acc
19
shaders/StylishShaders/BasicNoTexVert.glsl
Normal file
19
shaders/StylishShaders/BasicNoTexVert.glsl
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#version 410 core
|
||||||
|
|
||||||
|
layout (location = 0) in vec3 aPos;
|
||||||
|
layout (location = 1) in vec3 aColor;
|
||||||
|
layout (location = 2) in vec2 aTexCoord;
|
||||||
|
|
||||||
|
out vec2 fragCoord;
|
||||||
|
out vec4 color;
|
||||||
|
|
||||||
|
uniform mat4 projection;
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 transform;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = projection * view * transform * vec4(aPos, 1.0);
|
||||||
|
color = vec4(aColor, 1.0f);
|
||||||
|
fragCoord = aPos.xy;
|
||||||
|
}
|
21
shaders/StylishShaders/ProgressBarFrag.glsl
Normal file
21
shaders/StylishShaders/ProgressBarFrag.glsl
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,10 +1,12 @@
|
|||||||
package engine;
|
package engine;
|
||||||
|
|
||||||
|
import engine.gui.UIElement;
|
||||||
import engine.gui.UIElementText;
|
import engine.gui.UIElementText;
|
||||||
import engine.input.*;
|
import engine.input.*;
|
||||||
import engine.math.Vector3f;
|
import engine.math.Vector3f;
|
||||||
import engine.object.Hitbox;
|
import engine.object.Hitbox;
|
||||||
import engine.object.ObjectGl;
|
import engine.object.ObjectGl;
|
||||||
|
import engine.object.ProgressBar;
|
||||||
import engine.object.Sprite;
|
import engine.object.Sprite;
|
||||||
import engine.sound.*;
|
import engine.sound.*;
|
||||||
|
|
||||||
@ -60,8 +62,8 @@ public class TestEngine {
|
|||||||
zangief2.translate(new Vector3f(1000.0f, 200.0f, 0.0f));
|
zangief2.translate(new Vector3f(1000.0f, 200.0f, 0.0f));
|
||||||
zangief2.flipTextureWrapH();
|
zangief2.flipTextureWrapH();
|
||||||
|
|
||||||
Hitbox hitboxTest = new Hitbox(35.0f, 100.0f, 50.0f, 10.0f, new Vector3f(1.0f, 0.0f, 0.0f));
|
// Hitbox hitboxTest = new Hitbox(35.0f, 100.0f, 50.0f, 10.0f, new Vector3f(1.0f, 0.0f, 0.0f));
|
||||||
engine.add_objectGl(hitboxTest);
|
// engine.add_objectGl(hitboxTest);
|
||||||
|
|
||||||
engine.setCameraTrackingSF3ThirdStrike(zangief, zangief2);
|
engine.setCameraTrackingSF3ThirdStrike(zangief, zangief2);
|
||||||
|
|
||||||
@ -75,12 +77,17 @@ public class TestEngine {
|
|||||||
// UIElement uiElement = new UIElement(smiley, 0.0f, 1.0f, engine);
|
// UIElement uiElement = new UIElement(smiley, 0.0f, 1.0f, engine);
|
||||||
// engine.add_uiElement(uiElement);
|
// engine.add_uiElement(uiElement);
|
||||||
|
|
||||||
UIElementText uiTextTest = new UIElementText("Boulevard Combattant", 5.0f, 0.0f,1.0f, 25.0f, engine);
|
UIElementText fpsTracker = new UIElementText("Boulevard Combattant", 5.0f, 0.0f,0.5f, 25.0f, engine);
|
||||||
engine.add_uiElement(uiTextTest);
|
engine.add_uiElement(fpsTracker);
|
||||||
|
|
||||||
UIElementText uiTextCoordP1 = new UIElementText("Boulevard Combattant", 7.0f, 0.0f,0.05f, 25.0f, engine);
|
UIElementText uiTextCoordP1 = new UIElementText("Boulevard Combattant", 7.0f, 0.0f,0.05f, 25.0f, engine);
|
||||||
engine.add_uiElement(uiTextCoordP1);
|
engine.add_uiElement(uiTextCoordP1);
|
||||||
|
|
||||||
|
ProgressBar healthP1 = new ProgressBar(50f, 10, 1, 100, 100, 100);
|
||||||
|
UIElement healthP1UI = new UIElement(healthP1, 0f, 1f, engine);
|
||||||
|
engine.add_uiElement(healthP1UI);
|
||||||
|
float hpCurrent = 100;
|
||||||
|
|
||||||
// Text texTest = new Text("ABCDEFGHIJKLMNOPQRSTUVWYZ",20.0f, 10, engine);
|
// Text texTest = new Text("ABCDEFGHIJKLMNOPQRSTUVWYZ",20.0f, 10, engine);
|
||||||
// texTest.show();
|
// texTest.show();
|
||||||
// texTest.translate(new Vector3f(-1000.0f, (float) (-1000.0f * (3.0 / 4.0f) + 100.0f)));
|
// texTest.translate(new Vector3f(-1000.0f, (float) (-1000.0f * (3.0 / 4.0f) + 100.0f)));
|
||||||
@ -151,13 +158,16 @@ public class TestEngine {
|
|||||||
if (System.currentTimeMillis() - timer > 1000) {
|
if (System.currentTimeMillis() - timer > 1000) {
|
||||||
timer += 1000;
|
timer += 1000;
|
||||||
System.out.println("FPS: " + frame);
|
System.out.println("FPS: " + frame);
|
||||||
uiTextTest.setText("FPS: " + frame);
|
fpsTracker.setText("FPS: " + frame);
|
||||||
frame = 0;
|
frame = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// while (!nextFrame) {
|
while (!nextFrame) {
|
||||||
// nextFrame = System.currentTimeMillis() - lastFrame >= 16.66f;
|
nextFrame = System.currentTimeMillis() - lastFrame >= 16.66f;
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
hpCurrent -= 1;
|
||||||
|
healthP1.setCurrent(hpCurrent);
|
||||||
|
|
||||||
nextFrame = false;
|
nextFrame = false;
|
||||||
if (engine.shouldClose()) engine.setRunning(false);
|
if (engine.shouldClose()) engine.setRunning(false);
|
||||||
|
45
src/engine/object/ProgressBar.java
Normal file
45
src/engine/object/ProgressBar.java
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package engine.object;
|
||||||
|
|
||||||
|
import engine.math.Vector3f;
|
||||||
|
|
||||||
|
import static org.lwjgl.glfw.GLFW.glfwGetTime;
|
||||||
|
|
||||||
|
public class ProgressBar extends ObjectGl{
|
||||||
|
|
||||||
|
private float max;
|
||||||
|
private float current;
|
||||||
|
|
||||||
|
public ProgressBar(float z, float w, float h, float size, float current, float max) {
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrent(float newCurrent){
|
||||||
|
this.current = newCurrent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMax(float newMax){
|
||||||
|
this.max = newMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do shader binding, texture binding and vertexArray drawing
|
||||||
|
*/
|
||||||
|
public void render(){
|
||||||
|
|
||||||
|
this.shader.enable();
|
||||||
|
|
||||||
|
if (this.useTime) this.shader.setUniform1f("time", (float) glfwGetTime());
|
||||||
|
this.shader.setUniform1f("fill", (this.current / this.max) * this.getWidth());
|
||||||
|
|
||||||
|
this.shader.setUniformMat4f("projection", projection);
|
||||||
|
this.shader.setUniformMat4f("view", view);
|
||||||
|
this.shader.setUniformMat4f("transform", this.transform);
|
||||||
|
|
||||||
|
this.vertexArray.render();
|
||||||
|
|
||||||
|
this.shader.disable();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user