Removed STICKY property in SetTextureWrap

This commit is contained in:
Antoine 2021-06-14 18:38:37 +02:00
parent 95d2d7e21c
commit f3ab1e4c4d
7 changed files with 23 additions and 35 deletions

View File

@ -16,8 +16,8 @@ uniform float time;
void main()
{
float speed = 10f;
float amplitude = 4f;
float speed = 5f;
float amplitude = 10f;
vec3 newPos = aPos;
newPos.y = newPos.y + (sin((time + index * 10f + newPos.x) * speed) * amplitude);
gl_Position = projection * view * transform * vec4(newPos, 1.0);

View File

@ -47,7 +47,7 @@ public class TestEngine {
String pathToText = "textures/dejavu10x10_gs_tc.png";
ObjectGl zangief = new Sprite(10.0f, 10f, path, null);
zangief.setTextureWrap(58, 0, 62, 84, ObjectGl.DEFAULT);
zangief.setTextureWrap(58, 0, 62, 84);
engine.add_objectGl(zangief);
zangief.translate(new Vector3f(-1000.0f, 200.0f, 0.0f));
zangief.setColor(new Vector3f(1.0f, 1.0f, 1.0f));
@ -55,7 +55,7 @@ public class TestEngine {
zangief.useTime = true;
ObjectGl zangief2 = new Sprite(9.0f, 10f, path, null);
zangief2.setTextureWrap(58, 0, 62, 84, ObjectGl.DEFAULT);
zangief2.setTextureWrap(58, 0, 62, 84);
engine.add_objectGl(zangief2);
zangief2.translate(new Vector3f(1000.0f, 200.0f, 0.0f));
zangief2.flipTextureWrapH();
@ -67,7 +67,7 @@ public class TestEngine {
//Create background
ObjectGl background = new ObjectGl(0f,1f,1f,10f, pathToBG, null);
background.setTextureWrap(0,0,621, 224, ObjectGl.DEFAULT);
background.setTextureWrap(0,0,621, 224);
background.translate(new Vector3f(-3011.0f, 1400.0f, 1.0f));
engine.add_objectGl(background);
@ -82,8 +82,8 @@ public class TestEngine {
UIElementText uiTextCoordP1 = new UIElementText("Boulevard Combattant", 7.0f, 0.0f,0.05f, 25.0f, engine);
engine.add_uiElement(uiTextCoordP1);
HorizontalProgressBar healthP1 = new HorizontalProgressBar(50f, 10, 1, 100, 100, 100, false);
UIElement healthP1UI = new UIElement(healthP1, 0f, 1f, engine);
HorizontalProgressBar healthP1 = new HorizontalProgressBar(50f, 9, 1, 100, 100, 100, true);
UIElement healthP1UI = new UIElement(healthP1, 0.005f, 0.995f, engine);
engine.add_uiElement(healthP1UI);
float hpCurrent = 100;

View File

@ -33,21 +33,21 @@ public class KeyboardInput extends GLFWKeyCallback {
public static void keyboardInput(ObjectGl token, int speed) {
boolean keyPressed = false;
if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_S)) {
token.setTextureWrap(161,260,56,59, ObjectGl.STICK_BOTTOM);
token.setTextureWrap(161,260,56,59);
keyPressed = true;
} else if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_W)) {
keyPressed = true;
}
if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_A)) {
token.translate(new Vector3f (speed * -1.0f, 0.0f, 0.0f));
token.setTextureWrap(121,0,57,82, ObjectGl.STICK_TOP);
token.setTextureWrap(121,0,57,82);
keyPressed = true;
}
else if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_D)) {
token.translate(new Vector3f (speed * 1.0f, 0.0f, 0.0f));
token.setTextureWrap(178,0,62,82, ObjectGl.STICK_TOP);
token.setTextureWrap(178,0,62,82);
keyPressed = true;
}
if (!keyPressed) token.setTextureWrap(58,0,62,82, ObjectGl.STICK_TOP);
if (!keyPressed) token.setTextureWrap(58,0,62,82);
}
}

View File

