diff --git a/src/engine/gui/UIElementText.java b/src/engine/gui/UIElementText.java index 357536b..8933df5 100644 --- a/src/engine/gui/UIElementText.java +++ b/src/engine/gui/UIElementText.java @@ -40,7 +40,7 @@ public class UIElementText extends UIDummy{ public void setBackground(Vector3f color){ this.colorBg = color; - this.background = new ObjectGl(this.zPos, objs.size() * 10f, 10f, this.scalingFactor, null, this.colorBg ); + this.background = new ObjectGl(this.zPos, objs.size() * 10f, 10f, this.scalingFactor - 0.1f, null, this.colorBg ); engine.add_objectGl(this.background); } diff --git a/src/engine/object/ObjectGl.java b/src/engine/object/ObjectGl.java index fc9119a..c305a3f 100644 --- a/src/engine/object/ObjectGl.java +++ b/src/engine/object/ObjectGl.java @@ -30,15 +30,15 @@ public class ObjectGl { /** * xPos and yPos will stop to be relevant if you use rotate function */ - private float xPos; - private float yPos; - private float zPos; - private float xAngle; - private float yAngle; - private float zAngle; - private float width; // To be used in setTextureWrap - private float height; - private float scalingFactor; + protected float xPos; + protected float yPos; + protected float zPos; + protected float xAngle; + protected float yAngle; + protected float zAngle; + protected float width; // To be used in setTextureWrap + protected float height; + protected float scalingFactor; public boolean useTime; diff --git a/src/engine/object/SortZ.java b/src/engine/object/SortZ.java index 5b9cd33..d1c8eea 100644 --- a/src/engine/object/SortZ.java +++ b/src/engine/object/SortZ.java @@ -6,6 +6,9 @@ public class SortZ implements Comparator { public int compare(ObjectGl a, ObjectGl b) { - return (int) (a.getZPos() - b.getZPos()); + float diff = a.getZPos() - b.getZPos(); + if (diff < 0) return -1; + else if (diff > 0) return 1; + else return 0; } } \ No newline at end of file diff --git a/src/engine/object/Sprite.java b/src/engine/object/Sprite.java index d5ba390..116edb9 100644 --- a/src/engine/object/Sprite.java +++ b/src/engine/object/Sprite.java @@ -1,11 +1,42 @@ package engine.object; +import engine.math.Matrix4f; import engine.math.Vector3f; public class Sprite extends ObjectGl { + private ObjectGl shadow; + public Sprite(float z, float size, String tex, Vector3f color) { super(z, 1f, 1f, size, tex, color); + this.shadow = null; + } + + /** + * Move the object according to vec, direction can change if rotation method have been used + * @param vec Vector3f + */ + public void translate(Vector3f vec){ + this.xPos += vec.x; + this.yPos += vec.y; + this.zPos += vec.z; + Vector3f vecTemp = vec.divXYZ(this.scalingFactor); + this.transform = this.transform.multiply(Matrix4f.translate(vecTemp)); + if (this.shadow != null){ + this.shadow.translate(new Vector3f(vec.x, 0f, 0f)); + } + } + + /** + * Ajoute une ombre sous le personnage + */ + public void setShadow(){ + this.shadow = new ObjectGl(this.zPos, this.width, this.height * 0.3f, this.scalingFactor, "textures/shadow.png", null); + this.shadow.translate(new Vector3f(this.xPos, this.yPos - this.height * 4.3f, -8f)); // 8 ça fait bcp mais y du z-fighting sinon jsp pk + } + + public ObjectGl getShadow(){ + return this.shadow; } } diff --git a/src/gameplay/match/match.java b/src/gameplay/match/match.java index 77f6032..196692a 100644 --- a/src/gameplay/match/match.java +++ b/src/gameplay/match/match.java @@ -69,7 +69,7 @@ public class match { private static GamepadInput gamepad1 = null; private static GamepadInput gamepad2 = null; - // GUI + // GUI / HUD ? private static UIElementText coordP1; private static UIElementText coordP2; private static UIElement healthBarP1; @@ -78,7 +78,7 @@ public class match { private static HorizontalProgressBar healthBarP2Obj; private static UIElementText timerUI; - private static ObjectGl objP1,objP2; + private static Sprite objP1,objP2; private static Engine engine; private static Frame f; private static int acCode = 0; @@ -95,6 +95,9 @@ public class match { p2.setPos((int) (750 - objP2.getWidth() * objP2.getScalingFactor()), groundLevel); //TODO : change to better values if needed objP1.translate(new Vector3f(p1.getPosX(),p1.getPosY(),0)); objP2.translate(new Vector3f(p2.getPosX(),p2.getPosY(),0)); + // TODO meilleur implémentation possible + objP1.getShadow().translate(new Vector3f(0f,p1.getPosY(),0)); + objP2.getShadow().translate(new Vector3f(0f,p2.getPosY(),0)); } /** @@ -148,14 +151,13 @@ public class match { ObjectGl background = new ObjectGl(0f,1f,1f,2.5f, pathToBG, null); background.setTextureWrap(0, 0, 1914f, 701f); - background.translate(new Vector3f(-1000f, 1000f, 0f)); + background.translate(new Vector3f(-1350f, 1000f, 0f)); engine.add_objectGl(background); p1 = CharacterBlue.generateCharBlue(); p2 = CharacterBlue.generateCharBlue(); - objP1 = new Sprite(10f, 5f, path, null); - objP2 = new Sprite(15f, 5f, path, null); - objP2.setColor(new Vector3f(1.0f,0.0f,1.0f)); + objP1 = new Sprite(14f, 5f, path, null); + objP2 = new Sprite(15f, 5f, path, new Vector3f(1.0f,0.0f,1.0f)); engine.add_objectGl(objP1); engine.add_objectGl(objP2); @@ -166,6 +168,17 @@ public class match { objP2.setTextureWrap(f.getSprite()[0], f.getSprite()[1], f.getSprite()[2], f.getSprite()[3]); objP2.flipTextureWrapH(); + //Création des ombres + objP1.setShadow(); + engine.add_objectGl(objP1.getShadow()); + objP2.setShadow(); + engine.add_objectGl(objP2.getShadow()); + + System.out.println(objP2.getZPos()); + System.out.println(objP2.getShadow().getZPos()); + System.out.println(objP1.getZPos()); + System.out.println(objP1.getShadow().getZPos()); + if(Joystick1Present) { gamepad1 = new GamepadInput(GLFW_JOYSTICK_1); gamepad1.inputRefresh(); @@ -300,7 +313,7 @@ public class match { f = p2.getCurrentframe(); objP2.setTextureWrap(f.getSprite()[0], f.getSprite()[1], f.getSprite()[2], f.getSprite()[3]); - objP2.translate(new Vector3f(0-(p2.getPosX()-oldPosXp2),p2.getPosY()-oldPosYp2,0)); + objP2.translate(new Vector3f(-(p2.getPosX() - oldPosXp2),p2.getPosY()-oldPosYp2,0)); Frame nf = new Frame(); nf.clone(p2.getCurrentframe());