Première implémentation de l'affichage des hitbox
This commit is contained in:
parent
0c24eea79f
commit
ef1a8d5583
@ -40,4 +40,7 @@ public class Vector3f {
|
||||
return new Vector3f(this.x / div, this.y / div, this.z / div);
|
||||
}
|
||||
|
||||
public static Vector3f vectorBetweenTwoPoint(Vector3f origin, Vector3f target){
|
||||
return new Vector3f(target.x - origin.x, target.y - origin.y, target.z - origin.z);
|
||||
}
|
||||
}
|
||||
|
@ -231,6 +231,10 @@ public class ObjectGl {
|
||||
this.vertexArray.swapTextureBufferObject(texture);
|
||||
}
|
||||
|
||||
public Vector3f getPos(){
|
||||
return new Vector3f(xPos, yPos, zPos);
|
||||
}
|
||||
|
||||
public float getXPos(){
|
||||
return xPos;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import engine.gui.UIElementText;
|
||||
import engine.input.Button;
|
||||
import engine.input.GamepadInput;
|
||||
import engine.math.Vector3f;
|
||||
import engine.object.Hitbox;
|
||||
import engine.object.HorizontalProgressBar;
|
||||
import engine.object.ObjectGl;
|
||||
import engine.object.Sprite;
|
||||
@ -16,10 +17,7 @@ import gameplay.actions.Throw;
|
||||
import gameplay.actions.ThrowPart;
|
||||
import gameplay.entities.Status;
|
||||
import gameplay.frames.Frame;
|
||||
import gameplay.hitboxes.Active_HitBox;
|
||||
import gameplay.hitboxes.Passive_HitBox;
|
||||
import gameplay.hitboxes.Active_throw_Hitbox;
|
||||
import gameplay.hitboxes.Passive_throw_HitBox;
|
||||
import gameplay.hitboxes.*;
|
||||
import gameplay.input.InputBuffer;
|
||||
import gameplay.entities.Character;
|
||||
import gameplay.input.Inputs;
|
||||
@ -29,11 +27,13 @@ import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.lwjgl.system.CallbackI;
|
||||
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
|
||||
@ -78,6 +78,11 @@ public class match {
|
||||
private static HorizontalProgressBar healthBarP2Obj;
|
||||
private static UIElementText timerUI;
|
||||
|
||||
// Debug
|
||||
private static boolean showP1Hitbox = true; // TODO modifier pour le rendre activable
|
||||
private static boolean showP2Hitbox = false;
|
||||
private static List<Hitbox> listHitboxObj = new ArrayList<>();
|
||||
|
||||
private static Sprite objP1,objP2;
|
||||
private static Engine engine;
|
||||
private static Frame f;
|
||||
@ -150,7 +155,7 @@ public class match {
|
||||
|
||||
p1 = CharacterBlue.generateCharBlue();
|
||||
p2 = CharacterBlue.generateCharBlue();
|
||||
objP1 = new Sprite(14f, 5f, path, null);
|
||||
objP1 = new Sprite(14f, 4f, path, null);
|
||||
objP2 = new Sprite(15f, 5f, path, new Vector3f(1.0f,0.0f,1.0f));
|
||||
engine.add_objectGl(objP1);
|
||||
engine.add_objectGl(objP2);
|
||||
@ -347,6 +352,16 @@ public class match {
|
||||
p1.setCurrentFrame(nf);
|
||||
objP1.flipTextureWrapH();
|
||||
}
|
||||
|
||||
// Debug Hitbox Management
|
||||
removeHitboxEngine();
|
||||
if (showP1Hitbox){
|
||||
addHitbox(p1);
|
||||
} if (showP2Hitbox) {
|
||||
addHitbox(p2);
|
||||
}
|
||||
addHitboxEngine();
|
||||
|
||||
engine.update();
|
||||
engine.render();
|
||||
acCode = 23;
|
||||
@ -395,7 +410,7 @@ public class match {
|
||||
//do an attack if possible
|
||||
while(atkCount < c.getAttacks().length && !actionSet) {
|
||||
Attack atk = c.getAttacks()[atkCount];
|
||||
Boolean attackIsPossible = input.commandRecognized(atk.getCommand())
|
||||
boolean attackIsPossible = input.commandRecognized(atk.getCommand())
|
||||
&& atk.getRequiredStatus().equals(c.getStatus())
|
||||
&& ((atk.isSpecial() && c.getCurrentframe().isSpecialCancellable())
|
||||
|| (!atk.isSpecial() && c.getCurrentframe().isNormalCancellable()));
|
||||
@ -455,9 +470,9 @@ public class match {
|
||||
}
|
||||
|
||||
private static void handleThrows(Character p1, Character p2) {
|
||||
ArrayList<Active_throw_Hitbox> activeP1 = new ArrayList<Active_throw_Hitbox>(p1.getCurrentframe().getActThrowHitBox());
|
||||
ArrayList<Passive_throw_HitBox> passiveP2 = new ArrayList<Passive_throw_HitBox>(p2.getCurrentframe().getPassThrowHitBox());
|
||||
ArrayList<ThrowPart> tP = new ArrayList<ThrowPart>(p1.getNextThrowParts());
|
||||
ArrayList<Active_throw_Hitbox> activeP1 = new ArrayList<>(p1.getCurrentframe().getActThrowHitBox());
|
||||
ArrayList<Passive_throw_HitBox> passiveP2 = new ArrayList<>(p2.getCurrentframe().getPassThrowHitBox());
|
||||
ArrayList<ThrowPart> tP = new ArrayList<>(p1.getNextThrowParts());
|
||||
ThrowPart hit = new ThrowPart(tP.get(0).getFrames());
|
||||
hit.clone(tP.get(0));
|
||||
for(Active_throw_Hitbox atH : activeP1) {
|
||||
@ -487,9 +502,9 @@ public class match {
|
||||
* @param inputsP2 the inputs of the player 2, used to see if they're guarding
|
||||
*/
|
||||
private static void handleHits(Character p1, Character p2, InputBuffer inputsP2) {
|
||||
ArrayList<Active_HitBox> activeP1 = new ArrayList<Active_HitBox>(p1.getCurrentframe().getActHitBox());
|
||||
ArrayList<Passive_HitBox> passiveP2 = new ArrayList<Passive_HitBox>(p2.getCurrentframe().getPassHitBox());
|
||||
ArrayList<attackPart> aP = new ArrayList<attackPart>(p1.getNextAttackParts());
|
||||
ArrayList<Active_HitBox> activeP1 = new ArrayList<>(p1.getCurrentframe().getActHitBox());
|
||||
ArrayList<Passive_HitBox> passiveP2 = new ArrayList<>(p2.getCurrentframe().getPassHitBox());
|
||||
ArrayList<attackPart> aP = new ArrayList<>(p1.getNextAttackParts());
|
||||
attackPart hit = new attackPart(aP.get(0).getFrames());
|
||||
hit.clone(aP.get(0));
|
||||
for(Active_HitBox aH : activeP1) {
|
||||
@ -613,4 +628,47 @@ public class match {
|
||||
else {c.setPos((int)(c.getPosX()-c.getCurrentframe().getMove_x()),(int)(c.getPosY()+c.getCurrentframe().getMove_y()));}
|
||||
}
|
||||
|
||||
// TODO giga memory leak ?
|
||||
private static void addHitboxEngine(){
|
||||
for (ObjectGl obj : listHitboxObj){
|
||||
engine.add_objectGl(obj);
|
||||
}
|
||||
}
|
||||
|
||||
private static void removeHitboxEngine(){
|
||||
for (ObjectGl obj : listHitboxObj){ // Il faut le cast en ObjectGl
|
||||
engine.remove_objectGl(obj);
|
||||
}
|
||||
listHitboxObj = new ArrayList<>();
|
||||
}
|
||||
|
||||
private static void addHitbox(Character c){
|
||||
Frame f = c.getCurrentframe();
|
||||
Vector3f posC = new Vector3f(c.getPosX(), c.getPosY(), 100f);
|
||||
Vector3f darkBlue = new Vector3f(8f/255f, 29f/255f, 153f/255f);
|
||||
Vector3f green = new Vector3f(33f/255f, 135f/255f, 12f/255f);
|
||||
Vector3f red = new Vector3f(120f/255f, 19f/255f, 12f/255f);
|
||||
Vector3f lightBlue = new Vector3f(32f/255f, 103f/255f, 201f/255f);
|
||||
for (Passive_HitBox passive_hitBox : f.getPassHitBox()){
|
||||
Hitbox hb = new Hitbox(100f, passive_hitBox.getSize_x(), passive_hitBox.getSize_y(), 1f, darkBlue);
|
||||
hb.translate(new Vector3f(passive_hitBox.getPosX() + posC.x, passive_hitBox.getPosY() + posC.y));
|
||||
listHitboxObj.add(hb);
|
||||
}
|
||||
for (Passive_throw_HitBox passive_throw_hitBox : f.getPassThrowHitBox()){
|
||||
Hitbox hb = new Hitbox(101f, passive_throw_hitBox.getSize_x(), passive_throw_hitBox.getSize_y(), 1f, green);
|
||||
hb.translate(new Vector3f(passive_throw_hitBox.getPosX() + posC.x, passive_throw_hitBox.getPosY() + posC.y));
|
||||
listHitboxObj.add(hb);
|
||||
}
|
||||
for (Active_HitBox active_hitBox : f.getActHitBox()){
|
||||
Hitbox hb = new Hitbox(102f, active_hitBox.getSize_x(), active_hitBox.getSize_y(), 1f, red);
|
||||
hb.translate(new Vector3f(active_hitBox.getPosX() + posC.x, active_hitBox.getPosY() + posC.y));
|
||||
listHitboxObj.add(hb);
|
||||
}
|
||||
for (Active_throw_Hitbox active_throw_hitbox : f.getActThrowHitBox()){
|
||||
Hitbox hb = new Hitbox(103f, active_throw_hitbox.getSize_x(), active_throw_hitbox.getSize_y(), 1f, lightBlue);
|
||||
hb.translate(new Vector3f(active_throw_hitbox.getPosX() + posC.x, active_throw_hitbox.getPosY() + posC.y));
|
||||
listHitboxObj.add(hb);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user