@ -163,25 +163,13 @@ public class ObjectGl {
}
/**
* Change the wrapping coordinate
* Change the wrapping coordinate, beware every sprite have to be of the same size if you don't want strange behavior
* @param x starting wrapping on the horizontal axis
* @param y starting wrapping on the vertical axis
* @param w the length of the wrapping on the horizontal axis
* @param h the length of the wrapping on the vertical axis
*/
public void setTextureWrap(float x, float y, float w, float h, int sticky){
// TODO set sticky property + precision issue
if (this.stick_state != sticky){ // Check if we're using a new dimension
if (sticky == STICK_BOTTOM){
this.stick_state = STICK_BOTTOM;
this.translate(new Vector3f(0.0f, (h - this.height)*this.scalingFactor, 0.0f));
} else if (sticky == STICK_TOP){
this.stick_state = STICK_TOP;
this.translate(new Vector3f(0.0f, (h - this.height)*this.scalingFactor, 0.0f));
} else {
this.stick_state = DEFAULT;
}
}
public void setTextureWrap(float x, float y, float w, float h){
this.height = h;
this.width = w;
this.vertexArray.swapVertexBufferObject(Primitive.createRectangle(this.zPos, w, h));

View File

@ -109,13 +109,13 @@ public class Text {
private void ObjectGlSetCharWrap(char a, ObjectGl obj){
if (a < 132 && a > 96){
obj.setTextureWrap(0.0f + (a - 97) * 10.0f,40.0f,10.0f,10.0f, ObjectGl.DEFAULT);
obj.setTextureWrap(0.0f + (a - 97) * 10.0f,40.0f,10.0f,10.0f);
}
else if (a < 91 && a > 64){
obj.setTextureWrap(0.0f + (a - 65) * 10.0f,30.0f,10.0f,10.0f, ObjectGl.DEFAULT);
obj.setTextureWrap(0.0f + (a - 65) * 10.0f,30.0f,10.0f,10.0f);
}
else if (a < 64 && a > 31){
obj.setTextureWrap(0.0f + (a - 32) * 10.0f,0.0f,10.0f,10.0f, ObjectGl.DEFAULT);
obj.setTextureWrap(0.0f + (a - 32) * 10.0f,0.0f,10.0f,10.0f);
}
}

View File

@ -321,7 +321,7 @@ public class BlueBaseFrames {
Frame f = generateStandFrame1();
ObjectGl blue = new ObjectGl(0f, 60f, 80f, 5f, path, null);
blue.setTextureWrap(f.getSprite()[0], f.getSprite()[1], f.getSprite()[2], f.getSprite()[3], ObjectGl.STICK_TOP);
blue.setTextureWrap(f.getSprite()[0], f.getSprite()[1], f.getSprite()[2], f.getSprite()[3]);
blue.translate(new Vector3f(-750,200,0));
int posX = -750;
int posY = 200;

View File

@ -41,7 +41,7 @@ public class match {
/**
* the level of the "ground", used to determine if a character is in the air or not.
*/
private static final int groundLevel = -400;
private static final int groundLevel = 180;
private static int timer;
private static InputBuffer inputsP1, inputsP2;
@ -105,7 +105,7 @@ public class match {
String pathToBG = "textures/background_beach.png";
ObjectGl background = new ObjectGl(0f,1f,1f,10f, pathToBG, null);
background.setTextureWrap(0,0,621, 224, ObjectGl.DEFAULT);
background.setTextureWrap(0,0,621, 224);
background.translate(new Vector3f(-3011.0f, 1400.0f, 1.0f));
engine.add_objectGl(background);
@ -118,10 +118,10 @@ public class match {
engine.add_objectGl(objP2);
f = p1.getCurrentframe();
objP1.setTextureWrap(f.getSprite()[0], f.getSprite()[1], f.getSprite()[2], f.getSprite()[3], ObjectGl.STICK_TOP);
objP1.setTextureWrap(f.getSprite()[0], f.getSprite()[1], f.getSprite()[2], f.getSprite()[3]);
f = p2.getCurrentframe();
objP2.setTextureWrap(f.getSprite()[0], f.getSprite()[1], f.getSprite()[2], f.getSprite()[3], ObjectGl.STICK_TOP);
objP2.setTextureWrap(f.getSprite()[0], f.getSprite()[1], f.getSprite()[2], f.getSprite()[3]);
objP2.flipTextureWrapH();
if(Joystick1Present) {
@ -227,10 +227,10 @@ public class match {
updatePos(p1);
updatePos(p2);
f = p1.getCurrentframe();
objP1.setTextureWrap(f.getSprite()[0], f.getSprite()[1], f.getSprite()[2], f.getSprite()[3], ObjectGl.STICK_TOP);
objP1.setTextureWrap(f.getSprite()[0], f.getSprite()[1], f.getSprite()[2], f.getSprite()[3]);
objP1.translate(new Vector3f(p1.getPosX()-oldPosXp1,p1.getPosY()-oldPosYp1,0));
f = p2.getCurrentframe();
objP2.setTextureWrap(f.getSprite()[0], f.getSprite()[1], f.getSprite()[2], f.getSprite()[3], ObjectGl.STICK_TOP);
objP2.setTextureWrap(f.getSprite()[0], f.getSprite()[1], f.getSprite()[2], f.getSprite()[3]);
objP2.translate(new Vector3f(p2.getPosX()-oldPosXp2,p2.getPosY()-oldPosYp2,0));
boolean p1LooksRight = p1.getPosX() < p2.getPosX();