diff --git a/MAVENProject/src/main/java/entity/Attack.java b/MAVENProject/src/main/java/entity/Attack.java index ae31bddae50387dc1e81fb24e9078f682d94d14d..cb35f38774659bad17c87eaa535b9f5cd2aec8bd 100644 --- a/MAVENProject/src/main/java/entity/Attack.java +++ b/MAVENProject/src/main/java/entity/Attack.java @@ -18,4 +18,10 @@ public class Attack { public void dealDamage(Entity entity){ entity.setNbLifePoints(Math.max(entity.getNbLifePoints()-damage, 0)); } + + public HitBox getHitBox() { + return hitBox; + } + + } diff --git a/MAVENProject/src/main/java/entity/Character.java b/MAVENProject/src/main/java/entity/Character.java index 38b0e86909e891f5001569f10b57a103854e1c60..64955ae10c6ce963621863949c8d5cf33991307f 100644 --- a/MAVENProject/src/main/java/entity/Character.java +++ b/MAVENProject/src/main/java/entity/Character.java @@ -136,8 +136,10 @@ public class Character extends Entity{ @Override public void attaque(){ + Coordonnees attackCenter = new Coordonnees(coord.getX() + direction*entityWIDTH/2, coord.getZ()); + Attack characterAttack = new Attack(attackStat, attackCenter, new HitBox(attackCenter,entityHEIGHT,entityWIDTH)); for (Monster monster : Jeu.getMonsterList()){ - if (HitBox.collision(this.hitBox, monster.getHitBox()) && tableCommande.get("CommandAttack") == 1){ + if (HitBox.collision(characterAttack.getHitBox(), monster.getHitBox())){ //le Math.max est la juste pour que la vie du perso ne tombe pas en-dessous de zero monster.setNbLifePoints(Math.max(monster.getNbLifePoints()-attackStat,0)); } @@ -172,10 +174,10 @@ public class Character extends Entity{ public void evolveCharacter(){ getGameCommand(); deplacements(); - attaque(); collisionGestion(); updateVoisinage(); this.setHitBox(new HitBox(this.getCoord(),entityHEIGHT,entityWIDTH)); // mise à jour moins crade pour l'instant + if (tableCommande.get("CommandAttack") == 1) attaque(); resetCommand(); }